Expanding the click method wrapper
Let’s extend the clickAdv()
method to make it more robust and less likely to fail. First, we will add a pageSync()
function to the helper class. This function is an alternative way to determine when the page build has settled. After each click, we will perform the following actions:
- Count the number of visible
/span
elements on the page. - Wait 1/4 of a second.
- Repeat until either of the following occur:
- The count of /span elements is stable 3 times
- The timeout is reached
- Report service-level-agreement metrics on how long it took to complete.
- Add the option to customize the length of the wait time.
The page sync method will dynamically wait for the page to build. It is optimized to spend a minimum of 0.75 seconds detecting when the page is completed. This reduces the chance of throwing an error if our element does not exist as the page is building. But it also gives us the flexibility to wait longer, up to 30 seconds...