1

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:

  1. Is there a way that I can wait for angular load completely before I can switch to the iFrame and manipulate the controls purely in selenium?
  2. If not, is there a way or any one has any work around where only for angular app part we can use the Protractor scripts? (Basically I am asking if protractor and selenium suites can go hand in hand?)

Any help greatly appreciated.

Rajive Pai
  • 312
  • 1
  • 13
  • Have a look at -- http://stackoverflow.com/questions/25062969/testing-angularjs-with-selenium http://stackoverflow.com/questions/38621451/selenium-and-angularjs-wait-until-to-do-some-actions – Grasshopper Jan 19 '17 at 06:53

1 Answers1

1

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; 
   }   
  }
}
Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23
  • Thank you for posting an answer. However, one question - What is your take on using selenium for automating angular apps? – Rajive Pai Jan 19 '17 at 11:18
  • I would not recommend doing that.If it is angularJS then you should go for protractor only. In our case , there were some business reasons for choosing that. – Vishal Aggarwal Jan 19 '17 at 13:53
  • However I don't understand why we have to use javascript as a language in protractor. I wish there would be a porting of Protractor in ruby or python. – Vishal Aggarwal Jan 20 '17 at 16:04