selenium-webdriver - 无法读取设备场上的属性文件:- src/test/resources/Properties/Android_Or.properties -error
问题描述
请让我知道如何读取设备场中的属性文件,因为以下代码不起作用。我研究了各种解决方案,但设备场仍然无法识别属性文件,尽管此代码在本地工作正常
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);
}
}
解决方案
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;
}
推荐阅读
- css - 如何使用组件中的变量在角度样式绑定中使用 css calc()
- python - 重建计算机后 Mechanicalsoup 无法正常工作
- javascript - 如何使用 JQuery 进行闰年计算
- sql - 如何使用sql返回每篇论文的论文标题和作者数量
- ruby-on-rails - # 方法缺失或方法未定义“upsert”
- python - 将值导出到现有的 excel 文件到同一列
- arrays - livewire和laravel中的多维数组访问
- sql - 用于将whatsapp 数据传输到 SQL 或其他数据库的 ETL
- entity-framework-core - EF Core 诊断 - 每个上下文实例的查询计数
- cors - CORS vs CORB,有什么区别?