2017-05-29 49 views
1

我有以下不尋常的用例。我詳細它下面檢測Iframe是否有角度或不使用量角器

1)我&的角頁上我做在頁面上的一些動作[它加載一個無角的iFrame]

2)I切換到無角的iframe &相互作用與一些屏幕。

3)最終這會導致重定向回到角度頁面。

當我使用量角器的第2步,我必須使用它與國旗browser.ignoreSynchronization設置爲false,因爲它是非角度的。我需要一種方法來檢查我與之交互的表格是否有助於從步驟2)到步驟3的平滑過渡。

我知道你可以使用

browser.executeAsyncScript或browser.executeScript頁面上

!! window.angular(角V1)

!!窗口沿自動檢查功能角.getAllAngularTestabilities(angular v2)

但是這在這個用例中不起作用,因爲無論您是否與非角度iframe交互,所有這些都將返回true。有沒有人有任何其他建議可以用於這樣的用例?提前謝謝了。

回答

0

,當我需要自動化的iframe我通常做的是以下

// 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;

我希望這有助於