I've been making a functional tests using selenium-webdriver using yadda library. The problem it's that in my different environments the same test suite working different. Example:
On tests, the result it's different based on the environment that I entry.
Local localhost:5000
Open my search site
․ when i go to my site: 2169ms
․ when i write a text on the search input: 21ms
․ when i click the search button: 130ms
․ then i get the results page.": 46ms
Staging mystaging.domain.com
Open my search site:
StaleElementReferenceError: {"errorMessage":"Element is no longer attached to the DOM","request":{"headers":{"Accept":"application/json; charset=utf-8","Connection":"close","Content-Length":"2"
Production www.domain.com
Open my search site
․ when i go to my site: 2169ms
․ when i write a text on the search input: 21ms
․ when i click the search button: 130ms
․ then i get the results page.": 46ms
At this time, only the staging tests are failing, but in other situations when the internet connection it's slow, the tests fails in production but pass in staging. The main problem it's that the browser doesn't have the DOM ready for the test and they doesn't find the element required for the test.
My approach for trying to solve this, it's wait that appear the root element of my page like this:
return driver.wait(() => driver.isElementPresent(By.css(".my__homepage")), 50000);
But this isn't enough for me, because the test suites are still failing randomly.So, my question it's:
Which could be a best approach for run in different environments the tests suite dealing with the elements that isn't ready on the browser ?