The approach differs depending on whether you are using the (fast, headless PHP requests) or WebDriver (real browser testing via Selenium). 1. Using WebDriver (Selenium)
: Returns the raw body of the downloaded file.
When using the WebDriver module , the browser handles the download. To automate this without manual intervention, you must configure the browser profile to download files to a specific directory automatically. codeception check download file
Create a method in tests/Support/Helper/Acceptance.php to verify file existence:
PhpBrowser acts like a specialized curl client. While it doesn't "download" a file to a folder like a real browser, it captures the raw response content. You can access this via a custom helper: The approach differs depending on whether you are
modules: enabled: - WebDriver: url: http://localhost/ browser: chrome capabilities: goog:chromeOptions: prefs: download.default_directory: "/path/to/project/tests/_output/" download.prompt_for_download: false Use code with caution. 2. Using PhpBrowser
namespace Helper; class Acceptance extends \Codeception\Module { public function seeFileWasDownloaded($filename) { $path = codecept_output_dir() . $filename; $this->assertTrue(file_exists($path), "File $filename was not found in output directory."); } } Use code with caution. In your test file ( Cest or Test ), you can then use: When using the WebDriver module , the browser
: Can be used to save the returned binary to a local file for further inspection. Verifying the Downloaded File