Performance: Browser testing with Dusk
Browser testing with Dusk affects the development workflow speed and resource usage during automated UI tests, impacting test execution time and system responsiveness.
Jump into concepts and practice - no test required
public function testExample() {
$this->browse(function (Browser $browser) {
$browser->visit('/home')
->waitForText('Welcome', 10) // waits up to 10 seconds but continues as soon as text appears
->assertSee('Welcome');
});
}public function testExample() {
$this->browse(function (Browser $browser) {
$browser->visit('/home')
->pause(5000) // waits fixed 5 seconds
->assertSee('Welcome');
});
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed pause (pause(5000)) | Minimal | Minimal | Minimal but causes idle wait | [X] Bad |
| Dynamic wait (waitForText) | Minimal | Minimal | Minimal and efficient | [OK] Good |
visit(), and to check text is assertSee().open(), goTo(), and navigate(), which do not exist in Dusk.$browser->visit('/login')
->type('email', 'user@example.com')
->type('password', 'secret')
->press('Login')
->assertPathIs('/dashboard');type() method fills inputs correctly, and assertPathIs() verifies the current URL path. If login redirects to /dashboard, the test passes.$browser->visit('/profile')
->type('name', 'John Doe')
->click('Save')
->assertSee('Profile updated');press(), not click().type() fills inputs, assertSee() checks text, and visit() accepts paths, so these are correct.select().choose(), pick(), and set() do not exist or are incorrect for dropdown selection in Dusk.