yii - Behat步骤 "I should see"没有看到

标签 yii behat

在 Yii 框架中使用 Behat,我观察到它非常奇怪的行为:在使用像

这样的步骤时,Behat 没有找到一些文本
Then I should see "some text"

有些文本可以正常找到,但有些则不能。为了确保我位于我认为所在的页面上,我在 View 文件中添加了一些标记,Behat 可以看到它们。

所以,场景是

  Scenario: editing journal
    Given the following journals are present:
        | name          | link                      | description           |
        | Murzilka      | http://www.murz.com       | advanced child journal| 
        | Nature        | www nature com            | nice journal          |
    When I am on edit page for journal "Nature"
    Then I should see "Update Nature"
    Then I should see "nice journal"
    Then I should see "1qazxsw2" <-- a marker
    Then I should see "2wsxcde3" <-- a marker
    Then I should see "www nature com"

输出结果为

 Scenario: editing journal
   # features\journal.feature:21
Given the following journals are present:
   # FeatureContext::theFollowingJournalsArePresent()
  | name     | link                | description            |
  | Murzilka | http://www.murz.com | advanced child journal |
  | Nature   | www nature com      | nice journal           |
When I am on edit page for journal "Nature"
   # FeatureContext::iAmOnEditPageForJournal()
Then I should see "Update Nature"
   # FeatureContext::assertPageContainsText()
Then I should see "nice journal"
   # FeatureContext::assertPageContainsText()
Then I should see "1qazxsw2"
   # FeatureContext::assertPageContainsText()
Then I should see "2wsxcde3"
   # FeatureContext::assertPageContainsText()
Then I should see "www nature com"
   # FeatureContext::assertPageContainsText()
  The text "www nature com" was not found anywhere in the text of the current page.

奇怪的是,如果我进入该页面(在测试环境中),我会看到所有这些短语,包括“www nature com”。

最佳答案

当“那么我应该看到...”步骤引用输入字段中的文本时,该问题偶尔会出现。我发现为此目的有一个预定义的步骤

Then /^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/
    - Checks, that form field with specified id|name|label|value has specified value.
    # FeatureContext::assertFieldContains()

应该这样使用:

Then the "journal[name]" field should contain "nice journal"

通过此修改,Behat 可以找到所有短语。

关于yii - Behat步骤 "I should see"没有看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18599932/

相关文章:

javascript - Yii2 Active Record 在 where 子句中使用 FIND_IN_SET

yii-user 扩展 - 如何添加复选框配置文件字段?

php - 使用我们的自定义类扩展 Yii 框架 CHtml 帮助器类

php - MySQL 混淆查询

selenium - 无法使用 Selenium 3.5.x 通过 Behat/Mink 查找页面元素

php - 格式错误的字段路径 ""(InvalidArgumentException)

php - Yii 2.0 $request->post() 问题

来自命令行的 Behat "base_url"

php - Behat Mink webdriver session 在套件中的每个功能之后被销毁

php - 在特质中表现上下文