Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

If you want to verify selectbox options then you can use example below.


Selectbox


<select id="my-select-box">
<option value=""></option>
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
</select>

Gherkin


Feature: Dummy feature

Scenario: Selectbox will contain specific set of data
Given I am "/home"
And the selectbox "my-select-box" should have a list containing:
"""
11
22
33
"""

FeatureContext


class FeatureContext extends MinkContext implements KernelAwareContext
{
...
...

/**
* @Then /^the selectbox "([^"]*)" should have a list containing:$/
*/
public function shouldHaveAListContaining($element, PyStringNode $list)
{
$session = $this->getSession();
$page = $session->getPage();
$element = $page->findById($element);
if (is_null($element)) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS for "%s".', $element));
}

if ($element->getText() != implode('', $list->getStrings())) {
throw new \Exception(sprintf('Element "%s" content mismatch.', $element));
}
}

...
...
}