在旧版本的Firefox(v41.0)上运行Selenium(v3.4.0)测试

时间:2017-08-07 08:05:13

标签: javascript selenium firefox docker firefox-marionette

经过一段时间浏览互联网后,我无法找到解决方案。由于某些原因,我目前正在尝试在旧版本的Firefox(此处为v41.0)上测试我的应用。我通过docker image of Selenium传递集线器(v3.4.0)和docker image for the Firefox节点(v41.0)。

我知道对于旧版本的Firefox,Geckodriver,并不兼容,但它似乎有一个使用的解决方案

{ "marionette": true }

Firefox节点完美连接到网格。我可以使用docker exec -it <container-id> bash连接到它,但运行测试时会出现问题。

我仍然试图找到它,但我被阻止了。这里是Dockerfile的代码:hub.docker.com/r/selenium/node-firefox/~/dockerfile/用于Firefox节点,这里是测试代码(使用MochaJS)。

test.it("should redirect to Google with FIREFOX 41.0", () => {

    var firefoxCap = Capabilities.firefox();
    firefoxCap.set('marionette', true);

    driver = new webdriver.Builder()
        .usingServer(CONSTANTS.SELENIUM_HUB)
        .withCapabilities(firefoxCap)
        .build();

    driver.get(CONSTANTS.GOOGLE_URL);
    driver.wait(until.titleIs(CONSTANTS.GOOGLE_TITLE));
    driver.wait(until.elementLocated(By.name(CONSTANTS.GOOGLE_SEARCH_KEY))).sendKeys(CONSTANTS.GOOGLE_SEARCH_VALUE);
    driver.findElement(By.name(CONSTANTS.GOOGLE_SEARCH_BUTTON_NAME)).click();
    driver.wait(until.titleIs(CONSTANTS.GOOGLE_SEARCH_TITLE));
    driver.wait(until.elementLocated(By.tagName(CONSTANTS.GOOGLE_RES_LINK))).click();
    driver.wait(until.titleIs(CONSTANTS.GOOGLE_TITLE));
    driver.quit();
});

这里是日志

~/dev/selenium-grids/src$ mocha --timeout 30000 tests.js 
Starting the tests...


  Work with REMOTE URL
    1) should redirect to Google with FIREFOX 41.0


  0 passing (6s)
  1 failing

  1) Work with REMOTE URL should redirect to Google with FIREFOX 41.0:
     WebDriverError: Missing 'marionetteProtocol' field in handshake
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'd4b3266d29f4', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0_131'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
   0:           0x5787ed - backtrace::backtrace::trace::h59229d13f6a8837d
   1:           0x578942 - backtrace::capture::Backtrace::new::h23089c033eded8f0
   2:           0x450aec - geckodriver::marionette::MarionetteHandler::create_connection::h6f7058fccafe4367
   3:           0x425c32 - <webdriver::server::Dispatcher<T, U>>::run::h8f5348b8f5f7c053
   4:           0x40b22c - std::panicking::try::do_call::hb67c6fb6bcd96195
   5:           0x5dc20a - panic_unwind::__rust_maybe_catch_panic
                        at /checkout/src/libpanic_unwind/lib.rs:98
   6:           0x41b943 - <F as alloc::boxed::FnBox<A>>::call_box::h4100941edc372034
   7:           0x5d48a4 - alloc::boxed::{{impl}}::call_once<(),()>
                        at /checkout/src/liballoc/boxed.rs:650
                         - std::sys_common::thread::start_thread
                        at /checkout/src/libstd/sys_common/thread.rs:21
                         - std::sys::imp::thread::{{impl}}::new::thread_start
                        at /checkout/src/libstd/sys/unix/thread.rs:84
      at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:517:15)
      at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:509:13)
      at doSend.then.response (node_modules/selenium-webdriver/lib/http.js:441:30)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:169:7)
  From: Task: WebDriver.createSession()
      at Function.createSession (node_modules/selenium-webdriver/lib/webdriver.js:777:24)
      at Function.createSession (node_modules/selenium-webdriver/firefox/index.js:667:55)
      at createDriver (node_modules/selenium-webdriver/index.js:167:33)
      at Builder.build (node_modules/selenium-webdriver/index.js:629:16)
      at Context.test.it (tests_web.js:64:14)
      at runTest (node_modules/selenium-webdriver/testing/index.js:164:22)
      at node_modules/selenium-webdriver/testing/index.js:185:16
      at new ManagedPromise (node_modules/selenium-webdriver/lib/promise.js:1085:7)
      at controlFlowExecute (node_modules/selenium-webdriver/testing/index.js:184:14)
      at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:3092:14)
      at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:3075:27)
      at asyncRun (node_modules/selenium-webdriver/lib/promise.js:2982:25)
      at node_modules/selenium-webdriver/lib/promise.js:676:7
      at <anonymous>
  From: Task: Work with REMOTE URL should redirect to Google with FIREFOX 41.0
      at Context.ret (node_modules/selenium-webdriver/testing/index.js:183:10)



Closing the tests

在搜索问题时因为&#34; Google是您的朋友&#34;,唯一的回复是&#34;更新您的Firefox版本&#34;或者&#34;降级你的Selenium版本&#34;但我不能。有人可以解释我如何使它工作?即使是变通方法也会被接受。

由于

1 个答案:

答案 0 :(得分:0)

当您使用Selenium 3.4.0处理Mozilla Firefox 41.0时,您需要将geckodriver降级为版本v0.17.0v0.16.1v0.16.0。< / p>

  

以下是最后宣布的依赖:

     

geckodriver v0.18.0 现在建议 Firefox 53 and greater

     

geckodriver v0.16.0 仅与 Selenium 3.4 and greater

兼容

最后,假设geckodriver.exe绝对路径在System/User Path范围内,您必须明确将 marionette 属性设置为 false (强制性)

您的代码块将如下所示:

test.it("should redirect to Google with FIREFOX 41.0", () => {

    var firefoxCap = Capabilities.firefox();
    firefoxCap.set('marionette', false);

    driver = new webdriver.Builder()
        .usingServer(CONSTANTS.SELENIUM_HUB)
        .withCapabilities(firefoxCap)
    .build();

用于打开旧版Mozilla Firefox 47.0.1的Java代码(geckodriver v0.16.1):

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Opening_FIREFOX_legacy 
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver-v0.16.1-win64\\geckodriver.exe");
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        dc.setCapability("firefox_binary", "C:\\Program Files\\Mozilla Firefox47\\firefox.exe");
        dc.setCapability("marionette", false);
        WebDriver driver =  new FirefoxDriver(dc);
        driver.manage().window().maximize();
        driver.get("https://google.com");
    }
}

Python代码打开旧版Mozilla Firefox 47.0.1(geckodriver v0.18.0):

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox47\firefox.exe')
caps = DesiredCapabilities().FIREFOX
caps["marionette"] = False
driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get('https://stackoverflow.com')