我正试图在behat中编写一个函数来检查区域中元素的值。
我要编写这样的测试:
Then the "blockquote" element in the "content" region should contain "Blah blah blah"
我尝试查看 MinkContext.php 作为示例,但我不知道如何在特定区域中搜索元素。
这是检查元素的标准功能:
/**
* Checks, that element with specified CSS contains specified HTML
* Example: Then the "body" element should contain "style=\"color:black;\""
* Example: And the "body" element should contain "style=\"color:black;\""
*
* @Then /^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/
*/
public function assertElementContains($element, $value)
{
$this->assertSession()->elementContains('css', $element, $this->fixStepArgument($value));
}
这是检查区域中文本的功能:
/**
* @Then I should see( the text) :text in the :region( region)
*
* @throws \Exception
* If region or text within it cannot be found.
*/
public function assertRegionText($text, $region)
{
$regionObj = $this->getRegion($region);
// Find the text within the region
$regionText = $regionObj->getText();
if (strpos($regionText, $text) === false) {
throw new \Exception(sprintf("The text '%s' was not found in the region '%s' on the page %s", $text, $region, $this->getSession()->getCurrentUrl()));
}
}
这是我的自定义代码:
/**
* @And /^the "(?P<element>[^"]*)" element in the :region( region) should contain "(?P<value>(?:[^"]|\\")*)"$/
*
* @throws \Exception
* If region or text within it cannot be found.
*/
public function assertElementContainsRegionText($element, $region, $value) {
$regionObj = $this->getRegion($region);
// How do I search for an element in $regionObj? I tried ->find, but that didn't help...
}
}