Problem/Motivation
In Settings Tray tests we have OutsideInJavascriptTestBase::waitForNoElement. This is used when an element will be removed from the page but we can't just check to see if it removed becase the Javascript to remove might take time and this could cause random failures.
Proposed resolution
Create \Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait()
This will be similar to \Drupal\FunctionalJavascriptTests\JSWebAssert::waitForElement but course there is no point in returning the element which should not be there.
Remaining tasks
Write patch
User interface changes
None
API changes
New test assert
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #48 | 2892440-48.patch | 37.05 KB | alexpott |
| #48 | 43-48-interdiff.txt | 3.64 KB | alexpott |
| #43 | 2892440-43.patch | 35.75 KB | tedbow |
| #43 | interdiff-40-43.txt | 648 bytes | tedbow |
| #40 | 2892440-40.patch | 36.72 KB | bnjmnm |
Comments
Comment #2
dawehnerI know https://www.drupal.org/u/marcoscano had the same usecase on the weekend. I'm not sure right now what he ended up with.
Comment #5
tedbowOk here is patch. It does:
waitForNoElement()function and replace it with the new assert.This just waits for element instead of assuming it is already there. My assumption as to why this is needed because the new assert checks if he conditions pass more frequently then
\Drupal\FunctionalJavascriptTests\JavascriptTestBase::assertJsConditiondid which was used before so it get to this code a little bit faster and the JS that didDrupal.announcehas not fire yet.Comment #6
Anonymous (not verified) commentedLooks nice! But why
assertNoElementAfterWait()doesn't usewaitFor()API? Probably because it will lead to a kind of duplication of the header function inside the function. But I think it's better than duplicating the function body. We also can not affect the operation of this function, if one day we decide to change thewaitFor().Comment #7
tedbow@vaplas, we can't use
\Behat\Mink\Element\Element::waitForbecause it calls a user function until it returns a non-empty result. Where as in this case we have to wait for a empty result.Comment #8
Anonymous (not verified) commentedBut we can determine the condition by which the user function returns TRUE with empty result, and FALSE with non-empty result:
Comment #9
tedbowWe could but the docs for this method on
\Behat\Mink\Element\ElementInterface::waitFor()specifically sayWaits for an element(-s) to appear and returns it.The implementation of it though on
\Behat\Mink\Element\Element::waitForhas nothing to do with elements in the code.But still we would be calling this method for the opposite of its intended purpose. If we were going to use it in this case should we use every time we need to wait on
$result = call_user_func($callback, $this);regardless of whether it had anything to do with what the method on the interface docs say?
It would work in all kinds of situations but I don't think we should use outside of its intended purpose as describe on the interface.
Comment #10
Anonymous (not verified) commentedThen maybe there is a sense to make a universal
JTB::waitFor()method like c/p fromBehat\Mink\Element\Element::waitFor(). But this can be done later of course. RTBC++Just reroll #5 + few nit fixes.
Revert, because out of scope. This will be fixed like part of #2946294: Fix race conditions in OffCanvasTestBase.
Additional issues, that also wait
assertNoElementAfterWait:Comment #12
Anonymous (not verified) commented#11: Random fails?
Also after
setExpectedException()the test is stoped, it should be used only for the last assert. Replaced on try/catch.Comment #14
Anonymous (not verified) commented#5:
It is really related. Because
assertNoElementAfterWait()faster thanwaitForNoElement(). As a result, a test flaw is detected. So reverted this part from #2946294: Fix race conditions in OffCanvasTestBase again.OffCanvasTest uses
waitForElement(). So will be better just deprecated this method, but not remove.Comment #16
Anonymous (not verified) commentedComment #17
dawehnerHaha, yeah that's certainly a true statement.
Do you want to open up a follow up for that?
Comment #18
Anonymous (not verified) commentedThanks for review! Sure, done #2977089: Provide universal waitFor() to JavaScript tests
Comment #19
alexpottWe need a
@trigger_error('some mesage', E_USER_DEPRECATED)to inform other tests that this is going away.I think the
if ($node) {is unnecessary. Less conditions makes things less complicated.Nice tests!
Comment #20
Anonymous (not verified) commented#19: thanks for nice points! Done. Also remove
FieldTest::waitForNoElement(). In contrast to OffCanvasTestBase, FieldTest is not *Base test.Comment #22
bnjmnmReroll + a few coding standards fixes
Comment #23
phenaproximaThere's an extra blank line here, but that is fixable on commit.
Otherwise, I think this looks fine. Good to go.
Comment #25
tedbowI can't wait to get this is but if you search for "2892440" you will find 3 more @todo's we need to take care of in this issue. Should just be able to swap out the calls.
Comment #27
bnjmnmTook care of the 10 remaining @todos
Comment #28
lendudeThank you @bnjmnm. All feedback has been addressed, back to RTBC.
Comment #30
lendudeThe fail might be related to the removal of this line. It seems that removing this might cause a random fail.
Comment #31
bnjmnmThanks @lendude, looks like that line was inadvertently removed instead of replaced with the new method. Glad you & the tests caught that!
Comment #33
bnjmnmThe new test failure is most likely due to css transitions changing the location of the element the test is attempting to access. There's a test module in Layout Builder that disables css transitions that will likely fix the issue (and would add right now if I was on the machine with my dev environment)
Comment #34
bnjmnmAdded the test module that disables CSS transitions to
MoveBlockFormTest. Hoping that addresses the unexpected test failure.Comment #35
dwwInterdiffs look clean and right. Bot is happy green. RTBC.
Thanks!
-Derek
Comment #36
alexpottFor some reason this hasn;t been set back to needs work for the re-roll.
Comment #37
bnjmnmReroll
Comment #38
tedbow@bnjmnm thanks for getting this going again.
Is there a reason we are not replacing this with a call to
assertNoElementAfterWait()?Can we actually just remove this or do we have to deprecate it like the occurence in
OffCanvasTestBase? Because they are both base test classes.I think before we could just remove it because Layout Builder was experimental but now it is stable.
We should repace this call like the others.
I guess this has taken a while 😉
Need update this to 8.8.x
Need to update to 8.8.0
Comment #39
vacho commentedPatch applies well to 8.8.x
Comment #40
bnjmnm#38.1
. After discovering that
assertNoElementAfterWaitwould not work due to the element still being present (just hidden), I also realized the hide() transition is now instantaneous, so the wait is no longer neccessary. It had been added in an earlier iteration of the toggle issue when hide/show were animatedItems 2-5 of #38 are also addressed in this patch.
Comment #41
krzysztof domańskiThe element selector type is case-sensitive. CSS and XPath should be lowercase.
See #3041900: The element selector type "CSS, XPath" in JSWebAssert should be lowercase.
Comment #42
krzysztof domańskihttps://www.drupal.org/pift-ci-job/1295717
https://www.drupal.org/pift-ci-job/1295054
https://www.drupal.org/pift-ci-job/1295043
https://www.drupal.org/pift-ci-job/1295846
https://www.drupal.org/pift-ci-job/1295036
https://www.drupal.org/pift-ci-job/1295033
Comment #43
tedbowreroll plus #41
Comment #45
krzysztof domańskiNeeds reroll after fixed:
#2901792: Disable all animations in Javascript testing
Comment #46
krzysztof domański#3056536: LayoutBuilderDisableInteractionsTest randomly fails
The assertNoElementAfterWait has been changed in
core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php.Comment #47
alexpottThis is no longer critical.
Comment #48
alexpottRerolled and fixed fail.
Comment #49
lendudeCan't find anything to add to this, all feedback had been addressed again, so back to RTBC
Comment #50
alexpottCommitted 9a11de6 and pushed to 8.8.x. Thanks!
Committed 6ad73cb and pushed to 8.7.x. Thanks!
Comment #54
alexpottDidn't quite merge to 8.7.x correctly so had to commit a quick follow-up afterwards... Add block vs Add Block - fun https://www.drupal.org/commitlog/commit/2/6ad73cb21868ac8fba291aef6de5a6...