zoukankan      html  css  js  c++  java
  • 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;
          }
    }

  • 相关阅读:
    【来自知乎】AR技术可以通过H5实现吗?不通过APP
    太虚AR
    【ArUco】- Augmented reality library based on OpenCV
    unity MVC简易框架! MVC in Code Control
    游戏服务器框架与互联网产品的认识
    关于 boost::asio::io_service::run() 出现【句柄无效】的问题
    编译luabind-0.9.1 出现 error C2665: 'boost::operator ==' : none of the 4 overloads could convert all the argument types 的解决方案
    javascript 控制 table tr display block 显示模式时,只对第一个单元格有效
    Ogre::UINT 与 其他库的 类型冲突问题
    排序仿函数 出现 std::priority_queue::push() 的 invalid operator < 异常
  • 原文地址:https://www.cnblogs.com/Mr-xiao/p/6993020.html
Copyright © 2011-2022 走看看