使用量角器检测iframe是否成角度 [英] Detecting Whether An Iframe Is Angular Or Not With Protractor

查看:73
本文介绍了使用量角器检测iframe是否成角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下不寻常的用例.我在下面详细介绍

I have the following unusual use case. I detail it below

1)我在有角度的页面上&我在页面上执行了一些操作[它加载了非角度的iFrame]

1) I'm on an angular page & I do some actions on the page [It loads a non-angular iFrame]

2)我切换到非角度iframe&与某些屏幕互动.

2) I switch to the non-angular iframe & interact with some screens.

3)最终,这将导致重定向发回到有角度的页面.

3) Eventually this causes redirection to happen back to an angular page.

当我在第2步中使用量角器时,必须将其与标志browser.ignoreSynchronization设置为false一起使用,因为它是非角度的.我需要一种方法来检查与之交互的 form 是否成角度,以帮助从步骤2)顺利过渡到3).

When I use protractor for step 2 I have to use it with flag browser.ignoreSynchronization set to false as it is non-angular. I need a way to check whether the form I'm interacting with is angular or not to help with a smooth transition from steps 2) to 3).

我知道您可以使用

browser.executeAsyncScript或browser.executeScript以及

browser.executeAsyncScript or browser.executeScript along with

!! window.angular(angular v1)

!!window.angular (angular v1)

!! window.getAllAngularTestabilities(角度v2)

!!window.getAllAngularTestabilities (angular v2)

,但这在此用例中不起作用,因为无论您是否与非角度iframe进行交互,所有这些都将返回true.有人会对这样的用例起作用吗?预先非常感谢.

but this doesn't work in this use case as all of these will return true regardless of whether you are interacting with the non angular iframe or not. Would anyone have any other suggestion that may work for a use case like this? Many thanks in advance.

推荐答案

以下是我需要自动执行iframe时通常要做的事情

What I normally do when I need to automate an iframe is the following

// 1) When you know the iframe is there
browser.switchTo().frame(0);

// 2 a) You don't need to disable the wait for anguler, just use vanila webdriver, it will work on both
browser.driver.findElement(by.css('.your-css-selector'));
// Do some more interaction
browser.driver.findElement(by.css('.input-css-selector')).sendKeys('type something');
browser.driver.findElement(by.css('.button-css-selector')).click());

// 2b) Or now just use the Protractor syntax, 
//     because you switched you should be able to use it now.

// 3) Switch back
browser.switchTo().defaultContent();

// 4) Check for example with Protractor expectedConditions if the iframe is gone
var EC = protractor.ExpectedConditions;
// Waits for the ifram to be no longer present on the dom.
browser.wait(EC.stalenessOf($('iframe')), 5000);

如您所见,无需执行browser.ignoreSynchronization = true;

我希望这对您有帮助

这篇关于使用量角器检测iframe是否成角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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