我正在开发一个项目,开始使用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 Driver后运行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:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.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:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at Function.createSession (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\chrome.js:761:15)
at createDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:170:33)
at Builder.build (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:626:16)
at Hosted.getNewDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\driverProvider.js:53:33)
at Runner.createBrowser (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:195:43)
at q.then.then (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:339:29)
at _fulfilled (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.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。
谢谢!
更新
规范文件没有改变,但我更新了配置文件(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:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:27:5)
at Object.checkLegacyResponse (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at createDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:170:33)
at Builder.build (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:635:14)
at Hosted.getNewDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\driverProvider.js:53:33)
at Runner.createBrowser (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:195:43)
at q.then.then (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:339:29)
at _fulfilled (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
[13:14:13] E/launcher - Process exited with error code 199
和以前一样 - 旧版本的Windows 10,Edge(10240)和Edge驱动程序上的相同设置会尝试运行测试(尽管存在异步执行问题)。
这个设置可能比我之前使用的更好,但整体结果是一样的。量角器测试(在此机器上)未在MS Edge(16299)中运行。
非常感谢任何见解或建议。
谢谢!
答案 0 :(得分:0)
从我可以收集的内容中,您需要告诉量角器在哪里可以找到Edge驱动程序。我发现了一些博文,提到在配置中添加了seleniumArgs
。
seleniumArgs: ['-Dwebdriver.edge.driver=your/path/to/MicrosoftWebDriver.exe']
答案 1 :(得分:0)
经过额外的时间并使用另一台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