Web UI自动化测试框架 使用递归一次性加载配置文件信息(.properties)
来源:互联网 发布:mmd h 动作数据 编辑:程序博客网 时间:2024/05/17 08:03
1.递归加载配置信息代码:(需要注意的是 不同的配置文件不要有相同的key,一般key的命名使用命名空间方式如以下命名方式:
#页面加载时间initDriver.webdriver.pageloadtime = 20#查找元素超时时间(全局)initDriver.webdriver.scanelementtime = 20
package ec.qa.autotest.ui.utility;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.util.ArrayList;import java.util.Enumeration;import java.util.HashMap;import java.util.Properties;import ec.qa.autotest.ui.constants.CommonConstants;public class InitPropertiesUtil {/** * @author xin.wang * @throws 将config下的所有配置文件的内容加载到MAP中,方便快速获取配置文件的值 */public InitPropertiesUtil() {PropertiesUtil.setKeyValueMap(initKeyValueMap(System.getProperty(CommonConstants.CONFIG_FOLDER_PATH_KEY)));}public HashMap<String, String> initKeyValueMap(String floderPath) {HashMap<String, String> proKeyValus = new HashMap<String, String>();ArrayList<File> proFiles = getConfigFiles(new File(floderPath));try {for (File f : proFiles) {setKeyValueToMap(f, proKeyValus);}if (proKeyValus.isEmpty()) {throw new Exception("have no properties files or properties files have no key-value");}} catch (Exception e) {e.printStackTrace();}return proKeyValus;}/** * @author xin.wang * @see 将所有properties文件的key,value存入到map中,实现properties值的跨文件读取和快速读取。 */private void setKeyValueToMap(File f, HashMap<String, String> proKeyValues) throws Exception {Enumeration<?> en = geProObj(f.getAbsolutePath()).propertyNames();while (en.hasMoreElements()) {String key = (String) en.nextElement();String Property = geProObj(f.getAbsolutePath()).getProperty(key);proKeyValues.put(key, Property);}}/** * @author xin.wang * @param floderPath * 文件夹在工程中的路径 * @param files * 存放文件的列表对象 * @see 递归获取此文件夹下的所有配置文件 */public ArrayList<File> getConfigFiles(File floderPath, ArrayList<File> files) {for (File f : floderPath.listFiles()) {if (f.isFile() && f.getName().endsWith(".properties")) {files.add(f);continue;}getConfigFiles(f, files);}return files;}public ArrayList<File> getConfigFiles(File floderPath){ArrayList<File> files = new ArrayList<File>();return getConfigFiles(floderPath,files);}/** * @author xin.wang * @see 初始化properties文件的对象 */private Properties geProObj(String FilePath) throws Exception {Properties p = new Properties();InputStream ins = null;try {ins = new BufferedInputStream(new FileInputStream(FilePath));p.load(ins);ins.close();} catch (Exception e) {throw new Exception("can not find the properties file : " + FilePath);}return p;}}
package ec.qa.autotest.ui.utility;import java.util.HashMap;/** * @author xin.wang * @see 获取配置文件的值 */public class PropertiesUtil {private static HashMap<String, String> proKeyValus = null;public static void setKeyValueMap(HashMap<String, String> map){PropertiesUtil.proKeyValus = map;}public static String getProValue(String Key){return proKeyValus.get(Key);}public static HashMap<String, String> getProKVMap(){return proKeyValus;}}
3 在测试用例集启动的时候初始化 InitPropertiesUtil :
@BeforeSuite(alwaysRun = true)public void initTest() throws Exception {System.setProperty(CommonConstants.CONFIG_FOLDER_PATH_KEY, CommonConstants.CONFIG_FOLDER_PATH_VALUE);new InitPropertiesUtil();browserType = PropertiesUtil.getProValue(PropertiesKeys.BROWSER_TYPE).toString();}
4.使用PropertiesUtil工具类获取配置文件的健值实例:
@BeforeMethod(alwaysRun = true)public void initDriver(Method m) throws Exception {ConfigDriverParameters cp = new ConfigDriverParameters();cp.setPageLoadTime(Long.parseLong(PropertiesUtil.getProValue(PropertiesKeys.ADMIN_PORTAL_PAGELOAD_TIME)));cp.setTargetWebSite(PropertiesUtil.getProValue(PropertiesKeys.ADMIN_PORTAL_AUTO_TEST_WEBSITE));cp.setSerachElementTime(Long.parseLong(PropertiesUtil.getProValue(PropertiesKeys.IMPLICITLYWAIT_TIME)));cp.setTestMethod(m);configDriver(cp);}
0 0
- Web UI自动化测试框架 使用递归一次性加载配置文件信息(.properties)
- web【UI】自动化测试
- Web UI自动化应用测试框架实践 - 概览
- 一个简单的Web UI自动化测试框架Java实现
- Web自动化测试框架
- UI自动化测试框架F2etest
- Web UI 自动化测试实践
- Web UI自动化测试原理
- java web 加载配置文件信息
- Web自动化测试框架改进
- web自动化测试框架目录
- 基于webdriver的web UI自动化测试框架(系统架构+测试脚本应用架构)
- 基于webdriver的web UI自动化测试框架(系统架构+测试脚本应用架构)
- 安装protractor进行前端自动化测试-web ui自动化测试
- 自动化测试之Python + selenium = Web UI自动化测试
- 自动化测试之Python + selenium = Web UI自动化测试
- 基于UI Automation的自动化测试框架
- Android UI自动化测试框架Zinc30
- 初来乍到
- 【Java并发编程实战】—–CLH队列锁
- 文字颜色测试
- 几种加密算法的测试,包括对称加密和非对称加密
- git 笔记
- Web UI自动化测试框架 使用递归一次性加载配置文件信息(.properties)
- SimpleDateFormat用法大全及易错分析
- JavaScipr Attr 对checkbox失效问题
- POI导出EXCEL经典实现
- 严重: Exception starting filter struts2 java.lang.NullPointerException
- 解决 百度地图+slidingmenu 切换Fragment闪黑屏问题
- hdu1754I Hate It(线段树)
- java 嵌入式的Web服务器jetty使用例子
- 缓冲区溢出分析第07课:MS06-040漏洞研究——静态分析