In my project, the web application code is developed by a third party. The client does not know if ajax or other technologies are used which might load web elements at different times. We are automating the testing of the web application using Selenium Webdriver with Java, TestNg, POM. Will it be a bad practice to have explicit wait using ExpectedConditions for all the elements that we automate?
As of today (04September2022), we are running manual testing on the application to gauge which modules to automate first, and have noticed that the webpage elements (textboxes, links, buttons, dropdowns etc.) seemingly load at random times. Hence we are debating if we should use explicit wait for all the elements upfront, instead of a trial and error basis.
CodePudding user response:
Will it be a bad practice to have explicit wait using ExpectedConditions for all the elements that we automate?
In my opinion, largely not. I often identify elements by waiting for them to be clickable; from the way you've worded your question, it sounds like this could work and more importantly, be helpful in terms of avoiding any ElementNotFoundException
if you tell Selenium to simply grab that element without waiting.
Depending on your use case however, it may be that an element you're attempting to identify will never become clickable--or even visible or enabled, for that matter. In this case you could use the Expected Condition simply to wait for the element to be present.
An examination of the relevant Expected Conditions class (I'm not sure which language you're using, else I'd link it) will reveal to you exactly which explicit wait options you have at your disposal.
One more comment: are you testing a JavaScript-based frontend? If so I would recommend you consider Cypress, WebDriverIO, or Playwright, each of which waits much more intelligently for JS pages/elements to load properly.
CodePudding user response:
Wow I haven't heard anyone say Ajax in a very long time. You can use explicit wait, or you can just poll for it. there's not really much difference since Webdriver wait just polls for things as well. Whatever you find to be simpler in other words since Java is doesn't have events.