如何使用Behat版本3测试文件下载


How to test file download using Behat version 3

我在FeatureContext中实现了这个函数,但我不知道如何在behat.yml中配置

这是我的代码

FeatureContext.php

/**
 * @Then /^the file ".+" should be downloaded$/
 * @param $filename
 *
 * @throws 'Exception
 */
public function assertFileDownloaded($filename) {
    if (!file_exists('/download/dir/' . $filename)) {
        throw new Exception("Can not download");
    }
}

Download.feature

Scenario: Download unlock documents with Success Stories
  When I am on "managed-security-services/downloads/"
  Then I should be on "/managed-security-services/downloads/"
  And I should see "Bühler"
  Then I click on the text "Bühler"
  And I wait for "1" seconds
  And the file ".+" should be downloaded

我不知道如何传递参数到behat.yml下面是代码

suites:
    default:
      paths: &featurePaths
        - '%paths.base%/features'
      contexts: &contexts
        - FeatureContext

当我运行测试时,它显示的消息错误如下:

[behavior 'Testwork'Argument'Exception'UnknownParameterValueException]无法找到方法FeatureContext::assertFileDownloaded()的参数$filename的匹配值。

如何测试文件下载

试试这个:

/**
 * @Then /^the file :filename should be downloaded$/
 *
 * @throws 'Exception
 */
public function assertFileDownloaded($filename) {
    if (!file_exists('/download/dir/' . $filename)) {
        throw new Exception("Can not download");
    }
}