Selenium与Firefox版本不兼容

更新Firefox到54.0后发现以前的基于Selenium 2.48.2的测试程序报错:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 m

百度后得知Selenium和Firefox间存在版本兼容问题。(其它浏览器相信也是一样的)

更新selenium到3.4.0后运行测试,依然报错:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

到上述地址后发现,自Selenium 3后以Geckodriver作为Firefox的默认WebDriver。Geckodriver是一个以代理的形式,让Selenium程序和基于Gecko的浏览器,如Firefox交互的程序。
注:此版本(v0.17.0)的Geckodriver还没有实现所有功能,不能完美兼容Selenium,并且对Firefox v53或更新版本支持更好。

Selenium会从系统环境参数里寻找Geckodriver,你可以
1,在将其设置在path环境参数中
set PATH=%PATH%;%gecko_path%
2,在代码中添加系统变量
System.setProperty(“webdriver.gecko.driver”, “gecko_path”);
3,在启动java时添加参数
java -Dwebdriver.gecko.driver=%gecko_path% YourApplication
在bash环境中也可以用下面方式设置并找到geckodriver
% export PATH=$PATH:/home/user/bin
% whereis geckodriver
geckodriver: /home/user/bin/geckodriver

本人采取第一种方式,在系统环境变量path中添加Geckodriver的路径,旧测试程序正确运行。部分输出:
1498814251334 geckodriver INFO Listening on 127.0.0.1:15516
1498814252998 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args [“-marionette”]
1498814283823 Marionette INFO Listening on port 52325

P.S. 从下面路径能查看Selenium支持的FireFox版本:
selenium-server-standalone-3.4.0.jar\org\openqa\selenium\firefox\webdriver.xpi\install.rdf


<em:targetApplication>
    <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}em:id>
        <em:minVersion>3.0em:minVersion>
        <em:maxVersion>48.0em:maxVersion>
    Description>
em:targetApplication>

你可能感兴趣的:(selenium)