Wednesday 30 July 2014

Selenium: How to handle Stale Element Exception error

Common Causes
A stale element reference exception is thrown in one of two cases:
  1. The element has been deleted entirely or element/page  has been refreshed
  2. The element is no longer attached to the DOM.


Solution
  1. The most simple solution is to use the Java PageFactory, this will create a proxy WebElement that will find the element every time you use it (There is a slim change that the element will be released in the couple of milliseconds between it being found and you performing an action on it, in this case it is suggested to use an explicit wait to wait for the element to become stale before finding it again).
  2. Use try catch to handle this exception and reload the element in catch block.
  3. Add a short sleep between FindElement & action method..


Thursday 10 July 2014

Cucumber vs TestNG : Which is better?

I have been a long time user of TestNG.  Few months back, I started exploring about Cucumber. It was a wish from my client to create automation framework using Cucumber. I searched on web & found many blogs on Cucumber & its implementation. I started with assumption that Cucumber will replace TestNG. After working for few months, I came to following conclusion they are as follows -

                    Cucumber
                        TestNG
  • Cucumber is a collaboration tool, which lets non-technical people write executable specifications. Those executable specifications test your app from the outside - like a black box.
  • Cucumber is not meant to be used as a unit testing tool.
  •  It allows to write automated acceptance tests, functional requirements and software documentation into one format that would be understandable by non-technical people as well as testing tools
  • You can implement your tests using the same language you use to discuss them with the business. 
  • Cucumber adds the overhead of plain English (or other native language) to executable code conversion
  • Good for acceptance testing

  • TestNG are unit testing tools. They are great for testing individual classes, but not great for executable specifications that are readable (and writeable) by non-technical people.
  • It facilitates to test individual classes.
  •  You can group tests using tags.
  •  TestNG supports a lot of complicated practices like priorities, grouping, listener etc. 
  •  Useful when you have to automate large number of test case