博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读取config配置
阅读量:4590 次
发布时间:2019-06-09

本文共 1746 字,大约阅读时间需要 5 分钟。

在搭建自动化测试框架时,经常会使用config.properties文件存储配置,文件内容格式如下:

读取config.properties文件代码如下:

public class Putils {        public static Properties readConfig(){        Properties pps = new Properties();        String PATH="/config.properties";        try {            InputStream in=Putils.class.getResourceAsStream(PATH);            pps.load(in);        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }        return pps;    }    public String getProperties(String key){        //考虑命令行的方式的读取        Properties properties=Putils.readConfig();        String value=properties.getProperty(key, "");        return value;    }    }
View Code

调用方式:

public static WebDriver initDriver(){        Putils propertyUtils=new Putils();        String browserType=propertyUtils.getProperties("browserType");        if("ie".equals(browserType.trim())){            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();            ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);            driver = new InternetExplorerDriver(ieCapabilities);            driver.manage().window().maximize();        }else if("chrome".equals(browserType.trim())){            ChromeOptions option = new ChromeOptions();              option.addArguments("-test-type");              //最大化浏览器窗口              option.addArguments("-start-maximized");              driver = new ChromeDriver(option);         }else{                driver= new FirefoxDriver();        }        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);        return driver;    }
View Code

 

转载于:https://www.cnblogs.com/dingziyin/p/6093630.html

你可能感兴趣的文章
简洁的MysqlHelper
查看>>
Android面试收集录2 Broadcast Receiver详解
查看>>
基于HTML5实现的中国象棋游戏
查看>>
Luogu P2024 [NOI2001]食物链 | 并查集
查看>>
openLayers3 中实现多个Overlay
查看>>
SQlServer2008 之 定时执行sql语句作业的制定
查看>>
函数式编程
查看>>
由浅入深之Jquery笔记(1)
查看>>
IE、FF、Chrome浏览器中的JS差异介绍
查看>>
IO模式和IO多路复用
查看>>
Redis常用命令
查看>>
vim 撤销 恢复 快捷键
查看>>
python导入import requests报错
查看>>
Hexo博客搭建
查看>>
内部类详解(很详细)
查看>>
dubbox系列【三】——简单的dubbox提供者+消费者示例
查看>>
常见sql 写法总结
查看>>
Windows xp搭建Windows Phone 7开发环境
查看>>
[bzoj] 1597 土地购买 || 斜率优化dp
查看>>
Lodop的JS模版代码、文档式模版 生成加载赋值博文索引
查看>>