diff --git a/tests/behat/src/CmsFormsContext.php b/tests/behat/src/CmsFormsContext.php index b5dad7d62..68477e7a2 100644 --- a/tests/behat/src/CmsFormsContext.php +++ b/tests/behat/src/CmsFormsContext.php @@ -7,6 +7,7 @@ use Behat\Behat\Context\Context; use Behat\Mink\Exception\ElementHtmlException; use Behat\Gherkin\Node\TableNode; use SilverStripe\BehatExtension\Context\MainContextAwareTrait; +use SilverStripe\BehatExtension\Utility\StepHelper; use Symfony\Component\DomCrawler\Crawler; use Behat\Mink\Element\NodeElement; use SilverStripe\SiteConfig\SiteConfig; @@ -19,6 +20,7 @@ use SilverStripe\SiteConfig\SiteConfig; class CmsFormsContext implements Context { use MainContextAwareTrait; + use StepHelper; /** * Get Mink session from MinkContext @@ -255,6 +257,36 @@ JS; $siteConfig->flushCache(); } + /** + * Select a value in the tree dropdown field + * + * NOTE: This is react specific, may need to move to its own react section later + * + * @When /^I select "([^"]*)" in the "([^"]*)" tree dropdown$/ + */ + public function iSelectValueInTreeDropdown($text, $selector) + { + $page = $this->getSession()->getPage(); + $parentElement = null; + $this->retryThrowable(function () use (&$parentElement, &$page, $selector) { + $parentElement = $page->find('css', $selector); + assertNotNull($parentElement, sprintf('"%s" element not found', $selector)); + $page = $this->getSession()->getPage(); + }); + + $this->retryThrowable(function () use ($parentElement, $selector) { + $dropdown = $parentElement->find('css', '.Select-arrow'); + assertNotNull($dropdown, sprintf('Unable to find the dropdown in "%s"', $selector)); + $dropdown->click(); + }); + + $this->retryThrowable(function () use ($text, $parentElement, $selector) { + $element = $parentElement->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); + assertNotNull($element, sprintf('"%s" not found in "%s"', $text, $selector)); + $element->click(); + }); + } + /** * Locate an HTML editor field *