错误调试带有节点8异步/等待和角度6的量角器 [英] Error debugging protractor with node 8 async/await and angular 6

查看:77
本文介绍了错误调试带有节点8异步/等待和角度6的量角器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使量角器调试器与节点8 async/await和Angular 6一起使用.以elementExplorerbrowser.pause()browser.debugger()的旧方式返回节点7是不可行的.另外,因为将来会从Selenium中删除control flow,并且我不断阅读到,使用节点8 async/await而不是control flow是一种更好的调试体验.

I can not get the protractor debugger to work with node 8 async/await and Angular 6. Going back to node 7 in the old way with elementExplorer, browser.pause() and browser.debugger() is not an option. Also because in the future, the control flow is being removed from Selenium and I keep reading that it's a better debugging experience using node 8 async/await instead of control flow.

我正在使用角度6.0.3,角度CLI 6.0.5,节点8.11.2&铬71.0.3578.98.我通过使用CLI生成测试应用程序来重现该问题:

I am using angular 6.0.3, angular CLI 6.0.5, node 8.11.2 & chrome 71.0.3578.98. I reproduce the problem by generating a test app with CLI:

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

使用angular CLI生成此应用会自动安装&配置量角器5.3.2.

Generating this app with angular CLI automatically installs & configures protractor 5.3.2.

我有一个简单的测试,成功运行ng e2e:

I have a simple test that runs ng e2e with succes:

describe('workspace-project App', () => {
  it('should display welcome message', () => {
    browser.get('/');
    expect(element(by.css('app-root h1')).getText()).toEqual('Welcome to app!');
  });
});

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

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

To make it work with async/await I need to disable control flow so in protractor.conf.js I add SELENIUM_PROMISE_MANAGER: false and in ./e2e/tsconfig.e2e.json I change "target": "es5" into "target": "es2017"

在e2e测试中,我添加asyncawait并添加命令debugger

In the e2e test I add async and await and add the command 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时,它仍然可以成功运行:

When I execute ng e2e it still runs with succes:

我在终端会话中运行调试器:

I run the debugger in a teminal session:

node --inspect-brk ./node_modules/protractor/bin/protractor ./e2e/protractor.conf.js

我在浏览器中打开Chrome检查器chrome://inspect/#devices,找到当前正在运行的目标,然后单击inspect.然后,单击按钮resume script execution(或F8),然后测试应在第一行使用debugger关键字暂停.

I open chrome inspector chrome://inspect/#devices in browser, find the current running target and click on inspect. Then I click on the button resume script execution (or F8), and the test should pause at the first line with the debugger keyword.

但不是,Chrome会自动打开一个错误为ERR_CONNECTION_REFUSED的新窗口. Chrome DevTools的控制台为空.终端会话给出:

But it doesn't and Chrome automatically opens a new window with an error ERR_CONNECTION_REFUSED. The console of Chrome DevTools is empty. The terminal session gives:

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中.然后我得到错误:

So I read the suggestions and add getPageTimeout: 60000 to protractor.conf.js to . Then I get error:

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

似乎是相同的错误,因此我将protractor.conf.jsallScriptsTimeout: 11000更改为60000.然后我得到错误:

Seems like the same error so I change protractor.conf.js line allScriptsTimeout: 11000 into 60000. Then I get error:

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.同样的错误.

Again, so I change protractor.conf.js line defaultTimeoutInterval: 30000 as a part of jasmineNodeOpts into 60000. Same error.

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

I also tried a higher value, 200000, but in result the wait is longer but error is the same.

谁知道该问题的解决方案?

Who knows a solution for this problem?

推荐答案

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

Running Protractor directly won't automatically start an application to run tests against, this is part of the work ng e2e command does.

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

To fix the issue you can either start application in the separate terminal window using ng serve or probably you can run debugger against ng e2e command (which will start an application under the hood):

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

这篇关于错误调试带有节点8异步/等待和角度6的量角器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆