我无法让量角器调试器与节点 8 async/await 和 Angular 6 一起使用。以旧方式返回到节点 7elementExplorer
, browser.pause()
and browser.debugger()
不是一个选择。也因为在未来,control flow
正在从 Selenium 中删除,我一直读到使用 Node 8 async/await 而不是更好的调试体验control flow
.
我正在使用 Angular 6.0.3、Angular CLI 6.0.5、节点 8.11.2 和 chrome 71.0.3578.98。我通过使用 CLI 生成测试应用程序来重现该问题:
ng new stack-overflow-debugging-protractor --style=scss --routing
使用 Angular CLI 生成此应用程序会自动安装和配置 Protractor 5.3.2。
我有一个运行的简单测试ng e2e
成功:
describe('workspace-project App', () => {
it('should display welcome message', () => {
browser.get('/');
expect(element(by.css('app-root h1')).getText()).toEqual('Welcome to app!');
});
});
我按照这个文档来设置我的调试环境 https://github.com/angular/protractor/blob/master/docs/debugging.md
为了使其与 async/await 一起工作,我需要禁用control flow
so in protractor.conf.js
I add SELENIUM_PROMISE_MANAGER: false
and in ./e2e/tsconfig.e2e.json
我改变"target": "es5"
into "target": "es2017"
在 e2e 测试中我添加async
and await
并添加命令debugger
describe('workspace-project App', () => {
it('should display welcome message', async () => {
await browser.get('/');
debugger;
await expect(element(by.css('app-root h1')).getText()).toEqual('Welcome to app!');
});
});
当我执行时ng e2e
它仍然成功运行:
我在终端会话中运行调试器:
node --inspect-brk ./node_modules/protractor/bin/protractor ./e2e/protractor.conf.js
我打开 chrome 检查器chrome://inspect/#devices
在浏览器中找到当前运行的目标并点击inspect
。然后我点击按钮resume script execution
(或 F8),并且测试应在第一行暂停debugger
关键词。
但事实并非如此,Chrome 会自动打开一个新窗口并显示错误ERR_CONNECTION_REFUSED
。 Chrome DevTools 的控制台是空的。终端会话给出:
E/protractor - Could not find Angular on page http://localhost:4200/ : retries looking for angular exceeded
Failed: Angular could not be found on the page http://localhost:4200/. If this is not an Angular application, you may need to turn off waiting for Angular.
Please see https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load
所以我阅读了建议并添加getPageTimeout: 60000
to protractor.conf.js
到 。然后我得到错误:
Failed: Error while running testForAngular: script timeout: result was not received in 11 seconds
似乎是同样的错误,所以我改变了protractor.conf.js
line allScriptsTimeout: 11000
into 60000
。然后我得到错误:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
(node:11716) UnhandledPromiseRejectionWarning: Error: 'fail' was used when there was no current spec, this could be because an asynchronous test timed out
(node:11716) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which wasnot handled with .catch(). (rejection id: 1)
再次,所以我改变protractor.conf.js
line defaultTimeoutInterval: 30000
作为一部分jasmineNodeOpts
into 60000
。同样的错误。
我也尝试了更高的值,200000,但结果等待时间更长,但错误是相同的。
谁知道这个问题的解决方案?