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
  • 相关阅读:
    完美兼容的纯CSS下拉菜单
    ASP.Net分页控件发布(转)
    ASP.NET(C#)FileUpload实现上传限定类型和大小的文件到服务器
    完美的ASP.NET页面分页控件
    Asp.net上传图片同时生成缩略图和水印图
    狗狗约瑟夫环(链表)
    丹叔链表
    囧囧出的题……他自己都没过(一元多项式之和)
    More is better
    最短路
  • 原文地址:https://www.cnblogs.com/dingziyin/p/6093630.html
Copyright © 2011-2022 走看看