• 读取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
  • 相关阅读:
    ruby html解析器
    国外cdn
    ruby爬虫utf8编码相关
    Ruby 1.9 regex (named capture group)正则名组
    ruby爬虫综述
    ruby新加实例方法写法
    机房
    Net::HTTP Cheat Sheet
    ror一键安装包forwin
    病毒6655.la
  • 原文地址:https://www.cnblogs.com/dingziyin/p/6093630.html
Copyright © 2020-2023  润新知