Mink 提供了一个测试复选框的步骤:
the "form_checkbox" checkbox should be checked
Run Code Online (Sandbox Code Playgroud)
但是对于单选按钮,您需要编写自己的步骤。就像是 :
/**
* @Then /^Radio button with id "([^"]*)" should be checked$/
*/
public function RadioButtonWithIdShouldBeChecked($sId)
{
$elementByCss = $this->getSession()->getPage()->find('css', 'input[type="radio"]:checked#'.$sId);
if (!$elementByCss) {
throw new Exception('Radio button with id ' . $sId.' is not checked');
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 find() 方法通过 CSS 选择器来定位元素。在这里,我们搜索一个被选中并具有给定 id 的单选按钮。