量角器重定向到Auth0非角度页面后同步到角度页面 [英] Protractor syncing to an Angular page after redirection to Auth0 non-Angular page

查看:56
本文介绍了量角器重定向到Auth0非角度页面后同步到角度页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Protractor进行e2e测试的Angular Web应用程序.我最近添加了OAuth0身份验证.在使用await browser.waitForAngularEnabled(false)重定向到非Angular OAuth0页面之前,我禁用了Angular同步,并且工作正常.但是,对于该规范文件测试套件的其余部分,我无法再次使用await browser.waitForAngularEnabled(true)重新启用Angular同步,否则会收到臭名昭著的量角器超时错误.我想重新启用Angular同步,否则我必须使用预期的条件,等待和睡眠以确保加载后续页面,并且可能导致间歇性错误.

I have an Angular web app that uses Protractor for e2e tests. I recently added OAuth0 authentication. I disable Angular synchronisation before redirection to the non-Angular OAuth0 page using await browser.waitForAngularEnabled(false) and that works fine. However I cannot reenable Angular synchronisation using await browser.waitForAngularEnabled(true) again for the rest of that spec file test suite or I get the infamous protractor timeout errors. I'd like to re-enable Angular synchronisation as otherwise I have to use expected conditions, waits and sleeps to ensure follow-on pages are loaded and that can result in intermittent errors.

我已经阅读了所有问题和答案,并尝试了所有显而易见的方法-重新加载页面,获取新页面,等待,长时间睡眠等.

I have read all the questions and answers and have tried all the obvious - reloading the page, getting a new page, waits, long sleeps, etc, etc.

所以我的问题是非常具体的,而不是寻找建议-有谁了解Protractor与Angular页面进行同步的机制,并且您知道在重定向到和从Angular重新同步之后,Angular是否可以重新同步.非Angular页面,即我是在浪费时间寻找修复程序.我阅读了一些有关该机制的内容-它加载了要在页面上运行的脚本,但是我不确定为什么从auth0重定向返回后,当我执行browser.get {'/')时不能再次加载该脚本

So my question is quite specific rather than looking for suggestions - does anyone understand the mechanism Protractor uses to sync with Angular pages and do you know whether it possible or not for Angular to resync after a redirection out to, and back from, a non Angular page, i.e. am I wasting my time looking for a fix. I read up a little on the mechanism - it loads a script to be run on the page but I'm unsure why that can't be loaded again when I do a browser.get{'/') after returning from the auth0 redirection.

请注意,我可以使Angular同步保持禁用状态,并且可以使事情正常进行,因此我不寻求有关如何使事情正常工作的建议.如果您遇到了特定的问题并提出解决方案,我很乐意听到.

Note that I can leave Angular synchronisation disabled and can get things to work so I am not asking for advice on just how to get things working. If you have faced the specific problem and come up with a fix I'd love to hear it.

任何帮助表示赞赏.

推荐答案

答案-是的,您可以在量角器中重新启用角度.但是,量角器并非总是与角度应用程序一起使用.因此,只需确保量角器与您的应用程序保持同步,并且页面已准备就绪.

Answer - yes you can reenable angular in protractor. However, protractor doesn't always work with angular apps. So just make sure protractors synchronization will be working as it should with your app AND the page is ready for this.

首先,手动打开应用程序并获得授权.然后在控制台中运行 getAllAngularTestabilities().如果此命令不可用,则量角器不能与角钢一起使用.如果命令成功执行,请查看返回的对象,特别是 obj [0] ._ ngZone hasPendingMacrotasks hasPendingMicrotasks 属性.如果其中任何一个为 true ,则量角器无法与此页面一起使用.如果两个都是 false ,则可以继续进行下一步

First, manually open the app, and get authorized. Then in console run getAllAngularTestabilities(). If this command in not available, protractor can't work with angular. If the command is successful, take a look at returned object, specifically at hasPendingMacrotasks and hasPendingMicrotasks properties of obj[0]._ngZone. If any of them is true, protractor can't work with this page. If both of them are false then you can proceed to the next step

现在,当您现在可以使用 browser.waitForAngularEnabled(true)与量角器对话时,您需要为测试实现以下方法

Now, when you now the page can talk to protractor with browser.waitForAngularEnabled(true) you need to implement the following method for your tests

let login = async function (username, password) {
  await browser.waitForAngularEnabled(false);
  await browser.get(url);
  await $usernameInput.sendKeys(username);
  await $passwordInput.sendKeys(password);
  await $loginButton.click();
  // MOST IMPORTANTLY, YOU HAVE TO WAIT UNTIL YOUR APP FULLY LOADED
  await browser.wait(
    // whatever you need to wait for,
    timeout,
    'failure message'
  );
  // AND FINALLY
  await browser.waitForAngularEnabled(true);
}

我的意思是您不必使用此方法,我只是向您显示了要实现结果必须执行的操作顺序.

I mean you don't have to have this method, I just showed you the order of actions you have to follow to achieve your results.

基本上,要点是,当您登录时,请确保非角度登录页面已消失,并且在重新启用等待角度之前,您的角度页面已完全加载.

Basically, the point is, when you login, make sure the non-angular login page is gone, and your angular page is fully loaded before reenabling waiting for angular.

您可以使用两种方法:

  • 等待所有关键要素出现
  • 或编写一个将返回 return!obj [0] ._ ngZone.hasPendingMacrotasks&&的函数!obj [0] ._ ngZone.hasPendingMicrotasks 并将其传递给 browser.wait
  • wait for all key elements to be present
  • or write a function which will be returning return !obj[0]._ngZone.hasPendingMacrotasks && !obj[0]._ngZone.hasPendingMicrotasks and pass it to the browser.wait

这篇关于量角器重定向到Auth0非角度页面后同步到角度页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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