How to realize full-page screenshot by Laravel Dusk
This article is about how Laravel Dusk takes full-page screenshots. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Full page screenshot
Laravel dusks provides us with a screenshot of the failed test, which is very helpful in understanding the cause of the test failure. However, sometimes incorrect or problematic elements may be outside the display area of the screen.
To create a complete screenshot in Laravel Dusk, we must create a captureFailuresFor () method in our tests\ DuskTestCase.php that will override a method originally defined in Laravel\ Dusk\ Concerns\ ProvidesBrowser.
Protected function captureFailuresFor ($browsers) {$browsers- > each (function (Browser $browser, $key) {$body = $browser- > driver- > findElement (WebDriverBy::tagName ('body')); if (! empty ($body)) {$currentSize = $body- > getSize (); $size = new WebDriverDimension ($currentSize- > getWidth (), $currentSize- > getHeight ()); $browser- > driver- > manage ()-> window ()-> setSize ($size) } $name = str_replace ('\\','_', get_class ($this)). $this- > getName (false); $browser- > screenshot ('failure-'.$name.'-'.$key);});}
Now, whenever we call $browser- > screenshot ('$shotname'), we will get a complete screenshot when an error occurs
Thank you for reading! This is the end of the article on "how to achieve full-page screenshot in Laravel Dusk". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!