Behat:如何检查电子邮件地址输入字段是否包含域



我正在尝试使用Behat来测试电子邮件地址输入字段是否包含某个域。

这是HTML:

<input autocomplete="off" data-drupal-selector="edit-mail" aria-describedby="edit-mail--description" type="email" id="edit-mail" name="mail" value="newemail@example.com" size="60" maxlength="254" class="form-email required form-element form-element--type-email form-element--api-email" required="required" aria-required="true">

首先,我尝试了这个:

And the "input#edit-mail" element should contain "example.com"

然而,这在以下情况下失败:

The string "example.com" was not found in the HTML of the element matching css "input#edit-mail". (BehatMinkExceptionElementHtmlException)

因此,基于这个问题,我尝试在FeatureContext.php中编写自己的检查器:

/**
* @Then the :element element should have the value :value
*/
public function iShouldSeeValueElement($element, $value) {
$page = $this->getSession()->getPage();
// Alternately, substitute with getText() for the label.
$element_value = $page->find('css', "$element")->getValue();
if ($element_value != $value) {
throw new exception('Value "'.$value.'" not found in element '.$element.'.');
}
}

但是,此代码只有在值完全匹配的情况下才能找到该值,因此它不会仅与域匹配。

如何在输入字段中只检查域(部分匹配(?

Whoops,这个问题实际上只是读取PHP失败。这是工作代码:

/**
* @Then the :element element should have the value :value
*
* https://github.com/minkphp/Mink/issues/215
*/
public function iShouldSeeValueElement($element, $value) {
$page = $this->getSession()->getPage();
// Alternately, substitute with getText() for the label.
$element_value = $page->find('css', "$element")->getValue();
if (strpos("$element_value", "$value") === false) {
throw new exception('Value '.$value.' not found in element '.$element.', which had a value of '.$element_value.'.');
}
}

最新更新