Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize full-page screenshot by Laravel Dusk

Shulou Source: shulou.com Published: 2022-06-01 04:35:24 10月01日 Update

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!

Tags: Screen screenshot content method more article error medium creation help test good practical element area reason article look knowledge question reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information Xiaomi Linux Redmi