TestProject Forum
Powered by leading experts in the test automation community

Test fails because page randomizes every time a new test runs

So on my web test for Survey (web form)

Survey loads Pages for example 1,2,3,4,5, each page has checkboxes, radio buttons and textbox etc
I have the full test using CSS selector/Xpath (going to switch them all to CSS) but the problem is

Next time I run the test, Survey Loads Pages as 1,2,4,5,3 then next time 1,2,5,4,3 etc every time it is Random this is causing the elements to not be found because it expects pages as 1,2,3,4,5 and failing. So I can get maybe one out of 5 test GREEN. Not sure how to get it to find an element no matter what order the pages load in?

I hope I explained this okay. I am kind of lost on how to solve this right now.

Hey Marcel,
One way that you could get around this is to use the action that allows you to click on an element that contains certain text so instead of the step looking or an xpath that is changing, it will just search for an element that contains certain text.
You can also run the element action of getting the CSS value. Which you can then create a new parameter in that step so it saves that value it outputs. Then in your next step, use that saved parameter as the element to click on. This way it can save the randomized value for each test.

Sorry if that is confusing, I dont have time to add screenshots but let me know if you get stuck.

Thank you Erick,

I got it sorted out. Ran the test several times and looks consistent GREEN. Very happy. Thank you for your response.