There is an issue I have with automation.. Not that I do not agree that it is absolutely the best way to test an application, but in the sense that achieving stability is extremely hard to do. How do you guys make your tests stable? Of course I add explicit waits and the occasional thread.sleep()
, but they are never 100% stable.. The point of this thread is to post some tips and tricks that you guys have discovered that have made an impact on your automated tests

- 22,324
- 33
- 110
- 161

- 1,102
- 4
- 20
- 51
-
If 'wait' is your only concern then please visit http://stackoverflow.com/questions/12858972/how-can-i-ask-the-selenium-webdriver-to-wait-for-few-seconds-in-java – Amol Chavan Oct 26 '15 at 11:48
-
wait is not my only concern.. There are other ways to make tests more stable and that is what I am trying to find out – Tree55Topz Oct 26 '15 at 12:04
-
2What you mean by stable? What things are breaking your tests? – Ajinkya Oct 26 '15 at 12:25
-
Generally it is element not clickable which is an unknown error. I have tried the javascript executor and it works for some. Waits are really the only thing I use to help stabilize them. And by stable I mean for you to run your test with absolute certainty that the only thing that will cause your test to fail is a defect. Sometimes my tests run great, other times not so much – Tree55Topz Oct 26 '15 at 12:32
2 Answers
You should try to avoid using thread.sleep(), the reason why is when you get to the point having big test suite you will waste your time on waiting. Instead learn how to use Explicit and Implicit Waits.
Community experts recommend to use explicit waits more often, it would allow you to wait for specific action to happen, and once it happen WebDriver will continue to work without wasting any more time.
Even though there is some more advance tips and tricks written by Mark Collin in Mastering Selenium WebDriver book
Sometimes you can fail tests on purpose and catch exceptions then based on it make decision, learn how to use "try catch", I don't think it is a good practice, but I have seen test engineers(including myself) use it a lot.

- 444
- 3
- 9
-
1The above information is pretty correct. Use explicit waits often. Try/catch is extremely useful when utilized correctly, but most of your expect/actual result checking can and (in my opinion) should be done with if/else statements and creative use of the `fail()` method. – jagdpanzer Oct 26 '15 at 15:48
I would recommend looking at Selenide because if you don't want to go through the effort of figuring out how to make your own framework stable, you can just use the Selenide framework to get yourself going and then you wont need to worry about waits any more.
Of course, there is some value in creating your own framework, expecially if your doing test driven development and want to unit test your framework for Sonar code coverage. But, if your not at that level, using Selenide is what I would recommend for the biggest impact on your success.

- 28,471
- 61
- 196
- 289