运行behat时出错

时间:2016-09-23 13:06:28

标签: php testing behat

第一种情况有效但第二种情况失败

功能文件:

And I click the "#redeem" element
And I wait for the ajax response
And I should see "OPERATOR CONTACT DETAILS AND INFORMATION WILL BE PROVIDED VIA EMAIL ON CONFIRMATION"
And I click the "#place_order" element
And I wait for the ajax response
Then I should see "Woohoo and thanks for booking!"

@javascript
Scenario: For checking mail in inbox of Gmail 
Given I am on "https://gmail.com"
And I wait 12 seconds
And I fill in "Email" with "amit.dinda.prdxn@gmail.com"

minkcontext:

/**
     * Fills in form field with specified id|name|label|value.
     *
     * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
     * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/
     * @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
     */
    public function fillField($field, $value)
    {
        $field = $this->fixStepArgument($field);
        $value = $this->fixStepArgument($value);
        $this->getSession()->getPage()->fillField($field, $value);
    }

错误消息:

 And I should see "OPERATOR CONTACT DETAILS AND INFORMATION WILL BE PROVIDED VIA EMAIL ON CONFIRMATION" # FeatureContext::assertPageContainsText()
    And I click the "#place_order" element                                                                 # FeatureContext::iClickTheElement()
    And I wait for the ajax response                                                                       # FeatureContext::iWaitForTheAjaxResponse()
    Then I should see "Woohoo and thanks for booking!"                                                     # FeatureContext::assertPageContainsText()

  @javascript
  Scenario: For checking mail in inbox of Gmail                                 # features/Redeem_a_Experience_voucher.feature:45
    Given I am on "https://gmail.com"                                           # FeatureContext::visit()
    And I wait 12 seconds                                                       # FeatureContext::iWaitSeconds()
    And I fill in "Email" with "amit.dinda.prdxn@gmail.com"                     # FeatureContext::fillField()
      Form field with id|name|label|value|placeholder "Email" not found. (Behat\Mink\Exception\ElementNotFoundException)
    And I click the "#next" element   

如果以不同的方式运行两种情况,那么它的工作正常。如果将两个场景组合在一起,为什么它不起作用。

1 个答案:

答案 0 :(得分:1)

您应该在功能级别使用@insulated标记 此标记将确保您每次都有一个干净的会话。

Feature键之前,在功能文件的第一行添加此标记。

  

您可以在功能级别以相同的方式使用@javascript,它将适用于每个方案