Merge pull request #7221 from open-sausages/pulls/4.0/select-the-black-behat

Fix add function for selecting a value in the new tree dropdown
This commit is contained in:
Chris Joe 2017-07-28 14:27:19 +12:00 committed by GitHub
commit 1cf644c00a

View File

@ -7,6 +7,7 @@ use Behat\Behat\Context\Context;
use Behat\Mink\Exception\ElementHtmlException; use Behat\Mink\Exception\ElementHtmlException;
use Behat\Gherkin\Node\TableNode; use Behat\Gherkin\Node\TableNode;
use SilverStripe\BehatExtension\Context\MainContextAwareTrait; use SilverStripe\BehatExtension\Context\MainContextAwareTrait;
use SilverStripe\BehatExtension\Utility\StepHelper;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
@ -19,6 +20,7 @@ use SilverStripe\SiteConfig\SiteConfig;
class CmsFormsContext implements Context class CmsFormsContext implements Context
{ {
use MainContextAwareTrait; use MainContextAwareTrait;
use StepHelper;
/** /**
* Get Mink session from MinkContext * Get Mink session from MinkContext
@ -255,6 +257,36 @@ JS;
$siteConfig->flushCache(); $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 * Locate an HTML editor field
* *