调试带有节点8 async/await和angular 6的量角器时出错



我无法让量角器调试器与节点8 async/await和Angular 6一起工作。以elementExplorerbrowser.pause()browser.debugger()的旧方式返回节点7不是一种选择。此外,因为将来将从Selenium中删除control flow,我一直在读到使用节点8 async/await而不是control flow是更好的调试体验。

我使用的是angular 6.0.3、angular CLI 6.0.5、节点8.11.2&铬71.0.3578.98。我通过使用CLI:生成一个测试应用程序来重现这个问题

ng new stack-overflow-debugging-protractor --style=scss --routing

使用angular CLI生成此应用程序会自动安装&配置量角器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!');
});
});

我遵循此文档来设置我的调试环境

为了使其与async/await一起工作,我需要禁用control flow,因此在protractor.conf.js中我添加SELENIUM_PROMISE_MANAGER: false,在./e2e/tsconfig.e2e.json中我将"target": "es5"更改为"target": "es2017"

在e2e测试中,我添加了asyncawait,并添加了命令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添加到protractor.conf.js。然后我得到错误:

Failed: Error while running testForAngular: script timeout: result was not received in 11 seconds

看起来是同样的错误,所以我将protractor.conf.jsallScriptsTimeout: 11000更改为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.jsdefaultTimeoutInterval: 30000作为jasmineNodeOpts的一部分更改为60000。同样的错误。

我还尝试了一个更高的值,200000,但结果等待时间更长,但错误是相同的。

谁知道这个问题的解决办法?

直接运行Protractor不会自动启动应用程序来运行测试,这是ng e2e命令所做工作的一部分。

要解决此问题,您可以使用ng serve在单独的终端窗口中启动应用程序,也可以根据ng e2e命令运行调试器(这将在后台启动应用程序(:

node --inspect-brk ./node_modules/.bin/ng e2e

相关内容

最新更新