简体   繁体   English

等待量角器与页面同步时出错:在运行量角器测试用例时“在窗口中找不到角度”

[英]Error while waiting for Protractor to sync with the page: “angular could not be found on the window” on running protractor test case

I am testing the angular website. 我正在测试有角度的网站。 Our application starts with Login page and then vertical application selection frame (On the left corner of the page) which are Non-Angular web-pages and then after selecting the application in the left frame, it opens angular site inside the another frame (Right to the application selection frame) . 我们的应用程序从“登录”页面开始,然后是垂直应用程序选择框架(在页面的左角),它们是“非角度”网页,然后在左侧框架中选择应用程序后, 它将在另一个框架内打开角度站点(右侧到应用程序选择框架)

I have the following code to automate the scenario using Cucumber and Protractor. 我有以下代码来使用Cucumber和Protractor自动化方案。 After Logging in and launching the application from the left frame, I get the error message as: 登录并从左框架启动应用程序后,我收到以下错误消息:

Uncaught exception: Error while waiting for Protractor to sync with the page: "angular could not be found on the window". 未捕获的异常:等待量角器与页面同步时出错:“在窗口中找不到角度”。

[launcher] Process exited with error code 1 [启动器]进程退出,错误代码为1

Process finished with exit code 1 流程以退出代码1完成

Please find the code snippet below: 请在下面找到代码片段:

 var chai = require('chai'); var chaiAsPromised = require('chai-as-promised'); chai.use(chaiAsPromised); var expect = chai.expect; var assert = chai.assert; var myStepDefinitionsWrapper = function () { this.Given(/^I login to the application with valid (.*) and (.*)$/, function (username, password) { browser.driver.get(browser.baseUrl); browser.driver.wait(function () { return browser.driver.isElementPresent(by.id("ContentPlaceHolder1_UsernameTextBox")); }, 10000); browser.driver.findElement(by.id("ContentPlaceHolder1_UsernameTextBox")).then(function (usernameField) { usernameField.sendKeys(username); }); browser.driver.findElement(by.id("ContentPlaceHolder1_PasswordTextBox")).then(function (passwordField) { passwordField.sendKeys(password); }); return browser.driver.findElement(by.id("ContentPlaceHolder1_SubmitButton")).click(); }); this.Given(/^I launch the application from application selection page$/, function () { browser.driver.wait(function () { return browser.driver.isElementPresent(by.xpath("//a[starts-with(@class,'cp-icon') and contains(@style,'applaunch_default_26x26')]")); }, 10000); browser.driver.findElement(by.xpath("//a[starts-with(@class,'cp-icon') and contains(@style,'applaunch_default_26x26')]")).click(); browser.driver.wait(function () { return browser.driver.isElementPresent(by.xpath("//span[contains(@title,'AppName')]")); }, 10000); return browser.driver.findElement(by.xpath("//span[contains(@title,'AppName')]")).click(); }); this.When(/^I open the task for the (.*)$/, function (PersonName) { //Anugular Website starts from here browser.waitForAngular(); return element(by.xpath("//td[contains(text(),'" + personName + "')]/following::td[2]/button[text()='Perform']")).click(); }); 

I've had this issue a few times before, specifically with a login page(with angular) that takes me to a 'success' page(without angular), then redirects me to a landing page(with angular). 我之前有过几次这个问题,特别是登录页面(带角度)将我带到“成功”页面(无角度),然后将我重定向到登录页面(带角度)。

This usually works quite nicely: 这通常效果很好:

loginBtn.click();
browser.wait(function () {
    return browser.executeScript('return !!window.angular');
}, 10000, 'Timed out waiting for angular after login page);

See if you can get that to work for you as well! 看看是否也可以为您工作!

Edit after your edit: Sweet, this one looks tricky! 编辑后进行编辑:很好,这个看起来很棘手! Let's see what we can find out. 让我们看看我们能找到什么。

Can you switch to the frame? 可以切换到相框吗? Check this out: 看一下这个:

https://angular.github.io/protractor/#/api?view=webdriver.WebDriver.TargetLocator.prototype.frame https://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.switchTo https://angular.github.io/protractor/#/api?view=webdriver.WebDriver.TargetLocator.prototype.frame https://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype 。切换到

Since it is non-angular at the start, you may need: 由于开始时它是非角度的,因此您可能需要:

browser.driver.switchTo().frame(element(by.id('frameWithAngular')));

I don't think you will need a browser.wait until you can switch to the frame, but I'm not sure the behavior when you are in a non-angular area at the start. 我认为您不需要浏览器。请耐心等待,直到可以切换到框架为止,但是我不确定在开始时处于非角度区域时的行为。

Another thing to try is pointing your config to the area where angular will be with rootElement(Line 173): https://github.com/angular/protractor/blob/master/docs/referenceConf.js 尝试尝试的另一件事是使用rootElement(第173行)将您的配置指向要成角度的区域: https : //github.com/angular/protractor/blob/master/docs/referenceConf.js

This could disrupt the rest of your flow, though, depending on the site layout. 但是,这可能会干扰您的其余流程,具体取决于网站布局。 A bit more reading about iframes, though all in angular it talks about waiting for the frames properly: Protractor: Testing Angular App in an Iframe 关于iframe的更多信息,尽管涉及角度都涉及正确等待帧: 量角器:在iframe中测试Angular App

Let me know if you can get any closer with this! 让我知道您是否可以更进一步!

used iframe name to switch to iframe containing angular site. 使用iframe名称切换到包含角网站的iframe。

 browser.driver.switchTo().frame('<Frame Name>'); 

Also, it doesn't work with protractor 2.0 and 2.1. 而且,它不适用于量角器2.0和2.1。 So I had to downgrade the protractor to 1.8.0 所以我不得不将量角器降级到1.8.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 失败:等待量角器与页面同步时出错:“在窗口中找不到角度” - Failed: Error while waiting for Protractor to sync with the page: “angular could not be found on the window” 量角器“等待量角器与页面同步时出错”浏览Angular站点 - Protractor “Error while waiting for Protractor to sync with the page” browsing Angular site 带有 protractorjs 的 Angular 2 失败:等待 Protractor 与页面同步时出错:“window.getAllAngularTestabilities 不是函数” - Angular 2 with protractorjs Failed: Error while waiting for Protractor to sync with the page: "window.getAllAngularTestabilities is not a function" 在等待量角器与页面同步时刷新时发生错误,在捕获警报时 - Error while waiting for protractor to sync with the page on catching alert during refresh 执行量角器测试时出现“失败:等待量角器与页面同步时出错” - "Failed: Error while waiting for Protractor to sync with the page" while executing Protractor tests 在safari上运行量角器测试,说“在页面https://angularjs.org/上找不到Angular” - Running protractor test on safari, say “Angular could not be found on the page https://angularjs.org/” 在量角器中捕获“在窗口中找不到角” - Catching “angular could not be found on the window” in protractor 运行量角器时找不到规格 - No specs found while running protractor 使用量角器时,单击导致发出http请求的按钮时,我收到此消息:等待量角器同步时出错 - While using Protractor, when clicking a button which causes an http request to be made, I receive this: error while waiting for protractor to sync 量角器不等待页面加载 - Protractor not waiting for page load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM