Does WebDriver support testing of AngularJS application

398 views
Skip to first unread message

Vanshdeep Kewlani

unread,
Feb 10, 2016, 12:08:01 AM2/10/16
to Selenium Users
Hi,

I am working on Automation Testing of a AngularJS web application since 4-5 months using WebDriver with Java language. I had created my scripts for this website which was deployed on my local machine having static data and was able to execute it perfectly. 

Since, 1-2 months the website has been integrated with endpoints of server API and the data is coming dynamically for the application. In between I had switched to testing for another website in our project and was creating and executing scripts for it.

Now, when I am trying to execute my scripts I am facing a strange behavior - sometimes my scripts are running absolutely fine whereas other times I am getting StaleElementReferenceException. For example, my script will pass without any issues for 4-5 days and suddenly I will be facing this exception or it can happen that after 3-4 successful runs I will get this error again which seems to remain forever. There is no specific location in code where this exception will occur, it can point to any statement.

I have tried whatever ways I could think of for handling this be it but till now I am not sure if there is any feasible way of handling this:-
  • Different types of waits:-
    1. Implicit Wait
    2. PageLoadTimeout
    3. SetScriptTimeout
    4. Thread.sleep
    5. Conditional WebDriverWait
    6. FluentWait
  • Catching Exception and putting in Control flow with WebDriverWait/FluentWait
  • Catching Exception and putting in Control flow along with polling for certain interval of time and using either of (WebDriverWait or FluentWait)


Recently I read a document regarding causes of StaleElementReferenceException and it occurred to me that maybe the element is becoming Stale because in the background Angular is still doing some processing and some property of the element which was found earlier is getting changed in between.

I did further search in Google regarding testing of AngularJS website and got to know about Protractor tool that runs on top of Selenium WebDriver. What I have read till now regarding it I think this tool is designed for issue like this where the dynamic behavior of Angular can be handled and perhaps I will not face an exception like StaleElementReferenceException.

Since I don't have that much experience in Selenium and almost nil experience with Protractor, I cannot decide on this. So, I need advice from Selenium team whether is there any way I can handle this exception and keep working on my automation scripts using Java WebDriver or to switch to this new tool - Protractor.

Please advice soon as we are already getting delayed in our project.

The details for your reference are as follows:-
OS:- Windows 7 SP1
Selenium WebDriver:- 2.45.0
Chrome WebDriver - 2.16


StackTrace of Exception:-

org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document

  (Session info: chrome=47.0.2526.106)

  (Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Windows NT 6.1 SP1 x86) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 546 milliseconds

For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html

Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'

System info: host: 'GURUTC900086', ip: '172.19.56.202', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'

Driver info: org.openqa.selenium.chrome.ChromeDriver

Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\077965~1.AME\AppData\Local\Temp\scoped_dir11684_15075}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=47.0.2526.106, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]

Session ID: 62ea9a6ba535990ca839547151cddf79

*** Element info: {Using=xpath, value=preceding-sibling::div/strong}

                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

                at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)

                at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)

                at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)

                at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)

                at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:171)

                at org.openqa.selenium.remote.RemoteWebElement.findElementByXPath(RemoteWebElement.java:244)

                at org.openqa.selenium.By$ByXPath.findElement(By.java:357)

                at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:167)

                at pageRepository.batch1.PolicyCard.policyType(PolicyCard.java:320)

                at tests.batch1.TestPolicyCard.test(TestPolicyCard.java:116)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.lang.reflect.Method.invoke(Method.java:497)

                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

                at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

                at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

                at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

                at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

                at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 






Thank you & Regards,
Vanshdeep Kewlani

Serguei Kouzmine

unread,
Mar 14, 2016, 10:48:58 PM3/14/16
to Selenium Users
Hello Vanshdeep

Try the project 


it implements Protractor selectors and other stuff, in particular, all required Angular synchronization,  in Java / Selenium WebDriver, 



Please  feel free to ask  if you need further assistance, 

Note the article
http://www.codeproject.com/Articles/1066968/Developing-Protractor-tests-in-Csharp-or-Java

in this article, an Angular JS  Protractor C# and Java Client Library examples are explained.; Author: SERGUEIK; Updated: 3 Feb 201

Thanks 
Serguei Kouzmine 
Reply all
Reply to author
Forward
0 new messages