Skip to content

Commit 3f3d9bb

Browse files
authored
Document Dusk selector hooks
1 parent a092e41 commit 3f3d9bb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

dusk.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [Using The Mouse](#using-the-mouse)
1919
- [Scoping Selectors](#scoping-selectors)
2020
- [Waiting For Elements](#waiting-for-elements)
21+
- [Selector Hooks](#selector-hooks)
2122
- [Making Vue Assertions](#making-vue-assertions)
2223
- [Available Assertions](#available-assertions)
2324
- [Pages](#pages)
@@ -451,6 +452,30 @@ Many of the "wait" methods in Dusk rely on the underlying `waitUsing` method. Yo
451452
return $something->isReady();
452453
}, "Something wasn't ready in time.");
453454

455+
456+
<a name="selector hooks"></a>
457+
### Selector Hooks
458+
459+
Choosing good CSS Selectors for interacting with elements is one of the hardest parts of writing Dusk tests. Over time, frontend changes can cause CSS selectors like the following to break your tests:
460+
461+
// HTML...
462+
463+
<button>Login</button>
464+
465+
// Test...
466+
467+
$browser->click('.login-page .container div > button');
468+
469+
Selector hooks allow you to focus on writing effective tests rather than wrangling CSS selectors. To register a hook, add a `dusk` attribute to your HTML element, then prefix the hook with `@` to use it as a selector:
470+
471+
// HTML...
472+
473+
<button dusk="login-button">Login</button>
474+
475+
// Test...
476+
477+
$browser->click('@login-button');
478+
454479
<a name="making-vue-assertions"></a>
455480
### Making Vue Assertions
456481

0 commit comments

Comments
 (0)