0

我正在为我的 angular7 应用程序(Windows 10、chrome)创建 e2e 测试。在我的应用程序中首先出现一个非角度页面,当我输入用户名和密码时,出现角度页面。在导航到有角页面之前,我尝试过使用browser.ignoresynchronization = true非角页面。browser.ignoresynchronization = false尽管如此,量角器一到达角度页面就会抛出。

我已经browser.ignoresynchronization = true在我的 protractor.conf 文件中尝试过onPrepare(),然后在登录后和出现角度页面之前再次将此标志设置为 false。我仍然收到量角器同步错误。

我也尝试使用browser.waitForAngularEnabled(false)而不是ignoresynchronization但仍然没有成功。

4

1 回答 1

0

Welcome to SO!

Before getting to specifics:

Protractor supports both angular and non-angular pages. As you have done already, specify when you want protractor to wait for angular to load and when it shouldn't.

We also have an application that has both angular and non-angular pages. Been using protractor for E2E testing for quite sometime now. In our case, the intention is to migrate to Angular eventually across the app.

That said, we used browser.ignoreSynchronization (deprecated now) and browser.waitForAngularEnabled() to handle angular pages iow. the configuration was by default for non-angular. However, things became difficult as soon as the pages are getting migrated to angular. We had to do something.

Solution that worked for us:

  • Do nothing and let protractor believe its an angular application in general. This made sense as most of the pages are either completely angular or sections of the pages were using angular. IN your case, find the amount of angular vs non-angular pages. Set protractor config parameter accordingly so that majority works out of the box.
  • For non-angular pages, we moved that setting to PageObjects as, logically, thats the right place to hold that information i.e. whether it is angular or non-angular.
  • Specs started to work hand-in-hand with the page objects except places where clicking a link open a new tab/window/popup. Those places, we let Specs decide to disable and then enable back angular loading flag. So far, this is working very nicely

In specific:

From our experience, use the flag judiciously and at the start and end of an it block. That is: call browser.waitForAngularEnabled(true/false) at the very beginning of the it block and then restore it back at the end of same it block. Feel free to make your it block as small as possible to handle this. All in all make sure the it block is similar to

it('should do', function(){
  browser.waitForAngularEnabled(false/true)
  step1 here
  step2 here
  browser.waitForAngularEnabled(true/false)
})

The question did not include the error details, but this approach should work as protractor (to be precise, JavaScript engine) will run it block as a whole.

It is also not clear if you are using protractor promise manager or not. Do update if the above approach doesn't solve the issue.

All the best...

于 2019-08-17T09:40:14.443 回答