【问题标题】:behat FeatureContext.php how to skip a scenariobehat FeatureContext.php 如何跳过一个场景
【发布时间】:2015-10-13 14:51:34
【问题描述】:

我试图找到一种方法来跳过 FeatureContext.php 中的场景。 我得到了一个测试,只有在条件正确时才会执行,否则 der 将被跳过。我的想法是使用“@weeksale”之类的标签来检查场景

  @weeksale
  Scenario: test
    Given I go to "/"
    Then I should see "Unsere Leistungen"

在我的 FeatureContext 中,我得到了一个条件,如果它是假的,他们就跳过了

 /**
 * @beforeScenario
 * @weeksale
 *
 * @param Behat\Behat\Event\ScenarioEvent $event
 */
public function weekSaleInTime($event)
{
    $dateUrl = $this->parameters['weekSaleDatePage'];
    $date = file_get_contents($dateUrl);

    $dateArray = explode("\r\n", $date);

    $result = $this->isCurrentDateBetween($dateArray[0], $dateArray[1]);

if($result == false)
{
  //behat skip this scenario
}

任何人知道我如何告诉 behat 跳过一个场景?

(behat v2.5.5)

【问题讨论】:

    标签: php behat skip mink scenarios


    【解决方案1】:

    这是您的持续集成工具要做的工作。

    在您的 behat.yml 文件中创建一个新路径,如下所示:

    event:
     filters:
        tags: '~@event'
     paths:
          features:  features
          bootstrap: %behat.paths.features%/bootstrap
    
     extensions:
        Behat\MinkExtension\Extension:
            base_url: http://<YOUR URL HERE>
            javascript_session: selenium2
            browser_name: <BROWSER>
            selenium2:
               browser: "<BROWSER>"
               wd_host: "http://127.0.0.1:9515/wd/hub"
            goutte: ~
     formatter:
        name:               pretty,html,junit
        parameters:
            output_path:    ,../ci/published/report.html,../ci/published
    

    如果您在持续集成工具中包含一个脚本来选择运行哪个脚本,那么您应该在路上了。

    如果您在这些日期内手动运行测试,请将“事件”更改为“默认”,它将照常运行,同时删除所有标有“@event”的场景。

    【讨论】:

    • 是的,这有点像我们做的。我得到了 Jenkins CI 的 build.xml,其中执行了一个执行 shell 命令的 php 文件。使用日期条件,我只需在推荐 --tags ~@weeksale 处附加以排除所有带有此标签的行为测试。感谢您的回答
    【解决方案2】:

    在您的场景之上,只需在您的示例中添加一个标签,例如 @weeksale

    在执行场景时运行命令 behat --tags '~@weeksale'

    ~(否定)不运行特定的标记场景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多