In your test, you can call the fake() method on the Screenshot facade to fake the screenshot generation. Because the screenshot generation is faked, your tests will run much faster.
use Spatie\LaravelScreenshot\Facades\Screenshot;
beforeEach(function () {
Screenshot::fake();
});
##assertSaved
You can use the assertSaved method to assert that a screenshot was saved. You can pass a string path or a callable.
use Spatie\LaravelScreenshot\Facades\Screenshot;
Screenshot::assertSaved('screenshots/homepage.png');
With a callable for more detailed assertions:
use Spatie\LaravelScreenshot\Facades\Screenshot;
Screenshot::assertSaved(function ($screenshot, string $path) {
return $path === 'screenshots/homepage.png'
&& $screenshot->url === 'https://example.com';
});
##assertUrlIs
You can use the assertUrlIs method to assert that a screenshot was taken of a specific URL:
Screenshot::assertUrlIs('https://example.com');
##assertHtmlContains
You can use the assertHtmlContains method to assert that a screenshot was taken from HTML containing a given string:
Screenshot::assertHtmlContains('Hello World');
##Queued screenshot assertions
##assertQueued
You can use the assertQueued method to assert that a screenshot was queued for generation. You can pass a string path or a callable.
Screenshot::assertQueued('screenshots/homepage.png');
With a callable for more detailed assertions:
Screenshot::assertQueued(function ($screenshot, string $path) {
return $path === 'screenshots/homepage.png'
&& $screenshot->fullPage === true;
});
##assertNotQueued
You can use the assertNotQueued method to assert that no screenshots were queued, or that a specific path was not queued.
Screenshot::assertNotQueued();
Screenshot::assertNotQueued('screenshots/other.png');