laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.87k stars 319 forks source link

Case insensitive assertions #1073

Closed Bryce-Stabenow closed 8 months ago

Bryce-Stabenow commented 8 months ago

I'd like to add the ability for users to use the optional argument of Str::contains() through ->assertSeeIn() and ->assertSee() in order to make case-insensitive assertions.

Why it matters

Currently, ->assertSeeIn() only allows for case sensitive checks. Unfortunately this can cause a problem when comparing an element's innerText. On our site, we have this element:

<span class="whitespace-nowrap uppercase" id="langHeader">en</span>

On Chrome, the innerText of this element is 'EN', but on Safari, it is 'en'. I'd like to only write one time here an assertion so that I can cover both cases instead of having conditional logic for the browser I'll be testing on:

//Chrome, which passes
$browser->assertSeeIn('#langHeader', 'EN')

//Safari, which fails
$browser->assertSeeIn('#langHeader', 'EN')

//Proposed solution, passes on both
$browser->assertSeeIn('#langHeader', 'EN', true)

This won't break any current functionality since we can pass in a default argument which will keep the existing behavior as it is.