NoSuchWindowError:浏览上下文已被GeckoDriver Firefox和Protractor(Selenium)丢弃

时间:2019-02-04 11:28:17

标签: angularjs linux selenium protractor geckodriver

我正在尝试使用量角器运行一个简单的测试脚本。

环境:

Node Version: v9.8.0
Protractor Version: 5.4.1
Angular Version: 1.x
Browser(s): Mozilla Firefox 60.1.0
Operating System and Version: HELiOS release 6.10

这是我的量角器配置文件。

exports.config = {
  specs: ['todo-spec.js'],
  capabilities: {
    browserName: 'firefox',
    marionette : true
  }
};

这是我的测试脚本(todo-spec.js)

describe('application homepage', function() {
  it('should open homepage', function() {
    console.log("Opening localhost app");
    browser.get('http://localhost:8080/app/');
    browser.sleep(20000); // just to check if application loaded or not
  });
});

这是我的 node_modules / protractor / node_modules / webdriver-manager / selenium / 目录,如下所示:

enter image description here

当我使用/path/to/protractor conf.js运行测试时,出现以下错误。

[16:51:03] I/launcher - Running 1 instances of WebDriver
[16:51:03] I/local - Starting selenium standalone server...
[16:51:04] I/local - Selenium standalone server started at http://<ip-address>:45089/wd/hub
Started
Opening localhost
F

Failures:
1) application homepage should open homepage
  Message:
    Failed: Browsing context has been discarded
    Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
    System info: host: 'HOSTNAME', ip: 'ip_address', os.name: 'Linux', os.arch: 'i386', os.version: '2.6.32-754.3.5.el6.x86_64', java.version: '1.8.0_181'
    Driver info: driver.version: unknown
  Stack:
    NoSuchWindowError: Browsing context has been discarded
    Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
    System info: host: 'HOSTNAME', ip: 'ip_address', os.name: 'Linux', os.arch: 'i386', os.version: '2.6.32-754.3.5.el6.x86_64', java.version: '1.8.0_181'
    Driver info: driver.version: unknown
        at Object.checkLegacyResponse (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/error.js:546:15)
        at parseHttpResponse (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/http.js:509:13)
        at doSend.then.response (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/http.js:441:30)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:118:7)
    From: Task: Protractor.get(http://localhost:8080/app/) - reset url
        at thenableWebDriverProxy.schedule (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
        at ProtractorBrowser.executeScriptWithDescription (/export/home/test/protractor_test_2/node_modules/protractor/built/browser.js:404:28)
        at driver.controlFlow.execute.then.then.then (/export/home/test/protractor_test_2/node_modules/protractor/built/browser.js:679:25)
        at ManagedPromise.invokeCallback_ (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/promise.js:1376:14)
        at TaskQueue.execute_ (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/promise.js:3084:14)
        at TaskQueue.executeNext_ (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/promise.js:3067:27)
        at asyncRun (/export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/promise.js:2927:27)
        at /export/home/test/protractor_test_2/node_modules/selenium-webdriver/lib/promise.js:668:7
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:118:7)
    From: Task: Run it("should open homepage") in control flow
        at UserContext.<anonymous> (/export/home/test/protractor_test_2/node_modules/jasminewd2/index.js:94:19)
    From asynchronous test:
    Error
        at Suite.<anonymous> (/export/home/test/protractor_test_2/todo-spec.js:2:3)
        at Object.<anonymous> (/export/home/test/protractor_test_2/todo-spec.js:1:63)
        at Module._compile (module.js:649:30)
        at Object.Module._extensions..js (module.js:660:10)
        at Module.load (module.js:561:32)
        at tryModuleLoad (module.js:501:12)

1 spec, 1 failure
Finished in 0.159 seconds

[16:51:06] I/local - Shutting down selenium standalone server.
[16:51:06] I/launcher - 0 instance(s) of WebDriver still running
[16:51:06] I/launcher - firefox #01 failed 1 test(s)
[16:51:06] I/launcher - overall: 1 failed spec(s)
[16:51:06] E/launcher - Process exited with error code 1

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

此错误消息...

Failed: Browsing context has been discarded

...表示 GeckoDriver Marionette 之间的通信中断。

有关 GeckoDriver 二进制版本的更多信息将为我们提供一些有关发生了什么错误的线索。但是,由于以下多种因素,可能会发生此问题:

此用例

此问题的根本原因似乎是 MemoryUsage 。根据{{​​3}},这是间歇性的 。此问题曾经被标记为已解决,然后再次被标记为重新打开

@Madhan在使用Intermittent awsy\test_memory_usage.py TestMemoryUsage.test_open_tabs | NoSuchWindowException: Browsing context has been discarded应用程序和量角器时提到的始终包括:

waitForAngularEnabled(true);

最后,根据与 GeckoDriver Selenium Firefox浏览器一起使用时的最佳实践,遵循以下兼容性图表:

AngularJS

supported_platforms_geckodriver_24

答案 1 :(得分:0)

可以通过以下配置解决此问题。

- Protractor: v5.4.1 
- Selenium JAR driver: selenium-server-standalone-3.141.59.jar 
- geckodriver:geckodriver-v0.20.0-linux64

我们还需要在量角器conf文件中提供geckodrvier的路径。

geckoDriver: 'node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.20.0'

默认情况下,webdriver-manager将下载最新版本的geckodriver,该版本为0.24.0。但是所需的geckdriver是v0.20.0,因此我手动下载了它,并将其放在node_modules / protractor / node_modules / webdriver-manager / selenium /目录中。

希望这对面临类似问题的人们有所帮助。