【问题标题】:Can't read properties file on device farm :- src/test/resources/Properties/Android_Or.properties -error无法读取设备场上的属性文件:- src/test/resources/Properties/Android_Or.properties -error
【发布时间】:2020-06-17 14:30:56
【问题描述】:

请告诉我如何读取设备场中的属性文件,因为以下代码不起作用。我研究了各种解决方案,但设备场仍然无法识别属性文件,尽管此代码在本地工作正常

public abstract class AndroidCapabilities {

    // protected static AppiumDriver<MobileElement> driver;

    public static ExtentHtmlReporter reporter;
    public static ExtentReports extent;
    public static ExtentTest logger1;

//  @Parameters("browser")
//  @BeforeSuite
//  public void setUp() throws MalformedURLException {


    public static AndroidDriver<MobileElement> driver;
      public abstract String getName();

    @BeforeTest
    public abstract void setUpPage();

    @BeforeSuite
    public void setUpAppium() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
//      capabilities.setCapability("device", "Android");
//      capabilities.setCapability("platformName", "Android");
//      capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        final String URL_STRING = "http://127.0.0.1:4723/wd/hub";

        URL url = new URL(URL_STRING);

        // Use a empty DesiredCapabilities object
        driver = new AndroidDriver<MobileElement>(url, capabilities);

        // Use a higher value if your mobile elements take time to show up
        driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
    }

    public static Properties properties;
    static {
        properties = new Properties();
        FileInputStream fis;
        InputStream input;
        try {
//           fis = new FileInputStream(System.getProperty("user.dir") +
//           "//src//test//resources//Properties//Android_OR.properties");
            fis = (FileInputStream) Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream("//Properties//Android_OR.properties");
            System.out.println(properties.getProperty("url"));
            properties.load(fis);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    @BeforeTest
    public void createReport() {
        reporter = new ExtentHtmlReporter("./extent.html");
        extent = new ExtentReports();
        extent.attachReporter(reporter);

    }

    @AfterTest
    public void flush() throws IOException {
        extent.flush();
        // reporter.setAppendExisting(true);
    }

    @AfterSuite
    public void closeApplication() {
        driver.quit();
        Reporter.log("===Session End===", true);
    }

}

【问题讨论】:

  • 嗨,有谁可以建议我。
  • 当您将文件上传到 AWS Device Farm 时该文件位于何处?它可能不在您最初期望的位置。您可以尝试在 AWS Device Farm forums 上发布遇到此问题的跑步的跑步 URL。

标签: selenium-webdriver aws-device-farm


【解决方案1】:
Faced the same issue. Instead of using System.getProperty, try this:    

// pass fileName as "Android_OR.properties"
public Properties loadProperty(String fileName) {
        Properties prop = new Properties();
        try (InputStream input = Base.class.getClassLoader().getResourceAsStream(filePath)) {

            if (input == null) {
                System.out.println("Sorry, unable to find config.properties");
                return prop;
            }

            // load a properties file from class path, inside static method
            prop.load(input);

        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return prop;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    相关资源
    最近更新 更多