将量角器与ng-upgrade一起使用 [英] Using protractor with ng-upgrade

查看:115
本文介绍了将量角器与ng-upgrade一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将AngularJS(1.6)应用程序迁移到Angular(4),现在有一个混合应用程序,由NgUpgrade引导.

I am working on migrating my AngularJS (1.6) app to Angular (4) and now have a hybrid application, bootstrapped with NgUpgrade.

但是,这似乎完全破坏了我的量角器测试.

However, this seems to have completely broken my Protractor tests.

失败:11秒后等待异步Angular任务完成而超时.这可能是因为当前页面不是Angular应用程序.请参阅常见问题以获取更多详细信息: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular

在等待带有定位符的元素时-定位符:By(css选择器,.toggle-summary-button)

While waiting for element with locator - Locator: By(css selector, .toggle-summary-button)

混合应用更改

应用程序似乎运行良好,并且AngularJS和Angular组件均按预期运行.我在引导过程中所做的更改是:

The application seems to run fine, and both AngularJS and Angular components are working as expected. The changes I made in the bootstrapping process are:

1从html标签中删除了ng-app:

1 Removed ng-app from html tag:

<html lang="en" *ng-app="myapp">

2添加了一个AppModules(@NgModule)等.

2 Added an AppModules (@NgModule) etc.

3使用NgUpgrade引导应用程序:

3 Used NgUpgrade to bootstrap the app:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { UpgradeModule } from '@angular/upgrade/static';
import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
  const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
  upgrade.bootstrap(document.body, ['myapp'], {strictDi: true});
});

量角器测试

基于上面的错误,问题似乎与量角器在等待Angular时所做的事情有关.我有一个beforeEach块,该块可加载登录页面,填写详细信息并登录.奇怪的是,它仍在打开该页面并在用户名字段中输入文本,但是随后无法继续.

Based on the error above, the problem seems to be related to whatever Protractor does when it is waiting for Angular. I have a beforeEach block which loads the login page, fills in the details and logs in. Weirdly it is still opening the page and entering text into the username field, but then it fails to go any further.

我不明白为什么这会有所不同,并且似乎没有任何改变的迹象会有所帮助,因此任何指导都将受到欢迎!

I can't understand why this is any different and no amount of changing things around seems to help, so any guidance would be most welcome!

我尝试过,但没有成功:

I have tried, with no success:

  • 添加"rootElement:'body'"到我的量角器配置文件
  • 添加"ng12Hybrid:true";到我的量角器配置文件-我收到一条消息,说它在自动检测到时不再需要它.
  • allScriptsTimeout设置从11000增加到60000,但仍然超时.
  • 关闭waitForAngularEnabled设置.这样就解决了登录字段的问题,但是随后我的http模拟都无法正常工作,并且测试失败.
  • adding "rootElement: 'body'" to my protractor config file
  • adding "ng12Hybrid: true" to my protractor config file - I get a message saying that it should no longer be needed as it auto detects.
  • increasing the allScriptsTimeout setting from 11000 to 60000 and it still times out.
  • turning off the waitForAngularEnabled setting. This solves the problem with the login fields, but then none of my http mocks work and the tests fail.

推荐答案

有趣的是,我在15个月前问了关于角度1到角度2的完全相同的问题(+ github):

What is funny is I asked the exact same question (+github) 15 months ago about angular 1 to angular 2:

量角器+混合角度1 + 2应用=失败

在没有任何解决方案的情况下,我回滚到了角度1.今天,我们决定再次尝试像您一样从角度1上升到角度4,并着眼于您的问题,因为我们仍然有完全相同的问题...

Without any solution I rolled back to angular 1. Today we decided to try again to move up from angular 1 to 4 like you, and landed on your question because we still have the exact same problem...

嗯,实际上并没有那么有趣……我不明白为什么如此重要的功能会被这样分开.由于对Angular 2+的重大更改,应该积极维护AngularJs!有点令人失望(对那些希望得到真正答案的人感到抱歉,如果有更新,我会发布)...

Well, not so funny actually... I can't understand why a so important feature is put apart like that. AngularJs was supposed to be actively maintained because of the breaking change to Angular 2+! It's a little disappointing (sorry for those expecting an real answer, I will post if updates)...

我去了React

这篇关于将量角器与ng-upgrade一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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