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
  • 相关阅读:
    LeetCode 230. Kth Smallest Element in a BST
    LeetCode 114. Flatten Binary Tree to Linked List
    LeetCode 222. Count Complete Tree Nodes
    LeetCode 129. Sum Root to Leaf Numbers
    LeetCode 113. Path Sum II
    LeetCode 257. Binary Tree Paths
    Java Convert String & Int
    Java Annotations
    LeetCode 236. Lowest Common Ancestor of a Binary Tree
    LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
  • 原文地址:https://www.cnblogs.com/dingziyin/p/6093630.html
Copyright © 2011-2022 走看看