Skip to content
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

waitForTextIn() broken in dusk 7.11.2 #1065

Closed
emil-nasso opened this issue Oct 13, 2023 · 2 comments · Fixed by #1067
Closed

waitForTextIn() broken in dusk 7.11.2 #1065

emil-nasso opened this issue Oct 13, 2023 · 2 comments · Fixed by #1067
Assignees
Labels

Comments

@emil-nasso
Copy link

Dusk Version

7.11.2

Laravel Version

10.28.0

PHP Version

8.2

PHPUnit Version

10.4.1

Database Driver & Version

sqlite

Description

It seems like the behavior of ->waitForTextIn() was changed/broken in version 7.11.2.

We have a test case where a button is clicked, the button changes, and is then changed back again after three seconds. The relevant parts look something like this:

$browser->visit(new MyPage($secret))
  ->press('@copy-button')
  ->assertSeeIn('@copy-button', 'Copied!')  
  ->waitForTextIn('@copy-button', 'Copy', 3);

The waitForTextIn() method asserts that a text can be seen in a selector, and is expected to try repeatedly until it sees the text, or the specified number of seconds have passed.

return $this->waitUsing($seconds, 100, function () use ($selector, $text) {
  return $this->assertSeeIn($selector, $text);
}, $message);

When the assertion fails, an exception is thrown, but in the old code, all exceptions were caught:
ae5a90c#diff-61e17fcc4f9de0e83ca12934a78df293a652555e735631e83c53c37977b930b2L404

If I read it correctly, this is no longer the case. When the first assertion fails, the test fails.

Please let me know if I can provide any more information.

Steps To Reproduce

Use ->waitForTextIn(...); in a test that expects at least two iterations before it succeeds.

@voidgraphics
Copy link
Contributor

voidgraphics commented Oct 13, 2023

Same problem here. I have tracked it down a bit further.

This PR (#1062) replaced the previous waiting script with php-webdriver's WebDriverWait. The until method in that class, which is responsible for doing the waiting, only keeps waiting if it catches a NoSuchElementException error during the check (see line 61 in that class).

However, Dusk's waitForTextIn method calls $this->assertSeeIn(...) as a check, which throws PHPUnit\Framework\ExpectationFailedException as it fails, which in turn does not get caught by WebDriverWait. This means that it does not keep looping to check again after some time, it just throws the exception right away after the first failed check.


For anyone affected: you can temporarily force your dusk version to v7.11.1 in composer.json, until a fix is available:

    "laravel/dusk": "7.11.1",

@crynobone crynobone added the bug label Oct 14, 2023
@crynobone crynobone self-assigned this Oct 14, 2023
@crynobone
Copy link
Member

Upon reviewing this bug, waitForTextIn() is the only method that doesn't return bool using waitUsing() but instead make an assertion. Will fix this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants