Fix add function for selecting a value in the new tree dropdown in behat using react

This commit is contained in:
Christopher Joe 2017-07-28 11:59:24 +12:00
parent 697798b464
commit 4e222fc189

View File

@ -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
@ -254,7 +256,32 @@ JS;
$siteConfig->write();
$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 = $page->find('css', $selector);
assertNotNull($parentElement, sprintf('"%s" element not found', $selector));
$dropdown = $parentElement->find('css', '.Select');
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
*