-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add data-dusk DOM hooks (for less brittle tests) #343
Add data-dusk DOM hooks (for less brittle tests) #343
Conversation
I don't have it in front of me but I think modern browsers may not need the data- prefix, which means you could simplify this to duskhook="title" or something simpler. Not at my computer but worth checking out. Love this idea though! |
Interesting @mattstauffer - that scares me a little - but less if you wrap these
|
I like the |
@jakebathman - thanks for the input Jake. I agree - if this goes through, I'll PR a blade directive, or at least tweet a macro or something. |
Core could definitely use a pre-defined directive to close the loop on this kind of testing pattern. Good stuff. |
@calebporzio Curious: What's scaring about dropping the |
@mattstauffer - good call - maybe I like |
Particularly if coupled with an optional So you'd either have:
or
both of which could be referenced by
|
I agree with Keith. |
I like that: |
I like it combined with the Blade stuff. |
@taylorotwell - I changed the implementation to look for However, I couldn't think of a way to add a blade directive seeing as how the
The best option IMO is just to ship it with
|
I had always assumed it’d be part of |
TL;DR;
Depending on prone-to-change ui classes in Dusk tests like
div div div.campaign-panel--large ul li
can make for really brittle acceptance tests.There is a slightly better solution from the jquery days:
.js-campaign-title
Something like
.dusk-campaign-title
would do the trick, but I personally don't like muddying up my class lists.I've come up with a solution that I think is pretty BA:
<li class="active" data-dusk="campaign-title">...
My selectors in dusk now look like:
$browser->click('[data-dusk="campaign-title"]')
- which works but makes me a little sad. I've used macros like$browser->hook('campaign-title')
in the past, but things like that always feel hidden to me.I propose leveraging the existing
'@campaign-title' => 'div div.campaign-panel...'
idiom in Dusk and creating a fallback fordata-dusk
Now, anywhere in your DOM you can add
data-dusk="something"
, and it is immediately available via$browser->click('@something')
It's ballsy, I know - but people seem to really dig it.