Our company is developing a framework with Selenium, POM, Maven and Java for a Web application and we have around 35 test cases. When we run testng.xml there are at least 4 to 5 test cases that fail randomly because of stale element exception or element not clickable at that point, etc.
Is it common for some test cases to fail when we run testng.xml? How many test cases are ran in your organization and what is the estimate on how many that fail?
You just need to add some wait before your driver.findElement(). Selenium works very fast and that's why you are getting this Stale element or element not visible exceptions. Adding wait should solve the problem.
Test Automation is related to the repeatability of the tests and the speed at which the tests can be executed. There are a number of commercial and open source tools available for assisting with the development of Test Automation and Selenium is possibly the most widely-used open source solution among them.
This matrix may vary from organization to organization or as per specific Client Requirements. However Exit Criteria must hold the key for this limit. Having said that, as Test Automation through Selenium automates the Regression Tests so ideally there should be Zero failures. I have known some organization adhering to Zero Defect policy.
So the errors which you mentioned are not errors as such but may arise while Test Execution due to the following reasons:
These error can be addressed easily following the best practices mentioned above.
Failures due to stale elements, element not clickable at a point, timing issues, etc. must be handled and dealt with in your automation framework - the methods you're creating and using to construct the cases.
They should not propagate and lead to case failures - they are tech issues, not a product problem, or test case one. As such they must be accounted for (try/catch blocks for example) and dealt with (retry mechanisms, or re-getting a web element) promptly.
In the same time - and speaking simply out of my experience - cases dealing with live/dynamic data may sometimes randomly fail.
For instance, a SUT I'm working on displays some metrics and aggregations based on data and actions outside of my control (life traffic from upstream systems). There are cases checking a particular generated artifact behaves according to the set expecations (imagine a monthy graph for instance, which simply doesn't have a number of data points - there just was no activity on those days) - cases for it will fail, not because they were constructed incorrectly, and certainly not because there is a product bug - but because of the combination of the time of execution and the dataset.
Over time I've come to the conclusion having those failures is OK, getting them "fixed"- reselecting data sets, working around such outside fluctuations, etc. is an activity with diminishing value, and questionable ROI. Out of the current ~10,000 cases for this system, around 1.5% are failing because of this (disclaimer: the SUT is working exclusively with live/production data).
This is hardly a rule of thumb - it's just a number I've settled on as acceptable given the context.
And important note - if I had full control of this very data, I would have gotten rid of those "random" failures also. I've chosen to use the real data deliberately - thus my cases also verifying its integrity; with this negative side effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With