laravel / dusk

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

Add PHPUnit data provider set name to output filenames #1084

Closed ziadoz closed 7 months ago

ziadoz commented 7 months ago

If there's a failure in a Dusk test case that uses PHPUnit data providers, then only a screenshot of the last data set that failed will be available in the screenshots directory. This is because without the data set in the filename, each new screenshot overwrites the previous one.

This PR adds the data set, where applicable, to the filenames of screenshots and console output:

With no data provider:

failure-Tests_Browser_FooTest_test_without_data-0.png

With unnamed data set (0, 1):

failure-Tests_Browser_FooTest_test_with_data_0-0.png
failure-Tests_Browser_FooTest_test_with_data_1-0.png

With named data set (foo, bar):

failure-Tests_Browser_FooTest_test_with_named_data_foo-0.png
failure-Tests_Browser_FooTest_test_with_named_data_bar-0.png

I've retained the existing 140 character filename limit by trimming it off the left hand side of the filename, so namespaces are truncated.

github-actions[bot] commented 7 months ago

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

taylorotwell commented 7 months ago

Can we make the PR not change the names of screenshots for tests that use no data set?

ziadoz commented 7 months ago

@taylorotwell I've pushed a test to prove the filenames are unchanged if there's no data set.