[QA] waiting for DOM changes

Chris McMahon cmcmahon at wikimedia.org
Mon Dec 30 15:32:38 UTC 2013


One more example from the Flow tests, I had forgotten about this one:

This step waits for the spinner to disappear and then checks that the
element has some text:

Then(/^the saved topic body should contain (.+)$/) do |edited_post|
  on(FlowPage) do |page|
    page.small_spinner_element.when_not_present
    page.topic_post.should match(edited_post + @random_string)
  end


On Fri, Dec 20, 2013 at 3:12 PM, Amir E. Aharoni <
amir.aharoni at mail.huji.ac.il> wrote:

> 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‬
>
> _______________________________________________
> QA mailing list
> QA at lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/qa
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wikimedia.org/pipermail/qa/attachments/20131230/67ffc617/attachment.html>


More information about the QA mailing list