asp.net - Do I always have to "wait" for page loads when using selenium on non-ajax pages? -
i'm writing bdd tests using cucumber, selenium , xunit legacy asp.net application. way pages designed, every "click" leads new page being fetched server. if have automate tests particular page, should have line similar following after every "click"?
webdriverwait wait = new webdriverwait(driver, timespan.fromseconds(timeout)); wait.until(...); //wait until page true
i'm not sure if selenium wait implicitly page loads without explicitly having state time. recommended pattern handle scenario?
it's cumbersome have idea of "some element" can put in until
method , leads brittle tests. asp.net pages littered lots of dynamic controls , whole slew of page refreshes makes test code quite unreadable.
my proposed solution: write extension method waiting implicitly , takes parameter of element-id wait on. i'm refactoring above problem more manageable place. still have wait explicitly performed. there no way eliminate it? selenium have obvious default handle case without need such extension method or natural way of doing it?
if want tests reliable , wait needed time interval - yes, explicit waits webdriverwait
perfect solution. and, it's "natural" solution - think how you, user, define page loaded - it's when see desired content, correct? when @ loading page, reevaluating state of page, checking whether desired content appeared or not. explicit waits follow same logic - default, every 500 ms checks if expected condition true or not, no more x seconds you've configured when instantiating webdriverwait
.
if need use wait.until()
calls , want follow dry principle, think applying "extracting method" or other refactoring methods.
you can set implicit wait applied on every element search, or introduce hardcoded "artificial" delays, that's not going reliable , time-wasteful - you'll end waiting more needed , having occasional test failures.
Comments
Post a Comment