13/02/2015 - BEHAT
If the selectbox element has an ID tag then you can use code below.
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext
{
/**
* @Then /^The option "([^"]*)" should be selected in select box "([^"]*)"$/
*
* @param $elementId ID of the selectbox element.
* @param $expectedOption What option should be verified. Data needs to exploded.
* @throws \InvalidArgumentException
*/
public function getSelectedSelectboxOption($expectedOption, $elementId)
{
$session = $this->getSession();
$page = $session->getPage();
$element = $page->find('css', '#' . $elementId);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS element: "%s"', $elementId));
}
//index 0 = expected option value, index 1 = human friendly option text
$options = explode('~', $expectedOption);
$option = $element->getValue();
if ($option != $options[0]) {
throw new \InvalidArgumentException(sprintf('CSS element has different option selected'));
}
}
}