[QA] waiting for DOM changes

Amir E. Aharoni amir.aharoni at mail.huji.ac.il
Fri Dec 20 22:12:18 UTC 2013


Hallo,

TL;DR:
What is the most robust way to get JavaScript to tell Selenium that some
change to the DOM was made and that the testing script can go on with the
checks?

In detail:
The Language Engineering team has been developing a new special page for
the Translate extension in the last few weeks, and with Željko's help we
managed to do it quite well in test-driven development style.

One notable issue that we encountered during the development of tests for
it is testing that new elements appeared on the screen or initially
existing elements disappeared from the screen. This is made harder by
several factors:

1. WebDriver scripts working faster than JavaScript and making the test
before JavaScript finishes something. This is especially frequent with AJAX
API calls, but such a race condition can happen even without that.

2. An element can be accessed in the beginning of a scenario or even a
single step, disappear from the screen, then be recreated with the same
class. Even though it has the same class, it's a different object, so it
gets Selenium confused.

Željko initially suggested using Watir::Wait and using as a condition some
expected change in the DOM, for example a change in the count of some
elements. It worked for some time, but it cannot always be expected and the
two problems mentioned above came back to bite us and got us stuck thinking
how to resolve them in a more robust way.

The latest thing we came up with is setting a global variable in the
JavaScript code and then doing something like
Watir::Wait.while { @browser.execute_script "return window.updatingDom" }

You can see an example in
https://gerrit.wikimedia.org/r/#/c/102943/
(Not yet merged - review comments are welcome.)

What are your thoughts about it? Is it OK to use such a variable or is
there a better pattern? Is it OK to make it a property of the window
object? Are there any suggested naming patterns?

Thanks!

--
Amir Elisha Aharoni · אָמִיר אֱלִישָׁע אַהֲרוֹנִי
http://aharoni.wordpress.com
‪“We're living in pieces,
I want to live in peace.” – T. Moore‬
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wikimedia.org/pipermail/qa/attachments/20131221/06e704b1/attachment.html>


More information about the QA mailing list