Codeception:我如何测试文件下载?

时间:2015-09-28 17:22:10

标签: php testing codeception acceptance-testing

我有一个包含多个选项的页面和一个名为“下载”的按钮。

如何测试此按钮是否有效 - 文档开始下载,使用Codeception验收测试?

2 个答案:

答案 0 :(得分:2)

请参阅上一个有关保存到磁盘How to download any file and save it to the desired location using Selenium Webdriver

的问题

我不认为Codeception可以控制本地"另存为"对话框。您可以在不询问的情况下将Firefox配置文件更改为保存,在PHP中检查文件是否存在,如果文件不存在则断言错误。

如果您使用的是Cest格式,您可以像_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) );
    }

}

这应该允许您在Cest文件中执行$I->seeFileExists('downloadpath/filename.txt');

文档http://codeception.com/docs-2.0/03-ModulesAndHelpers

中有一些自定义断言的例子

答案 1 :(得分:0)

几年前,我们为此任务创建了一个额外的模块。我不知道它是否可以与最新的代码接收版本一起使用,但是可以用它来上传文件。

https://github.com/DigitalProducts/codeception-module-remoteupload

class CreateCommentCest
{
    public function testRemoteFileUpload (WebGuy $I, $scenario)
    {
        $I->amOnPage("/html/formulare/anzeige/input_file.htm");
        $I->attachFileRemote("Datei", "image.png");
    }
}
相关问题