问题
Using Behat in Yii framework, I am observing its quite strange behaviour: Behat does not find some text when using steps like
Then I should see "some text"
Some text it finds normaly, but some - not. To be sure that I am on the page I think I am on, I've added sort of markers in the view files and Behat sees them.
So, the scenario is
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"
The output is then
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.
The strange is that if I go to the page (in test environment), I see all those phrases including "www nature com".
回答1:
The problem sporadically appears when the step "Then I should see ..." refers to the text in an input field. I've found out that for this purpose there is a predefined step
Then /^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/
- Checks, that form field with specified id|name|label|value has specified value.
# FeatureContext::assertFieldContains()
which is supposed to be used like this:
Then the "journal[name]" field should contain "nice journal"
With this modification, Behat finds all phrases.
来源:https://stackoverflow.com/questions/18599932/behat-step-i-should-see-does-not-see