There are two main reasons for flaky automated tests.
1) Poor Locator Strategy. Find a methodology that is testable before you have to depend upon it in your automated testing. I just posted a video on this topic a week ago, which shares why our team exclusively utilizes xPath for some of the most reliable locators you can build. Realize xPath has got a bad rap and is often demonstrated online in some awful ways. This video will show you the beginning of how to build reliable locators. https://realworldtestautomation.com/basic-xpath-example/
2) Poor Synchronization Strategy. You should never need any type of sleep or wait in your test automation. These are almost always present in flaky automation, and it's no wonder why. Wait() is as good as Hope() when determining how long is long enough to pause for something to happen. Instead, build your automation with a more intelligent synchronization strategy based on these four fundamental methods. Exist, Not Exist, Wait to Exist, Wait to Not Exist. So the foundation to using these four synchronizations is to determine the state of a locator. You should be able to ask any locator does it Exist or Not Exist at any moment? You should also be able to ask your automation to check for a locator to exist for a determined period of time (Wait to Exist). Likewise, you should be able to ask your automation to check if a locator no longer exists for a determined period of time (Wait to Not Exist).
If you adopt these two fundamentals to your automation strategy, the majority of your flaky test will go away without any additional actions necessary.
There are two main reasons for flaky automated tests.
ReplyDelete1) Poor Locator Strategy. Find a methodology that is testable before you have to depend upon it in your automated testing. I just posted a video on this topic a week ago, which shares why our team exclusively utilizes xPath for some of the most reliable locators you can build. Realize xPath has got a bad rap and is often demonstrated online in some awful ways. This video will show you the beginning of how to build reliable locators. https://realworldtestautomation.com/basic-xpath-example/
2) Poor Synchronization Strategy. You should never need any type of sleep or wait in your test automation. These are almost always present in flaky automation, and it's no wonder why. Wait() is as good as Hope() when determining how long is long enough to pause for something to happen. Instead, build your automation with a more intelligent synchronization strategy based on these four fundamental methods. Exist, Not Exist, Wait to Exist, Wait to Not Exist. So the foundation to using these four synchronizations is to determine the state of a locator. You should be able to ask any locator does it Exist or Not Exist at any moment? You should also be able to ask your automation to check for a locator to exist for a determined period of time (Wait to Exist). Likewise, you should be able to ask your automation to check if a locator no longer exists for a determined period of time (Wait to Not Exist).
If you adopt these two fundamentals to your automation strategy, the majority of your flaky test will go away without any additional actions necessary.
Pursue the Craft of Testing in excellence.
Thank you, Greg for the advice! I have just one question: how about wait for element to be clickable?
DeleteExcellent guide!
ReplyDeleteMost of the flakiness I have come across come from the the tests themselves.
Totally agree with the Remedies recommended there.