-
Notifications
You must be signed in to change notification settings - Fork 28
Switch to querySelector #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ public function testBasicForm(): void | |
|
|
||
| $page->pressButton('Save'); | ||
|
|
||
| if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { | ||
| if ($this->safePageWait(5000, 'document.querySelector("#first") !== null')) { | ||
| $this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText()); | ||
| $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); | ||
| $this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText()); | ||
|
|
@@ -70,7 +70,7 @@ public function testFormSubmitWays(string $submitVia): void | |
|
|
||
| $page->pressButton($submitVia); | ||
|
|
||
| if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { | ||
| if ($this->safePageWait(5000, 'document.querySelector("#first") !== null')) { | ||
| $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); | ||
| } else { | ||
| $this->fail('Form was never submitted'); | ||
|
|
@@ -98,7 +98,7 @@ public function testFormSubmit(): void | |
|
|
||
| $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit(); | ||
|
|
||
| if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { | ||
| if ($this->safePageWait(5000, 'document.querySelector("#first") !== null')) { | ||
| $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); | ||
| } | ||
| } | ||
|
|
@@ -113,7 +113,7 @@ public function testFormSubmitWithoutButton(): void | |
|
|
||
| $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit(); | ||
|
|
||
| if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { | ||
| if ($this->safePageWait(5000, 'document.querySelector("#first") !== null')) { | ||
| $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); | ||
| } | ||
| } | ||
|
|
@@ -204,7 +204,7 @@ public function testAdvancedForm(): void | |
|
|
||
| $button->press(); | ||
|
|
||
| if ($this->safePageWait(5000, 'document.getElementsByTagName("title") === "Advanced form save"')) { | ||
| if ($this->safePageWait(5000, 'document.querySelector("title")?.textContent === "Advanced form save"')) { | ||
| $out = <<<'OUT' | ||
| array( | ||
| agreement = `on`, | ||
|
|
@@ -245,7 +245,7 @@ public function testQuoteInValue(): void | |
|
|
||
| $button->press(); | ||
|
|
||
| if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { | ||
| if ($this->safePageWait(5000, 'document.querySelector("title") !== null')) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if these cases with the title element actually makes sense - there's a pretty high chance we will always have a title element (on both the before and the after pages), so it feels kinda pointless?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. We should check such checks to more bullet-proof ones. See my other comment. |
||
| $out = <<<'OUT' | ||
| first_name = `Foo "item"`, | ||
| last_name = `Bar`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Author of the https://www.reddit.com/r/learnjavascript/comments/i0f5o8/comment/fzqhln4/ comment tells (I haven't checked that personally) that after DOM update:
document.querySelectormethod would return the DOM element from the old page;document.getElementByIdwould return the DOM element from the new page.If that is really the case, then
#firstelement won't be found at all and you'll have a 5-second delay all the time.Have you checked this delay while running a new test suite version (from this PR) locally?
IMO we should be doing either of these:
document.getElementById) for an element that is only present on the page loaded after the form submission is finishedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how you are reading that, the comment seems to say something else (unrelated to the page).
From what I know, both return the same element object. This can be easily checked with
document.getElementById("first") === document.querySelector("#first").I think the misunderstanding is from getElementsByClassName (returns a live HTMLCollection) vs querySelectorAll (which returns a non-live NodeList). According to some search, there is no such thing as a live/non-live node - that term only applies to collections, and it means whether looping through the collection returns items from when the collection was produced (non-live) or re-executes the condition each time (live).
And in any case, it should be impossible for plain javascript (which we are executing within the context of a page) to retrieve elements from a previous page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you're not getting 5sec delay each time and
querySelectorworks as expected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it (the ones with the red mark have the 5s wait, but test finished quickly):

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However that doesn't fully disprove your point - we are only checking if the title element exists - it doesn't check which page it is from.