Prop.Properties配置测试应用的环境和其他配置项

prop.propertiesfile contains important info that needs to be changed before the test is run, such as: Browser type (browser =), Product (test-prod). Depend your test setup; you may not need the test-env and other configurations.

定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Browser type
# 1 => FireFox
# 2 => IE
# 3 => Chrome
# 4 => Safari
BrowserType = 2

# Test server and login information
BaseURL = http://www.site.com/
UserName =
UserPwd =

# UI actions' timeout in millisecond
Timeout = 30000

提取

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class GlobalSetting
{

public static Properties prop = getProperties();

public static String baseURL = prop.getProperty("BaseURL");
public static int browserType = Integer.parseInt(prop.getProperty("BrowserType"));

public static String getProperty(String property) {
return prop.getProperty(property);
}

public static Properties getProperties() {
Properties prop = new Properties();
try {
FileInputStream file = new FileInputStream("prop1.properties");
prop.load(file);
file.close();
} catch (Exception e) {
e.printStackTrace();
}
return prop;
}
}

#引用

1
2
3
4
@Test
public void doTest(){

System.out.Println(GlobalSetting.baseURL);
}

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!