Behat:如何检查电子邮件地址输入字段是否包含域?
Behat: how to check if an email address input field contains a domain?
我正在尝试使用 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". (Behat\Mink\Exception\ElementHtmlException)
然后我尝试在 FeatureContext.php
中基于 this issue:
编写自己的检查器
/**
* @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.'.');
}
}
但是,此代码仅查找完全匹配的值,因此它不会只匹配域。
如何检查输入字段中的域(部分匹配)?
哎呀,这个问题真的只是阅读失败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.'.');
}
}
我正在尝试使用 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". (Behat\Mink\Exception\ElementHtmlException)
然后我尝试在 FeatureContext.php
中基于 this issue:
/**
* @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.'.');
}
}
但是,此代码仅查找完全匹配的值,因此它不会只匹配域。
如何检查输入字段中的域(部分匹配)?
哎呀,这个问题真的只是阅读失败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.'.');
}
}