Testing: Fix randomly failing E2E test#28073
Conversation
…e or not an HTMLElement`
2c247e6 to
a932bfd
Compare
|
Size Change: +22 B (0%) Total Size: 1.3 MB
ℹ️ View Unchanged
|
|
Hey thanks for this! Do you know why the network request causes a focus loss? Is that a bug that should be fixed? |
|
A possibly less fragile approach here would be to use |
|
Let's merge this because it fixes an infuriating intermittent test failure 🙂 I think that we need to check why focus is lost when the network request completes, though. I worry that there's an actual bug there. |
@noisysocks You're welcome! I'm not sure why the request is causing the focus loss, I'll try to analyze it later. 😸
Yes! I tried waiting for the Thanks for the feedback! 😀 |
|
Awesome work here and I'm very happy that this intermittent failure is fixed. It seems to me that this test is written in such a way that consequential tests depend on each other (which is not great). Ideally we'd start a new page/load screen in |
Description
The E2E tests for the
multi-entity-editing.test.jsfile were failing very often, in a random sort (like here, here, and here). When testing locally, I found that the issue was happening due to the tested HTML element's focus being lost. This PR fixes this error.For better understanding, check the "How has this been tested?" section 😸.
How has this been tested?
In short - this test consists of editing the entities and asserting whether they have been correctly dirtied, so, the basic flow for each closure of the test is:
editthe target element;assertobtained results;savechanges (afterEachmethod call).The error was happening due to a bug between the
assertand thesavestep:After asserting the results for a previous test closure, the
savestep calls thesaveAllEntitiesfunction:gutenberg/packages/e2e-tests/specs/experiments/multi-entity-editing.test.js
Lines 202 to 205 in a7fb6bb
Which would be basically clicking the "Save" button on the tested page:
gutenberg/packages/e2e-tests/specs/experiments/multi-entity-editing.test.js
Lines 68 to 72 in a7fb6bb
The problem: calling
awaiton the button click just waits for the returned click promise to be resolved; it doesn't wait for the whole save process to be completed.Therefore, sometimes, when the save process was not yet completed and the test continued, after the save request completed, the
editstep would try to change the element value - but it would fail, due to the focus change that would happen in the page. I find this very hard to explain only using words, so maybe these screenshots might help:This is the exact moment where the error happens: right after saving the changes, about to focus on the next tested element.
I simulated the behavior in the console:
I made a
setIntervalcall to keep logging the active element (the one currently focused) - and right after, the default test behavior: click the save button and start the next test closure. As shown, the block element would lose its focus right after the save request completed, causing the error.In addition, I ran the test 60 times, comparing the outputs before and after the changes:
Before - Failing 70% of the time (42 failures out of 60 runs) - failures related to the error that was being fixed (
Node is not visible/Node is detached from document).After - No failures. 🥳🎉🎉🎉🎉😸
Types of changes
Bugfix to the E2E tests.
Checklist: