Reputation: 312
I have an application under test, that has an iFrame, where Angular app is injected. My test suite is in Java Selenium and I am finding it very difficult to manipulate the controls inside the angular app.
I have used protractor and selenium in isolation, but this scenario, I am finding it difficult to get a solution.
My question is:
Any help greatly appreciated.
Upvotes: 1
Views: 1025
Reputation: 4178
We are also automating Angularjs Application using Selenium & java. We have written our own sync and wait for load functions as below:
public void Sync()
{
//waitForLoading();
try
{
JavascriptExecutor js = (JavascriptExecutor)driver;
WebDriverWait wait = new WebDriverWait(webDriver, 300);//timeoutInSeconds
wait.Until(js.executeScript("return document.readyState").toString().equals("complete"));
Thread.sleep(4000);
}
catch
{
Thread.sleep(16000);
}
}
//Another version of the same function based on time based polling to make it more dynamic
public void checkPageIsReady() {
JavascriptExecutor js = (JavascriptExecutor)driver;
//Initially bellow given if condition will check ready state of page.
if (js.executeScript("return document.readyState").toString().equals("complete")){
System.out.println("Page Is loaded.");
return;
}
//This loop will rotate for 25 times to check If page Is ready after every 1 second.
//You can replace your value with 25 If you wants to Increase or decrease wait time.
for (int i=0; i<25; i++){
try {
Thread.sleep(1000);
}catch (InterruptedException e) {}
//To check page ready state.
if (js.executeScript("return document.readyState").toString().equals("complete")){
break;
}
}
}
Upvotes: 1