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

Fixes waitForTextIn() broken in v7.11.2 #1067

Merged
merged 6 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"require-dev": {
"mockery/mockery": "^1.4.2",
"orchestra/testbench": "^7.0|^8.0",
"orchestra/testbench": "^7.33|^8.13",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5.10|^10.0.1",
"psy/psysh": "^0.11.12"
Expand Down
7 changes: 5 additions & 2 deletions src/Concerns/WaitsForElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Dusk\Concerns;

use Closure;
use Exception;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\ScriptTimeoutException;
use Facebook\WebDriver\Exception\TimeoutException;
Expand Down Expand Up @@ -394,8 +395,10 @@ public function waitUsing($seconds, $interval, Closure $callback, $message = nul

$this->driver->wait($seconds, $interval)->until(
function ($driver) use ($callback) {
if ($callback()) {
return true;
try {
return $callback();
} catch (Exception $e) {
return false;
}
},
$message ? sprintf($message, $seconds) : "Waited {$seconds} seconds for callback."
Expand Down
3 changes: 3 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ migrations:

workbench:
start: '/'
welcome: false
discovers:
web: true
11 changes: 11 additions & 0 deletions tests/Browser/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ public function test_it_can_browse_default_laravel_page()
->assertSee('Documentation');
});
}

public function test_it_handle_wait_for_text_in()
{
$this->browse(function (Browser $browser) {
$browser->visit('/tests/wait-for-text-in')
->assertSeeIn('@copy-button', 'Copy')
->press('@copy-button')
->assertSeeIn('@copy-button', 'Copied!')
->waitForTextIn('@copy-button', 'Copy', 3);
});
}
}
17 changes: 17 additions & 0 deletions workbench/resources/views/wait-for-text-in.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<script type="text/javascript">
function copy(e) {
e.innerHTML = 'Copied!'

setTimeout(() => {
e.innerHTML = 'Copy'
}, 2000);
}
</script>
</head>
<body>
<button dusk="copy-button" onclick="copy(this)">Copy</button>
</body>
</html>
17 changes: 17 additions & 0 deletions workbench/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::view('/', 'welcome');
Route::view('tests/wait-for-text-in', 'workbench::wait-for-text-in');