selenium3 文件系列之------读取properties文件

      一个eclipse工程会有很多配置文件,有的配置文件是写在properties里,也有写在xml文件里的。这个总结一下是自动化测试是如何读取properties文件。

一、准备config.properties

在项目根路径创建一个TestConfig的文件夹,在该文件夹创建一个config.properties文件(右击项目,选择new—file)

config.properties文件具体内容为:

 

二、   建一个测试类

package first;

 

import java.io.FileInputStream;

import java.io.InputStream;

import java.util.Properties;

 

public class ReadPropertiesFile {

    public  static String browser_Name;

    public static String server_Url;

    public static void main(String[] args)throws Exception Properties p=new Properties();

   InputStream ips=new FileInputStream(".\TestConfig\config.properties");

    p.load(ips);

    browser_Name=p.getProperty("browserName"); //参数为config.properties里的值

    server_Url=p.getProperty("serverUrl");//参数为config.properties里的值

    System.out.println(browser_Name);

    System.out.println(server_Url);

    ips.close();

}

}

三、   运行结果

好了,今天的学习总结就到这里了,希望大家多多关注,一起学习~

原文地址:https://www.cnblogs.com/miaojjblog/p/9684806.html