若将浏览器的配置,及url写在了.properties文件中,则需要读取该配置文件;

1.若测试项目的结构如下:

testng: 获取src/main/resources资源文件夹下路径

2.在ReadProperties.java 需要获取config.properties的路径:

testng: 获取src/main/resources资源文件夹下路径

如下:

 public Properties readProperties(){
        //创建对象
        Properties pro = new Properties();
        //读取properties文件到缓存[获取src/main/resources下文件的绝对路径]
        try {

            BufferedInputStream in = (BufferedInputStream) this.getClass().getResourceAsStream("/config.properties");

            //加载缓存到pro对象
            pro.load(in);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //返回pro对象
        return pro;
    }

 

相关文章: