5
votes

I know that both of them can be used to validate if an element appears on the page but I was wondering about the performance impact and readability implications of each. So my question is, suppose you have 20 elements to check in the page,

  1. Is it better to use Wait Until Element Is Visible for all 20 elements?

OR

  1. Use Wait Until Element Is Visible for one element (for example, a header text) to let my automation script know that the page has loaded AND then use Element Should Be Visible for the rest (e.g. form fields)?
2
depend what kind of test you have to make, logically if you check if 1 element is loaded/visible doesn't mean that all the other have been loaded, so if you need use the element for do some other action use "wait until ..." otherwise depend if you need check the element or not, if it's just an element of the page that you don't need verify just ignore itCarlo 1585
If you're curious about the performance impact, why not just write a short test using each method and see which one performs better in your specific situation?Bryan Oakley

2 Answers

6
votes

Yes, factually both of them can be used to validate if an element appears on the page but ofcoarse you can design your tests for a much better performance.

Ideally, the Waits should be implemented strictly as per your Usecase and Test Steps.

  • Using Wait Until Element Is Visible: If your usecase involves visibility of all the 20 elements, albeit Wait Until Element Is Visible is the best fit.

  • Using Wait Until Element Is Visible for header text AND then use Element Should Be Visible: If your usecase involves visibility of any element, inducing Wait Until Element Is Visible for header text would be a complete overhead. As you have no validation with the header text, this step isn't necessary. Rather you should directly induce Wait for the visibility of the desired element(s).

-1
votes

In a strict performance comparison the execution speed of Wait Until Element Is Visible vs Element Should Be Visible, on element(s) that is already present in the DOM, is virtually the same.
They both do the same thing - find the element in the DOM, and call selenium's is_visible() method. The difference is the Wait Until loops and repeats if any of the two steps fail.

Thus for your (or similar) case, when the presence of one element (the header) should guarantee the other 19 are also already loaded, which one to use shouldn't matter.
If you use Wait Until ... on the header and Element Should Be Visible on the others, you'll be also testing that assumption in your case. Naturally, if all but the 19th elements are loaded together with the header, the case will fail.
If you use Wait Until ... on all elements the chance of passing will be higher - if any of the elements is added and visualized slower than the rest, the kw will wait for it. Obviously this situation will lead to slower runtime - because of the waiting on the condition to be fulfilled.


As for the readability aspect of using one vs the other, I won't comment on that. This is a question of implementation and code structure; you can always make something simple look dreadful, or present a complex solution in a beautiful way :). The same as python allowing you to write code like poetry, or ugly mess (the same goes for some SO answers :D); yours truly is guilty of doing all of this :)