Behat tests are failing due to not waiting for Javascript to finish

Bug #1575512 reported by Aaron Wells
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Robert Lyon
17.10
Fix Released
High
Robert Lyon

Bug Description

We're seeing an annoying number of Behat tests that are failing due to a race condition between Behat and the Javascript in the browser. Here's an example: http://test.mahara.org/job/mahara-gerrit/5558/console

In that case, the test is failing in this part:

1. I press "Create folder"
2. And I follow "Folder1"

The failure happens because Behat can't find a link named "Follow1" when it tries to carry out that step. The way it *should* work, is basically like this:

1. Behat step: I press "Create folder"
2. Behat web driver locates and presses the "Create folder" button.
3. The button press triggers a Pieform javascript method, which fires off an Ajax request to submit the form for creating a new folder.
4. The Ajax request is handled by a PHP script, which creates the artefact and sends back a success response, including updated HTML for what the file area should look like now.
5. Pieform Javascript receives the response from the Ajax script, and swaps the new HTML in place of the old HTML. The new HTML contains the link to the new folder.
6. Behat step: I follow "Folder1"
7. Behat web driver locates and clicks the link with text "Folder1".

The race condition seems to happen because when you do the "I press" step (defined in \Behat\MinkExtension\Context\MinkContext) waits for the conclusion of any HTTP requests caused by the button press, but it doesn't wait for the Pieform callback to finish.

The quick workaround for these is to add a "And I wait "1" seconds" step on affected tests. But it would be better to get a systemic fix to it. I think maybe the best thing to do, would be to change all the underlying "find" methods into spin functions, which, if they don't find the element, will wait up to 5 seconds to find it. Behat's inheritance structure for steps may make that tricky to do, though.

Tags: behat
Son Nguyen (ngson2000)
Changed in mahara:
assignee: nobody → Son Nguyen (ngson2000)
status: Confirmed → In Progress
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/6988

Robert Lyon (robertl-9)
Changed in mahara:
milestone: 16.10.0 → 16.10.1
Robert Lyon (robertl-9)
Changed in mahara:
milestone: 16.10.1 → 17.04.0
Changed in mahara:
assignee: Son Nguyen (ngson2000) → nobody
Robert Lyon (robertl-9)
Changed in mahara:
assignee: nobody → Robert Lyon (robertl-9)
Robert Lyon (robertl-9)
no longer affects: mahara/16.04
Robert Lyon (robertl-9)
no longer affects: mahara/16.10
no longer affects: mahara/17.04
Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/6988
Committed: https://git.mahara.org/mahara/mahara/commit/f27e5ebf72bb88e8feac9fced877c27c5f7eec3e
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit f27e5ebf72bb88e8feac9fced877c27c5f7eec3e
Author: Son Nguyen <email address hidden>
Date: Wed Aug 31 13:54:05 2016 +1200

Bug 1575512: Better way to check if a page is ready for behat tests

Add JS event handlers for
- pieforms
- tinyMCE editor
- bootstrap
to detect when a page is ready after a behat test step

Refactor behat tests .feature files
- remove redundant steps I wait
- replace the step I set the field ...
by the faster step I fill in ...
for regular text inputs

Change-Id: I0ce4cc8dc32f228a648cfee608ec60ed917b7774

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/8094
Committed: https://git.mahara.org/mahara/mahara/commit/70ac7cec17e778da31d928ea37a7e2c7de13459f
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit 70ac7cec17e778da31d928ea37a7e2c7de13459f
Author: Cecilia Vela Gurovic <email address hidden>
Date: Thu Oct 5 17:06:05 2017 +1300

Bug 1720269: old_raw patches for bugs: (General)

Bug 1720264
Bug 1720235
Bug 1719736
Bug 1718821
Bug 1705126
Bug 1694908
Bug 1690687
Bug 1690232
Bug 1686843
Bug 1685041
Bug 1683561
Bug 1681987
Bug 1681934
Bug 1675223
Bug 1636064
Bug 1575512
Bug 1369569
Bug 692769

Also fixing up un-closed html tags in Bug 1701437 for raw and old raw

behatnotneeded

Change-Id: I8ac930ceebf78b4edad97289994318e7689a1e94

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "17.10_STABLE" branch: https://reviews.mahara.org/8116

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/8116
Committed: https://git.mahara.org/mahara/mahara/commit/a25f4f11d35bf17d54acfb8010cd29e432fc86ea
Submitter: Robert Lyon (<email address hidden>)
Branch: 17.10_STABLE

commit a25f4f11d35bf17d54acfb8010cd29e432fc86ea
Author: Cecilia Vela Gurovic <email address hidden>
Date: Thu Oct 5 17:06:05 2017 +1300

Bug 1720269: old_raw patches for bugs: (General)

Bug 1720264
Bug 1720235
Bug 1719736
Bug 1718821
Bug 1705126
Bug 1694908
Bug 1690687
Bug 1690232
Bug 1686843
Bug 1685041
Bug 1683561
Bug 1681987
Bug 1681934
Bug 1675223
Bug 1636064
Bug 1575512
Bug 1369569
Bug 692769

Also fixing up un-closed html tags in Bug 1701437 for raw and old raw

behatnotneeded

Change-Id: I8ac930ceebf78b4edad97289994318e7689a1e94
(cherry picked from commit 70ac7cec17e778da31d928ea37a7e2c7de13459f)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.