Challenge - 5 Problems
Dusk Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Dusk test do?
Consider this Laravel Dusk test code snippet:
What is the main behavior this test checks?
public function testUserLogin() {
$this->browse(function (Browser $browser) {
$browser->visit('/login')
->type('email', 'user@example.com')
->type('password', 'secret')
->press('Login')
->assertPathIs('/home');
});
}What is the main behavior this test checks?
Laravel
public function testUserLogin() {
$this->browse(function (Browser $browser) {
$browser->visit('/login')
->type('email', 'user@example.com')
->type('password', 'secret')
->press('Login')
->assertPathIs('/home');
});
}Attempts:
2 left
💡 Hint
Look at the sequence of actions: visit, type, press, then assert the path.
✗ Incorrect
The test visits the login page, fills in email and password, presses the login button, and then checks if the browser is redirected to '/home'. This confirms successful login and redirection.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Dusk test code
Look at this Dusk test snippet:
What is the syntax error here?
$this->browse(function (Browser $browser) {
$browser->visit('/dashboard')
->click('button#save')
->assertSee('Saved successfully')
});What is the syntax error here?
Laravel
$this->browse(function (Browser $browser) {
$browser->visit('/dashboard')
->click('button#save')
->assertSee('Saved successfully')
});Attempts:
2 left
💡 Hint
Check the end of the method chain inside the closure.
✗ Incorrect
In PHP, each statement must end with a semicolon. The method chain ends without a semicolon, causing a syntax error.
❓ state_output
advanced2:00remaining
What is the value of $count after this Dusk test runs?
Given this Dusk test code:
What is the value returned by testAddItem()?
public function testAddItem() {
$count = 0;
$this->browse(function (Browser $browser) use (&$count) {
$browser->visit('/items')
->click('@add-item')
->waitForText('Item added')
->assertSee('Item added');
$count++;
});
return $count;
}What is the value returned by testAddItem()?
Laravel
public function testAddItem() {
$count = 0;
$this->browse(function (Browser $browser) use (&$count) {
$browser->visit('/items')
->click('@add-item')
->waitForText('Item added')
->assertSee('Item added');
$count++;
});
return $count;
}Attempts:
2 left
💡 Hint
Notice the use of 'use (&$count)' and where $count++ happens.
✗ Incorrect
The variable $count is passed by reference into the closure. Inside the closure, $count is incremented by 1. After the closure runs, $count is 1 and returned.
🔧 Debug
advanced2:00remaining
Why does this Dusk test fail with a timeout error?
This Dusk test fails with a timeout:
What is the most likely reason for the timeout?
$this->browse(function (Browser $browser) {
$browser->visit('/profile')
->click('@save-button')
->waitForText('Profile updated', 2)
->assertSee('Profile updated');
});What is the most likely reason for the timeout?
Laravel
$this->browse(function (Browser $browser) {
$browser->visit('/profile')
->click('@save-button')
->waitForText('Profile updated', 2)
->assertSee('Profile updated');
});Attempts:
2 left
💡 Hint
Check the waitForText timeout duration and the expected text presence.
✗ Incorrect
The waitForText method waits up to 2 seconds for the text 'Profile updated'. If the text appears after 2 seconds, the test times out and fails.
🧠 Conceptual
expert2:00remaining
Which option best describes the role of the Browser class in Laravel Dusk?
In Laravel Dusk, what is the primary purpose of the Browser class?
Attempts:
2 left
💡 Hint
Think about what actions a user performs in a browser and how tests simulate them.
✗ Incorrect
The Browser class in Dusk simulates real user actions like visiting URLs, clicking buttons, typing text, and checking page content.