selenium多浏览器支持

编写配置文件如下:

#配置需要使用的浏览器
#(Firefox ,Chrome or IE)
#browser = Firefox
#browser = Chrome
browser = IE

#配置需要测试的网站
webSite = http://zc.qq.com/chs/index.html

#报告名称
reportName = 注册QQ号测试

#浏览器驱动为位置
#browserLocation = F:/selenium/Mozilla Firefox/Mozilla Firefox/firefox.exe
#browserLocation = F:/Google/chromedriver.exe
browserLocation  = C:/Program Files/Internet Explorer/IEDriverServer.exe

#浏览器启动时需要加载的插件的位置
#fireBugLocation = webdriver.firefox.bin
#fireBugLocation = webdriver.chrome.driver
fireBugLocation  = webdriver.ie.driver

浏览器启动文件如下:

package SecondTest;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SetUp {
    private static Logger log = Logger.getLogger(SetUp.class);//日志
    
      public WebDriver lanuch() throws Exception{
          Properties config = new Properties();
          WebDriver dr = null;
          InputStreamReader fn = new InputStreamReader(new FileInputStream
                  (System.getProperty("user.dir")+"/src/SecondTest/config.properties"),"UTF-8");
          config.load(fn);
          String browser = config.getProperty("browser");//读取要使用的浏览器
          String fileBugLoacation = config.getProperty("fireBugLocation");//读取浏览器插件位置
          String browserLocation = config.getProperty("browserLocation");//读取浏览器驱动位置
          String weburl = config.getProperty("webSite");//读取测试网站
          
          if(browser.equals("Firefox")){//使用火狐浏览器
              System.setProperty //环境配置
              (fileBugLoacation, browserLocation);
              log.info("打开Firefox浏览器");
              dr=new FirefoxDriver();//打开浏览器
              dr.get(weburl);
          }else if(browser.equals("Chrome")){//使用谷歌浏览器
              System.setProperty
              (fileBugLoacation,browserLocation);
              ChromeOptions opt = new ChromeOptions();

                opt.setBinary("C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chrome.exe");
              //谷歌浏览器地址

              log.info("打开Chrome浏览器");
              dr = new ChromeDriver(opt);
              dr.get(weburl);
          }else{//使用IE浏览器
                System.setProperty
              (fileBugLoacation,browserLocation);
              log.info("打开IE浏览器");
              dr = new InternetExplorerDriver();
              dr.get(weburl);
          }
              log.info(dr);
              dr.manage().window().maximize();
              return dr;
      }
}

转载于:https://www.cnblogs.com/Mr-xiao/p/6993020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值