zoukankan      html  css  js  c++  java
  • selenium之如何启动不同浏览器的driver,兼容性就是这么简单!

    一.概述

    大家都知道selenium支持不同的浏览器,而webdriver启动项目时需要启动浏览器的driver,于是乎配置不同的浏览器来启动不同的driver势在必行了,

    下面请看代码;

    二.编写一个初始化selenium测试框架driver类

    public class SeleniumDriver {
        
        private Log log=new Log(this.getClass());
        
        private WebDriver driver;
        
        public WebDriver getDriver() {
            return driver;
        }
    
        public SeleniumDriver(){
            this.initialDriver();
        }
        
        public void initialDriver(){
            if("firefox".equals(Config.browser)){
                ProfilesIni allProfiles = new ProfilesIni(); 
                FirefoxProfile profile = allProfiles.getProfile("default");
                System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
                driver = new FirefoxDriver();
            }else if("ie".equals(Config.browser)){
                System.setProperty("webdriver.ie.driver", "files/IEDriverServer64.exe");
                DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
                capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                capabilities.setCapability("ignoreProtectedModeSettings",true);       
                driver = new InternetExplorerDriver(capabilities);
            }else if("chrome".equals(Config.browser)){
                System.setProperty("webdriver.chrome.driver", "files/chromedriver.exe");
                ChromeOptions options = new ChromeOptions();
                options.addArguments("--test-type");
                driver = new ChromeDriver(options);
            }else{    
                log.info(Config.browser+" 的值不正确,请检查!");
                throw new DefinedException(Config.browser+" 的值不正确,请检查!");
            }
        }

    三.关于Config类的情况

    Config是一个加载了浏览器信息的静态类,通过该类可以读取到浏览器的配置信息。。。。。。。哈哈,对于上面的代码,你是否豁然开朗了许多呢!!!!!!

  • 相关阅读:
    C#开发BIMFACE系列44 服务端API之计算图纸对比差异项来源自哪个图框
    C#开发BIMFACE系列43 服务端API之图纸拆分
    C#开发BIMFACE系列42 服务端API之图纸对比
    利用 OpenVINO 进行推理加速(一)
    虚拟化技术概述(一)
    利用目标跟踪来提高实时人脸识别处理速度
    目标追踪(Object Tracking)概念的简要介绍
    Python3 使用IMAP接收邮件
    Git使用
    Git基础
  • 原文地址:https://www.cnblogs.com/liwu/p/5010066.html
Copyright © 2011-2022 走看看