1

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

我知道对于旧版本的 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

当因为“谷歌是你的朋友”而搜索问题时,唯一的回应是“更新你的 Firefox 版本”或“降级你的 Selenium 版本”,但我不能。有人可以解释我如何使它工作吗?甚至可以接受一种解决方法。

谢谢

4

1 回答 1

1

当您使用时Selenium 3.4.0Mozilla Firefox 41.0您需要将您geckodriver的版本降级为v0.17.0v0.16.1v0.16.0.

以下是最后宣布的依赖项:

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 (geckodriver v0.16.1) 的 Java 代码:

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");
    }
}

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

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')
于 2017-08-07T08:33:17.740 回答