Laravel - Browser Tests - Dusk Selectors

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:

    
    // HTML...
    
    
    
    // Test...
    
    $browser->click('.login-page .container div > button');
	

Dusk selectors allow you to focus on writing effective tests rather than remembering CSS selectors. To define a selector, add a dusk attribute to your HTML element. Then, when interacting with a Dusk browser, prefix the selector with @ to manipulate the attached element within your test:

    
    // HTML...
    
    
    
    // Test...
    
    $browser->click('@login-button');