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

时间:2016-09-20 03:00:29

标签: php yaml behat

我在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

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

  

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

此处为How to test file download in Behat

的参考

1 个答案:

答案 0 :(得分:0)

试试这个:

/**
 * @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");
    }
}