Creating configuration properties for Selenium Test Suite
来源:互联网 发布:报表数据分析实例 编辑:程序博客网 时间:2024/05/17 02:23
http://selftechy.com/2011/06/20/creating-configuration-properties-for-selenium-test-suite
Create a configuration properties file to store parameters such as log file path, test data path, results path, selenium execution speed, wait period, etc, then make changes to the parameters whenever needed.
Java provides a way to create configuration file for storing configurable parameters of an application. Selenium Test Suite also needs such a file to keep global configuration settings.
In this post let us try to understand how we can create a “.properties” file and how to access values from the properties file.
Create a file text file (using any text editor such as notepad) Selconfig.properties (as in the file –view file) and save the file as “Selfconfig.properties”
Create classes as in the following code snippets:
package com.selftechy.readdata;/* * Author - Seetaram Hegde * */import com.selftechy.library.*;import java.io.IOException;public class TestRun {public static void main(String[] args) throws IOException {// TODO Auto-generated method stubconfig cfg = new config("F:\\Helios-Workspace\\Config\\SelConfig.properties");System.out.println(cfg.ReadProperty("ConfigPath"));}}
package com.selftechy.library;/* * Author - Seetaram Hegde * */import java.io.*;import java.util.*;public class config { String str, key; private String filepath; public config(String filepath){ this.filepath=filepath; } public String ReadProperty(String propkey){ String propval=""; try{ int check = 0; while(check == 0){ check = 1; File cfgfile = new File(filepath); if(cfgfile.exists()){ Properties props = new Properties(); FileInputStream propin = new FileInputStream(cfgfile); props.load(propin); propval=props.getProperty(propkey); } else{ check = 0; }} } catch(IOException e){ e.printStackTrace(); }return propval; }}
Save both the classes and then execute the first one (TestRun.java) as Java application. In the Selconfig.properties file, TestData & ConfigPath are the keys and “F:\\Helios-Workspace\\TestData & F:\\Helios-Workspace\\Config” are the respective values. In .properties file we can put comments using “#”. Any sentence that starts with # will be considered as comment.
To access the values of any properties, use the “key” parameter. For example, to access the value of “TestData” and “ConfigPath” write the code as follows:
config cfg = new config("F:\\Helios-Workspace\\Config\\SelConfig.properties");
cfg.ReadProperty("ConfigPath")
cfg.ReadProperty("TestData")
- Creating configuration properties for Selenium Test Suite
- 用Selenium RC从命令行运行Test Suite
- Test Suite
- Creating test database for alias 'postgres'... Got an error creating the test database: permission
- SauceLabs + Selenium+ Nunit For Web Ui Test
- Python for Selenium: build test environment
- Is there a conformance test suite for XML processo
- selenium test
- Rational Test Suite-Purify
- 管理Test Suite
- HTML Test Suite
- Phoronix Test Suite
- Android Compatibility Test Suite
- The Browser Test Suite
- Database Test Suite
- JUnit test suite 结构
- (OK) Phoronix Test Suite
- Empty test suite.
- 心跳的原理和对应的设计
- FFmpeg iOS 编译
- hdu 5040bfs+优先队列 需要存状态
- 快速上手Expression Tree(一):做一做装配脑袋的Expression Tree 习题
- UIWebView加载本地HTML5文件
- Creating configuration properties for Selenium Test Suite
- 利用ASP.NET加密和解密Web.config中连接字符串
- PMC 携手C3 沙龙探究存储技术
- 配置ssh密钥认证自动登录(从物理机ssh到虚拟机)
- 调用系统拍照功能
- LinkedList中定义一个堆栈或者队列
- MYSQL 加密SQL
- 车载系统之 Windows CE 应用软件框架设计
- Spring声明式事务配置管理方法