Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception: how do I test file download?

I have a page with a several options and a button named "Download".

How do I test that this button works - document begin downloading, using Codeception acceptance tests?

like image 339
FelikZ Avatar asked Sep 28 '15 17:09

FelikZ


People also ask

How do you skip tests in Codeception?

The codeception library is built on top of phpunit, so to skip test there is a function markTestSkipped . Every code after this function will not be executed. It is good to add message explaining why test was skipped. Skipped tests will be marked with capital letter S .

Does Codeception use selenium?

Codeception is very flexible framework that you can use to write your Selenium tests.

Is Codeception open source?

Codeception. Being a full-stack PHP-based testing framework, Codeception open source test automation tool allows QA teams to create and execute a plethora of tests, including acceptance, functional, and even unit ones on different browsers, using the Selenium Web Driver.


1 Answers

See this previous question about saving to disk How to download any file and save it to the desired location using Selenium Webdriver

I don't think Codeception can control a native "Save as" dialog box. You could probably change the Firefox profile to save without asking, check for file existence in PHP and assert an error if the file does not exist.

If you are using the Cest format you could make a helper like the following in _support/WebHelper.php.

<?php
namespace Codeception\Module;

// here you can define custom functions for WebGuy

class WebHelper extends \Codeception\Module
{

    public function seeFileExists($filename)
    {
        \PHPUnit_Framework_Assert::assertTrue( file_exists($filename) );
    }

}

This should allow you to do $I->seeFileExists('downloadpath/filename.txt'); in your Cest files.

There are a few examples of custom assertions in the documentation http://codeception.com/docs-2.0/03-ModulesAndHelpers

like image 165
cambist Avatar answered Sep 30 '22 04:09

cambist