zoukankan      html  css  js  c++  java
  • 读取config配置

    在搭建自动化测试框架时,经常会使用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
  • 相关阅读:
    性能测试术语讲解
    Silverlight 部署
    C#数据库SQLServer查询、修改数据
    有一点点背
    Ajax与XMLHttpRequest对象
    ServletListener 之 监听HTTP会话
    JAVA中几种常见集合的使用实例
    [转]全面接触Java集合框架(二)
    自定义标签之 SimpleTag的开发
    jsp常用内置对象
  • 原文地址:https://www.cnblogs.com/dingziyin/p/6093630.html
Copyright © 2011-2022 走看看