The document discusses automated browser testing. It notes that while standard browser testing is time-consuming and can miss things, automating it through tools like Dusk can validate user experiences in a realistic way. Dusk makes it possible to write simple tests that check for page content or fill out and submit forms with just a few lines of code. The document demonstrates some sample tests and argues that automated testing helps prevent issues, catch bugs, and ensure quality as a site evolves. It should be added early and test critical user flows and workflows.
3. Current testing trends
— Everyone does some form of testing (even if it isn't
structured)
— Testing results might not be logged anywhere (critical
paths)
— Lots of testing happens when a project launches, but
this may reduce as smaller features/updates are
deployed
Automated browser testing - David Darke | atomicsmash.co.uk 3
4. A lot of testing might be around requirements or client
questions:
Automated browser testing - David Darke | atomicsmash.co.uk 4
5. Standard browser testing isn't perfect
— Time consuming.
— VERY easy to forget to test something important.
— New developers on projects might not know what to
test.
— Dev aren't lazy, but most of the time there is
something more important they should be working on.
Automated browser testing - David Darke | atomicsmash.co.uk 5
7. You probably have heard
of unit testing
Automated browser testing - David Darke | atomicsmash.co.uk 7
8. With Unit Testing you break
down functionality into small
chunks (units) and validate one
bit at a time.
Automated browser testing - David Darke | atomicsmash.co.uk 8
9. For example...
A fake subscription purchase
— User logs in
— User makes purchase
— Get subscription information from the order
— Assign subscription to user
Automated browser testing - David Darke | atomicsmash.co.uk 9
10. — User logs in
— Get current user
— Validate
— Log user into site
— User makes purchase
— An order is created
— Order emails are sent
— Get subscription information from the order
— Check order for subscription product
— Sign up emails might be sent
— Assign subscription to user
— Check subscription was purchased
— Add subscription to user
— Check the subscription is active
Automated browser testing - David Darke | atomicsmash.co.uk 10
12. Unit testing is great,
but simple browser testing
give you realistic user
experiences
Automated browser testing - David Darke | atomicsmash.co.uk 12
16. Install with 4 commands
https://github.com/unglud/dusker
Automated browser testing - David Darke | atomicsmash.co.uk 16
17. Here is a very simple test. This looks for text on a screen
public function testFindText()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Text on Homepage');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 17
18. Here is a very simple test. This looks for text on screen
public function testFindText()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Text on Homepage');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 18
19. Here is a very simple test. This looks for text on screen
public function testFindText()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Text on Homepage');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 19
20. Here is a very simple test. This looks for text on screen
public function testFindText()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Text on Homepage');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 20
21. You can even fill out a form:
public function testBasicForm()
{
$this->browse(function (Browser $browser) {
$browser->visit('/form-page/')
->type('name_field', 'Cool name')
->type('email_field', 'coolemail@gmail.com')
->press('Submit')
->waitForText('Thanks for contacting us!')
->assertSee('We will get in touch with you shortly');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 21
22. You can even fill out a form:
public function testBasicForm()
{
$this->browse(function (Browser $browser) {
$browser->visit('/form-page/')
->type('name_field', 'Cool name')
->type('email_field', 'coolemail@gmail.com')
->press('Submit')
->waitForText('Thanks for contacting us!')
->assertSee('We will get in touch with you shortly');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 22
23. You can even fill out a form:
public function testBasicForm()
{
$this->browse(function (Browser $browser) {
$browser->visit('/form-page/')
->type('name_field', 'Cool name')
->type('email_field', 'coolemail@gmail.com')
->press('Submit')
->waitForText('Thanks for contacting us!')
->assertSee('We will get in touch with you shortly');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 23
24. You can even fill out a form:
public function testBasicForm()
{
$this->browse(function (Browser $browser) {
$browser->visit('/form-page/')
->type('name_field', 'Cool name')
->type('email_field', 'coolemail@gmail.com')
->press('Submit')
->waitForText('Thanks for contacting us!')
->assertSee('We will get in touch with you shortly');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 24
25. You can even fill out a form:
public function testBasicForm()
{
$this->browse(function (Browser $browser) {
$browser->visit('/form-page/')
->type('name_field', 'Cool name')
->type('email_field', 'coolemail@gmail.com')
->press('Submit')
->waitForText('Thanks for contacting us!')
->assertSee('We will get in touch with you shortly');
});
}
Automated browser testing - David Darke | atomicsmash.co.uk 25
26. Run the tests with:
php artisan dusk
Automated browser testing - David Darke | atomicsmash.co.uk 26
29. !
Endless possibilities
— You don't have to just look at the frontend of the site
— You can use special testing databases
— Maybe even create special API endpoint to fact check
some tests
Automated browser testing - David Darke | atomicsmash.co.uk 29
30. When should these tests be added?
Automated browser testing - David Darke | atomicsmash.co.uk 30
31. When should these tests be added?
Automated browser testing - David Darke | atomicsmash.co.uk 31
32. How much of the codebase should I test?
Automated browser testing - David Darke | atomicsmash.co.uk 32
33. Standard browser testing isn't perfect.. let's review
— Time consuming.
— VERY easy to forget to test something important.
— New developers on projects might not know what to
test.
— Dev aren't lazy, but most of the time there is
something more important they should be working on.
Automated browser testing - David Darke | atomicsmash.co.uk 33
34. Do we actually use it?
Automated browser testing - David Darke | atomicsmash.co.uk 34