zoukankan      html  css  js  c++  java
  • 【转】一文搞定web自动化环境常见问题

    Firefox

    1. Firefox路径问题

    firefox火狐浏览器去完成自动化测试时,代码报了如下错误:

    Cannot find firefox binary in PATH. mark sure firefox is installed

    错误原因:

    firefox安装在其它路径,不是默认的安装路径

    解决办法:

    指定firefox可执行文件路径:webdriver.firefox.bin

    代码设置:

    System.setProperty("webdriver.firefox.bin", "D:\Program Files\Mozilla Firefox\firefox.exe");
    

    2. selenium 3.x Firefox驱动问题

    使用selenium3.x+firefox火狐浏览器去完成自动化测试时,代码报了如下错误:

    The path to the driver executable must be set by the webdriver.gecko.driver system properity

    错误原因:

    缺少火狐浏览器驱动包。如果selenium版本是3.x的,需要使用驱动包

    解决办法:

    往项目中添加火狐驱动包,并加载驱动的配置。至于该驱动版本适配的浏览器和selenium版本在驱动的change log里有说明(如:使用selenium 3.5.1+firefox 56)

    代码设置:

    System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver.exe");
    

    3. selenium与驱动版本匹配问题

    使用selenium2.x版本+firefox去完成自动化测试时,代码报了如下错误:

    Unable to connect to host 127.0.0.1 on port 7055 after 45000ms

    错误总结:

    firefox浏览器版本和selenium版本不适配。

    解决办法:

    建议降级火狐版本到47以下(比如:selenium 2.53.0+firefox 46)

    4.selenium for firefox说明

    selenium 2.x

    selenium 2.x中自动集成了firefox驱动。

    因此只须selenium 版本与firefox浏览器版本对应即可

    selenium版本Firefox浏览器
    2.25.0 v 18
    2.30.0 v 19
    2.31.0 v 20
    2.42.2 v 29
    2.44.0 v 33 (不支持31)
    2.52.0 v 45.0
    2.53.0 v 46.0
    2.53.1 v 47.0.1

    selenium 3.x

    selenium,geckodriver,firefox 对应版本说明:

    selenium版本geckodriver版本Firefox版本
    3.3 0.15 v 48+
    3.4 0.16 v 52
    3.4 0.17 v 52
    3.4 0.18 v 53
    3.5 0.19 v 55
    3.11 0.21 v 57
    • 从selenium 3.0.0开始就要求firefox为48及以上版本
    • selenium 3.x使用的java版本为jdk 1.8
    • selenium 3.x使用geckodriver作为firefox浏览器的驱动的替代

    4、Firefox自动化相关工具链接

    Change log https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG

    Firefox驱动https://github.com/mozilla/geckodriver/releases/

    Firefox各版本 http://ftp.mozilla.org/pub/firefox/releases/

    Firefox驱动 镜像 https://npm.taobao.org/mirrors/geckodriver/

    InternetExplorer

    1. IE浏览器驱动问题

    使用IE浏览器去完成自动化测试时,代码报了如下错误:

    The path to the driver executable must be set by the webdriver.ie.driver system property

    错误总结:

    缺少IE浏览器驱动包

    解决办法:

    往项目中添加IE驱动包,并加载驱动的配置。

    System.setProperty("webdriver.ie.driver", "src/test/resources/IEDriverServer.exe");
    

    下载地址 http://www.seleniumhq.org/download/

    建议下载版本:3.7.0
    http://selenium-release.storage.googleapis.com/index.html?path=3.7/

    IE驱动版本与Selenium版本保持相同即可
    http://selenium-release.storage.googleapis.com/index.html

    2. IE浏览器保护模式问题

    使用IE浏览器去完成自动化测试时,代码报了如下错误:

    Protected Mode Settings are not the same for all zones

    解决方法1:

    浏览器设置(但是换一台电脑就不适用了)
    打开IE浏览器->工具->安全->全部勾选启用保护模式

    解决方法2:

    忽略浏览器保护模式的设置InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
    代码:

    //取消IE安全设置(忽略IE的Protected Mode的设置)
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    

    3. IE浏览器缩放设置

    使用IE浏览器去完成自动化测试时,代码报了如下错误:

    Browser zoom level was set to 125%.It should be set to 100%

    错误总结:

    浏览器缩放级别设置不对导致的(点工具栏页面->缩放设置)

    解决办法:

    忽略此设置:InternetExplorerDriver.IGNORE_ZOOM_SETTING
    代码:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
    

    4. IE浏览器window丢失问题

    使用IE浏览器去完成自动化测试时,代码报了如下错误:

    unable to find element with id -- kw

    错误总结:

    不是因为没有设置等待时间,而是因为之前的window对象已经丢失

    解决办法:

    最快的解决办法是直接指定一个初始化页面
    InternetExplorerDriver.INITIAL_BROWSER_URL
    代码:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com");

    总结解决办法:
    1、针对IE11,需要修改注册表。如果是32位的windows,key值为

    HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet 
    ExplorerMainFeatureControlFEATURE_BFCACHE

    ,如果是64位的windows,key值为

    HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternet 
    ExplorerMainFeatureControlFEATURE_BFCACHE

    如果key值不存在,就添加。之后在key内部创建一个iexplorer.exe,DWORD类型,值为0,我的windows是64位的,修改后的注册表如下图所示: 
    这里写图片描述

    2、

    1 DesiredCapabilities desiredCapabilities=new DesiredCapabilities();
    2 //忽略掉保护模式的设置
    3 desiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
    4 //忽略掉缩放的设置
    5 desiredCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING,true);
    6 
    7 System.setProperty("webdriver.ie.driver","F:\IDEA CODE\TestngANDMockANDSelenium\src\test\resources\IEDriverServer.exe");
    8 //1、打开IE浏览器
    9 InternetExplorerDriver ieDriver=new InternetExplorerDriver(desiredCapabilities);

    之后Selenium就可以正常打开ie浏览器。

    Chrome

    1. chrome浏览器驱动路径

    使用Chrome做测试时,报了如下错误:

    The path to the driver executable must be set by the webdirver.chrome.driver system properity

    解决方案:

    系统设置Chrome驱动文件的路径

    System.setProperty("webdriver.chrome.driver", "xxx");
    

    2. chrome浏览器与chromeDriver匹配问题

    使用chrome浏览器去完成自动化测试时,chrome浏览器停止运行

    chromedriver.exe 已停止工作

    错误总结:

    chrome浏览器版本过高,虽然根据官网上的信息,2.33的chrome驱动支持60-62的谷歌。但是60根本不行

    解决办法:

    降级chrome

    3.Chrome与ChromeDriver版本对照表

    ChromeDriver 版本支持的 Chrome 版本
    v2.41 v67-69
    v2.40 v66-68
    v2.39 v66-68
    v2.38 v65-67
    v2.37 v64-66
    v2.36 v65-67
    v2.35 v62-64
    v2.34 v61-63
    v2.33 v60-62
    v2.32 v59-61
    v2.31 v58-60
    v2.30 v58-60
    v2.29 v56-58

    chrome浏览器各版本
    http://www.chromedownloads.net/chrome64win/

    禁止谷歌浏览器更新
    https://jingyan.baidu.com/article/76a7e409f2137afc3b6e15be.html

    ChromeDriver 镜像 http://npm.taobao.org/mirrors/chromedriver

    Selenium 镜像 http://npm.taobao.org/mirrors/selenium

    JDK版本问题

    使用3.x的selenium来完成自动化测试时,代码报了如下错误:

    Exception in thread "main" java.lang.UnsupportedClassVersionError:

    错误总结:

    3.x的selenium需要1.8的jdk,可能jdk版本过低

    解决办法:

    降级selenium版本,或提高jdk的版本为1.8

    =====请大家尊重原创,如要转载,请注明出处:转载自:https://www.cnblogs.com/tudou-22/,谢谢!!=====
    • =====有任何疑问,欢迎加微信 qd20150815 (请备注:博客园)=====
     
    每天进步一点点,快乐生活多一点。
  • 相关阅读:
    获取html页面传递过来的参数
    jqueryWeiui+pagehelper滚动加载(实现分页)
    【JS】js随笔
    【Java】Java基础
    【FrameWork】Hibernate
    【FrameWork】Struts2
    去掉inline-block间的间隙
    javascript单例模式
    关于call/apply与bind的一点误解
    git笔记-常用命令
  • 原文地址:https://www.cnblogs.com/yiruliu/p/15268393.html
Copyright © 2011-2022 走看看