无法使用Microsoft Edge运行Protractor / Jasmine测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法使用Microsoft Edge运行Protractor / Jasmine测试相关的知识,希望对你有一定的参考价值。

我正在开发一个项目,开始使用Protractor和Jasmine测试Node / Angular应用程序。我有一个POC在大多数浏览器中工作但在MS Edge上遇到很多麻烦。这是我的环境:

OS: Windows 10 Pro (Version 1709, OS Build 16299.98)
Edge: 41.16299.15.0
Edgehtml: 16.16299
MS Web Driver: 10.0.16299.15
Node: 6.12.0
Protractor: 5.2.1
Jasmine: 2.8.0
Selenium: 3.8.1

当我在Chrome,Firefox和IE(11)中运行测试时,行为很好(测试以预期结果运行)。但是,对于MS Edge,在测试规范甚至可以运行之前,该过程会失败。

示例代码/输出使用Protractor教程,但在使用我们的应用程序时遇到了同样的问题。

工作conf.js(适用于Chrome和Firefox)

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['./spec/spec.js'],

  multiCapabilities: [
    { 'browserName': 'chrome' },
    { 'browserName': 'firefox', 'marionette': true, 'firefox_binary': "C:\Program Files\Mozilla Firefox\firefox.exe" }//,
]  
}

失败的conf.js(对于MS Edge)

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:17556',
  specs: ['./spec/spec.js'],

  capabilites: { browserName: 'MicrosoftEdge' }
}

spec.js

// spec.js
describe('Protractor Demo App', function() {
  it('should have a title', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');

    expect(browser.getTitle()).toEqual('Super Calculator');
  });
});

启动Microsoft Web驱动程序后运行MS Edge测试时,会发生以下情况:

$ protractor conf.js
[14:14:18] I/launcher - Running 1 instances of WebDriver
[14:14:18] I/hosted - Using the selenium server at http://localhost:17556
[14:14:20] E/launcher - Error code: 135
[14:14:20] E/launcher - Error message: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:17556
[14:14:20] E/launcher - Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:17556
    at ClientRequest.<anonymous> (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverhttpindex.js:238:15)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:310:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1281:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
From: Task: WebDriver.createSession()
    at Function.createSession (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverlibwebdriver.js:769:24)
    at Function.createSession (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverchrome.js:761:15)
    at createDriver (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverindex.js:170:33)
    at Builder.build (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverindex.js:626:16)
    at Hosted.getNewDriver (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractoruiltdriverProvidersdriverProvider.js:53:33)
    at Runner.createBrowser (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractoruilt
unner.js:195:43)
    at q.then.then (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractoruilt
unner.js:339:29)
    at _fulfilled (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:834:54)
    at self.promiseDispatch.done (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:863:30)
    at Promise.promise.promiseDispatch (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:796:13)
[14:14:20] E/launcher - Process exited with error code 135

问题似乎是在某个地方,它说它在'localhost'上使用服务器,但后来在'127.0.0.1'上发出请求。从理论上讲,它们是一样的。但在操作中,只有'localhost'才有响应。如果我尝试访问127.0.0.1:17556它没有响应。

This website could not be found
Error Code: INET_E_RESOURCE_NOT_FOUND

我一直在寻找很长一段时间(这里,SQA,以及关于GitHub的Protactor讨论)以获取相关信息,但尚未找到解决方案。关于GitHub的一些讨论表明,使用Protractor的MS Edge测试正在进行中。有没有人能够使用此版本的MS Edge和MS Webdriver成功运行Protractor测试?

最后一点信息:我可以访问另一台具有旧版Edge(10240)的Windows 10机器。在那台机器上我没有这个问题(localhost vs 127.0.0.1),但是,它已经足够老了仍然存在异步问题,我无法用它来测试Protractor。

谢谢!

UPDATE

规范文件没有改变,但我更新了配置文件(conf.js):

// conf.js
exports.config = {
    directConnect: false,
    framework: 'jasmine',
    specs: ['./spec/spec.js'],
    seleniumAddress: 'http://localhost:4444/wd/hub',

    multiCapabilities: [
        //{ 'browserName': 'chrome' },
        //{ 'browserName': 'firefox', 'marionette': true, 'firefox_binary': "C:\Program Files\Mozilla Firefox\firefox.exe" },
        { 'browserName': 'MicrosoftEdge' }
    ]
};

启用后,Chrome和Firefox都可以运行测试。

Edge因以下情况而失败(超时等待驱动程序服务器启动):

$ protractor conf.js
[13:13:53] I/launcher - Running 1 instances of WebDriver
[13:13:53] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[13:14:13] E/launcher - Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'QA-01', ip: '10.1.1.80', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9.0.1'
Driver info: driver.version: unknown
[13:14:13] E/launcher - WebDriverError: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'QA-01', ip: '10.1.1.80', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9.0.1'
Driver info: driver.version: unknown
    at WebDriverError (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverliberror.js:27:5)
    at Object.checkLegacyResponse (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverliberror.js:546:15)
    at parseHttpResponse (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverlibhttp.js:509:13)
    at doSend.then.response (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverlibhttp.js:441:30)
    at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
    at Function.createSession (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverlibwebdriver.js:769:24)
    at createDriver (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverindex.js:170:33)
    at Builder.build (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesselenium-webdriverindex.js:635:14)
    at Hosted.getNewDriver (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractoruiltdriverProvidersdriverProvider.js:53:33)
    at Runner.createBrowser (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractoruilt
unner.js:195:43)
    at q.then.then (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractoruilt
unner.js:339:29)
    at _fulfilled (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:834:54)
    at self.promiseDispatch.done (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:863:30)
    at Promise.promise.promiseDispatch (C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:796:13)
    at C:UsersUSER.NAMEAppDataRoaming
pm
ode_modulesprotractor
ode_modulesqq.js:556:49
[13:14:13] E/launcher - Process exited with error code 199

和以前一样 - 在旧版本的Windows 10,Edge(10240)和Edge驱动程序上的相同设置会尝试运行测试(尽管存在异步执行问题)。

这种设置可能比我之前使用的更好,但总体结果是相同的。量角器测试(在此机器上)未在MS Edge(16299)中运行。

任何见解或建议都非常感谢。

谢谢!

答案

根据我的收集,您需要告诉量角器在哪里可以找到Edge驱动程序。我发现了一些博客文章,提到在配置中添加seleniumArgs

seleniumArgs: ['-Dwebdriver.edge.driver=your/path/to/MicrosoftWebDriver.exe']
另一答案

经过一段时间并使用另一台Windows 10机器后,我成功地运行了这个简单的测试。

我只能得出结论,该特定机器上有某些东西妨碍了测试的正确执行。我无法弄清楚那是什么,但是,“它有效吗?”问题得到了回答。它确实(这是人们所期望的)。

conf.js:

// conf.js
exports.config = {
  directConnect: false,
  framework: 'jasmine',
  specs: ['./spec/spec.js'],
  seleniumAddress: 'http://localhost:4444/wd/hub',

  multiCapabilities: [
    { 'browserName': 'chrome' },
    { 'browserName': 'firefox', 'marionette': true },
    { 'browserName': 'MicrosoftEdge' }
  ]
};

spec.js:

// spec.js
describe('Protractor Demo App', function() {
  it('should have a title', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');

    expect(browser.getTitle()).toEqual('Super Calculator');
  });
});

结果:

[10:07:15] I/launcher - 0 instance(s) of WebDriver still running
[10:07:15] I/launcher - chrome #01 passed
[10:07:15] I/launcher - MicrosoftEdge #21 passed
[10:07:15] I/launcher - firefox #11 passed

以上是关于无法使用Microsoft Edge运行Protractor / Jasmine测试的主要内容,如果未能解决你的问题,请参考以下文章

Microsoft Edge 无法使用专用 IP 访问 VM

以管理员身份运行 Microsoft Edge 时不支持登录

解决撤梯后『Microsoft Edge』无法访问的问题

windows 10中Microsoft Edge Beta登录账户提示:以管理员身份运行 Microsoft Edge 时不支持登录。请以非管理员身份重新启动 Microsoft Edge,然后重新

Microsoft Edge,媒体查询无法正常工作

使用Microsoft Edge设置Protractor