量角器无法在已部署的应用程序上检测到Angular 5

mc.*_*cki 8 cucumber protractor e2e-testing angular angular-e2e

我正在尝试使用Protractor和Cucumber为我的Web应用程序创建一个包含E2E测试的存储库.我从这个存储库开始:https://github.com/spektrakel-blog/angular-protractor-cucumber

当我强迫Protractor将应用程序视为常规网页时,测试运行正常.测试运行器正在与应用程序交互并期待一些结果.问题是,我想让Protractor检测Angular,以便在检查'Then'断言之前等待区域稳定.

这是我的protractor.conf.js:

exports.config = {
  allScriptsTimeout: 30000,
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--no-sandbox']
    }
  },
  directConnect: true,
  baseUrl: 'http://<ci-server-address>/',

  specs: [
    './e2e/features/*.feature'
  ],

  framework: 'custom',
  frameworkPath: require.resolve('protractor-cucumber-framework'),

  cucumberOpts: {
    require: ['./e2e/steps/**/*.ts'],
    strict: true,
    format: [
      'json:reports/summary.json'
    ],
    dryRun: false,
    compiler: []
  },

  onPrepare() {
    browser.ignoreSynchronization = true;
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  }
};
Run Code Online (Sandbox Code Playgroud)

简而言之 - 测试使用以下配置运行,但是当我删除时browser.ignoreSynchronization = true;,我收到以下错误:Timed out waiting for asynchronous Angular tasks to finish after 30 seconds. This may be because the current page is not an Angular application..

到目前为止我尝试过的事情(没有改进):

  • 添加ng-app<body>标签
  • 检查window.getAllAngularRootElements()- app-root正确返回
  • 检查window.getAllAngularTestabilities()- 返回一个Testability对象
  • 在Chrome上启动测试(有或没有沙箱)
  • 在Firefox上启动测试
  • 尝试部署我们的应用程序的CI服务器和本地环境 ng serve

我使用的是最新版本的Protractor,Cucumber,Chai和TypeScript.任何帮助将非常感激.非常感谢你提前!

Nar*_*arm 6

这听起来像是一个潜在的Zone问题.角度取决于ZoneJS(ngZone).这并不是说鲜见使用任何异步JavaScript功能,例如,当运行到这个错误setTimeout(),setInterval()等...

原因是ZoneJS猴子修补了这些功能,并且它是在Angular区域的上下文中完成的.当Protractor尝试连接到您的应用程序时,它不再在Angular Zone中运行,因此Protractor将挂起并最终因您收到的错误而超时.

如果我是你,我会看看你的应用程序是否有ZoneJS猴子补丁的任何异步功能.通常,在代码中查找在应用程序区域的上下文之外运行的任何内容.

这是一篇关于ZoneJS的好文章,它不仅可以帮助您理解ZoneJS,还列出了猴子修补的功能了解ZoneJS

  • 一旦忽略同步,就不会出现区域问题,因为浏览器不应该等待Angular稳定性.因此,如果删除`ignoreSynchronization`并且您使用的是Angular应用程序,则可能是区域问题.我喜欢这个答案,可能会对此下注. (3认同)
  • 这为我们解决了!我一直试图弄清楚我们的量角器自动化发生了什么,并且从未想过这一点.谢谢! (2认同)