我用量角器进行e2e测试。当我的应用程序在服务器上运行时,测试通过正常,然后浏览器关闭,但是当服务器关闭时,浏览器仍然存在(Firefox,Chrome)。在我的本地机器上可以,但我正在尝试在远程CI机器上运行测试,并担心如果服务器无法运行,测试可能会产生多个浏览器窗口。如何确保量角器在这种情况下关闭浏览器窗口?
这是我的配置:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'../test/e2e/*.js'
],
capabilities: {
'browserName': 'firefox'
},
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
,测试是:
'use strict';
describe('typicaClient', function() {
browser.get('index.html');
it('test', function() {
expect('str').toMatch('str');
});
});
答案 0 :(得分:2)
量角器让浏览器在那些无法识别且无法处理的错误上打开。
查看以下示例。由spawn()
进程抛出的此错误未被Protractor处理,并以错误代码退出 - 199
describe('sample test', function(){
it('Sample Check', function(){
browser.get("http://www.protractortest.org/#/");
browser.sleep(5000);
var terminal = require('child_process').spawn('34e3545')
});
});
输出:
[18:26:46] I/local - Starting selenium standalone server...
[18:26:46] I/launcher - Running 1 instances of WebDriver
[18:26:46] I/local - Selenium standalone server started at http://192.168.1.5:61146/wd/hub
Started
[18:26:49] E/launcher - spawn 34e3545 ENOENT
[18:26:49] E/launcher - Error: spawn 34e3545 ENOENT
at exports._errnoException (util.js:873:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
[18:26:49] E/launcher - Process exited with error code 199
要避免这些,请在非量角器命令中正确处理错误
describe('sample test', function(){
it('Sample Check', function(){
browser.get("http://www.protractortest.org/#/");
browser.sleep(5000);
var terminal = require('child_process').spawn('34e3545').on('error', function(err) {
fail('Test is failing because we provided an invalid process')
});
});
});
在这种情况下输出:
[18:57:22] I/local - Starting selenium standalone server...
[18:57:22] I/launcher - Running 1 instances of WebDriver
[18:57:22] I/local - Selenium standalone server started at http://192.168.1.5:49867/wd/hub
Started
F
Failures:
1) sample test Sample Check
Message:
Failed: Test is failing because we provided an invalid process
Stack:
Error: Failed: Test is failing because we provided an invalid process
at ChildProcess.<anonymous> (C:\Users\ayannam\WebstormProjects\demo\errorHandle.js:7:13)
at emitOne (events.js:77:13)
at ChildProcess.emit (events.js:169:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
1 spec, 1 failure
Finished in 6.582 seconds
查看此情况处理未处理的异常并且Protractor抛出错误代码 - 1正常处理