First time I've seen this particular random failure https://www.drupal.org/pift-ci-job/2629301
1) Drupal\FunctionalJavascriptTests\Tests\JSWebAssertTest::testJsWebAssert
WebDriver\Exception\CurlExec: Curl error thrown for http POST to http://chromedriver-jenkins-drupal-patches-175432:9515/session/3d49e65f913131440b1a261ae7b7ebd0/execute with params: {"script":"return arguments[0].getAttribute(\"id\")","args":[{"ELEMENT":"0.49279528092055735-44"}]}
Retries: 10 and last result:
{"sessionId":"3d49e65f913131440b1a261ae7b7ebd0","status":10,"value":{"message":"stale element reference: element is not attached to the page document\n (Session info: headless chrome=106.0.5249.103)\n (Driver info: chromedriver=106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249@{#569}),platform=Linux 4.9.0-0.bpo.6-amd64 x86_64)"}}
Steps to reproduce
In another galaxy issue, far, far away, I reproduced the first error and took screenshots when the assertion fails. That looks like this:

Or in fact any number in that text except for the wanted 1100.
So the assertion is done whilst the DOM-manipulation through JavaScript isn't finished.
Which is number 2 on the list of why the "stale element"-stuff happens:
The failure can only happen for two reasons:
1. The element under test is removed from the DOM.
2. The page changed whilst after getting the element under test.
Proposed resolution
Many moons ago, when we were on some faster testbot servers, the assertion would be called when the DOM-manipulation was long done.
However, nowadays stuff goes slower, so we need to assert the elements _after_ the JS-magic is done.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3350973-7.patch | 976 bytes | spokje |
Comments
Comment #2
penyaskitoAgain at https://www.drupal.org/pift-ci-job/2640694
Comment #4
spokjeLet's first proof that there still is a random test failure.
Here's a patch that runs _only_
\Drupal\FunctionalJavascriptTests\Tests\JSWebAssertTest500 times.Comment #5
spokjeComment #6
spokjeThe normal routine to prove a random failure is fixed is to run the failing patch and the patch with the fix at the same time, whilst the latter has to have ~8000 - 10.000 failure free runs to prove it's credibility.
So let's do that here.
Comment #7
spokje25.000 runs is fine with me, here's the actual patch
Comment #8
spokjeComment #9
spokjeComment #10
smustgrave commentedImprovement looks good. Thanks @Spokje for explaining too!
Comment #15
catchReally nice find!
Committed/pushed to 11.x and cherry-picked back through to 9.5.x, thanks!