Summer Sale! All accounts are 50% off this week.

restran's avatar

Testing File Download with Dusk

Hey!

I'm new using Dusk and I need to test the following case:

I have a Download File button, when I click it a csv file is downloaded.

  • Is there a way to check that the file was successfuly downloaded to my Download folder?

Thanks!

0 likes
7 replies
jlrdw's avatar

Why would you test a file download? Wouldn't it pass if you just downloaded a file, and it worked? Just curious.

restran's avatar

Yes, I need to verify that the file has downloaded correctly at least.

ohffs's avatar

You might be better using the 'basic' http tests for downloads. You can do things like :

$response = $this->actingAs($user)->get(route('export.report'));

$response->assertStatus(200);
$response->assertHeader('content-disposition', 'attachment; filename="report.csv"');
$file = $response->getFile();
$filename = $file->getPathname();
// do whatever you need with the filename/file
3 likes
hieuluong's avatar

RESTRAN, Have you test download file with dusk yet?

tobyreed's avatar

Has anyone found a way of testing if a download has successfully been downloaded and asserted it?

lucasvdh's avatar

@tobyreed when the ->get() method succeeds it implies the download was successful. If you also want to check the content of the downloaded file you could probably just get that from the $response.

gypsyskies's avatar

As tobyreed asked, how do you assert that a file was downloaded with Dusk? If a download is triggered client-side.

Please or to participate in this conversation.