java+selenium+new——读取配置文件——config.properties ——读取配置参数打开浏览器和网址——简单示例

package jkcs;
import java.util.Properties;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import java.io.FileInputStream;

public class dqpzwj 
{

    public static void main(String[] args) 
    {
        // TODO Auto-generated method stub
        
                   Properties  pzwj = new Properties();
        
                   try
                   {
                         pzwj.load(new FileInputStream("src/jkcs/config.properties"));
                   }
                    catch(Exception e)
                    {
                               e.printStackTrace();
                    }
        
                    String pzqd = pzwj.getProperty("qd");
        
                    System.out.println(pzqd);
        
        
                    if ("firefox".contentEquals(pzqd))
                    {
                            System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");    //设置火狐的安装路径,防止系统找不到
       
                            FirefoxDriver driver = new FirefoxDriver();        //初始化FireFox浏览器实例,并打开浏览器
       
                            driver.get(pzwj.getProperty("url"));
                            
                            driver.get("https://www.ifeng.com");
                            
                            driver.quit();
                     }

            

        }

}

 

posted @ 2020-04-06 15:19  小白龙白龙马  阅读(253)  评论(0编辑  收藏  举报