Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions browser-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ $page->assertSee('Welcome to Some Subdomain');

</div>

### Downloads

<div class="collection-method-list" markdown="1">

[expectDownload](#expect-download)
[expectDownloads](#expect-downloads)

</div>

### Debugging tests

<div class="collection-method-list" markdown="1">
Expand Down Expand Up @@ -1194,6 +1203,52 @@ The `waitForKey` method opens the current page URL in the default web browser an
$page->waitForKey(); // Useful for debugging
```

## Downloads

<a name="expect-download"></a>
### expectDownload

The `expectDownload` method executes a callback and captures the download it triggers:

```php
$download = $page->expectDownload(fn ($page) => $page->click('a[download]'));

$download->assertFilename('report.pdf');
$download->assertSuccessful();
$download->saveAs('/path/to/report.pdf');
```

The returned `Download` object provides methods for file access and assertions:

```php
$download->url();
$download->suggestedFilename();
$download->path();
$download->contents();
$download->assertFilename('data.csv');
$download->assertFilenameContains('report');
$download->assertUrlContains('/export');
$download->assertContentContains('Name,Email');
$download->assertSuccessful();
$download->assertFailed();
```

<a name="expect-downloads"></a>
### expectDownloads

The `expectDownloads` method executes a callback and captures multiple downloads:

```php
$downloads = $page->expectDownloads(
fn ($page) => $page->click('#download-all'),
count: 3
);

foreach ($downloads as $download) {
$download->assertSuccessful();
}
```

## Debugging tests

<a name="debug"></a>
Expand Down