【发布时间】:2013-11-18 12:59:18
【问题描述】:
我想将我的 selenium 测试设置外部化,以使其更具可配置性。 我想将我的 testURL 和我的节点 URL 外部化。
这是我的代码:
public void setup () throws MalformedURLException
{ //the URL of the application to be tested
TestURL = "http://frstmwarwebsrv2.orsyptst.com:9000";
//Hub URL
BaseURL = "http://10.2.128.126";
//Node1 URL
winURL = "http://10.2.128.120:5556/wd/hub";
//Node2 URL
androidURL ="http://10.2.128.120:5555/wd/hub";
目前我在每个测试中都添加了这个设置函数,我想将它放在一个 XML 文件中作为示例,以便使其可配置,有什么建议吗?
谢谢
感谢您的帮助
更新:
这是我到目前为止所做的:
添加了包含此内容的 config.properties 文件:
# This is my test.properties file
AppURL = http://************
HubURL= http://*****************
WinURL= http://*********/wd/hub
AndroidURL =
iOSURL
并创建了一个类来读取属性:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
public class ReadPropertiesFile {
public static void main(String[] args) {
try {
File file = new File("config.properties");
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInput);
fileInput.close();
Enumeration enuKeys = properties.keys();
while (enuKeys.hasMoreElements()) {
String key = (String) enuKeys.nextElement();
String value = properties.getProperty(key);
System.out.println(key + ": " + value);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
运行时出现此错误:
java.io.FileNotFoundException: config.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at ReadPropertiesFile.main(ReadPropertiesFile.java:15)
我的属性文件在 src 文件夹下
【问题讨论】:
-
很好地复制了项目源下的文件,感谢 Niall :)
标签: selenium-webdriver selenium-grid automated-tests