【问题标题】:How to test file download using Behat version 3如何使用 Behat 版本 3 测试文件下载
【发布时间】:2016-09-20 03:00:28
【问题描述】:

我在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");
    }
}

下载.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

【问题讨论】:

标签: php yaml behat


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-24
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    相关资源
    最近更新 更多