diff --git a/src/Context/BasicContext.php b/src/Context/BasicContext.php index 061a5f9..640f99e 100644 --- a/src/Context/BasicContext.php +++ b/src/Context/BasicContext.php @@ -1280,7 +1280,6 @@ JS; )); } - /** * We have to catch exceptions and log somehow else otherwise behat falls over * @@ -1290,4 +1289,38 @@ JS; { file_put_contents('php://stderr', 'Exception caught: ' . $exception->getMessage()); } + + /** + * Detect element with javascript, rather than having the selector converted to xpath + * There's already an xpath based function 'I see the "" element' iSeeTheElement() in silverstripe/cms + * There's also an 'I should see "" element' in MinkContext which also converts the css selector to xpath + * + * @When /^I should see the "([^"]+)" element/ + * @param $selector + */ + public function iShouldSeeTheElement($selector) + { + $sel = str_replace('"', '\\"', $selector); + $js = <<getSession()->evaluateScript($js); + assertNotNull($element, sprintf('Element %s not found', $selector)); + } + + /** + * Selects the option in select field with specified id|name|label|value. + * Note: this is duplicate code from SilverStripeContext selectOption + * In practice, the primary context file using in modules have inherited from BasicContext + * and not SilverStripeContext so the selectOption method is not available. + * + * @When /^I select "([^"]+)" from the "([^"]+)" field$/ + * @param string $value + * @param string $locator - select id, name or label - NOT a css selector + */ + public function iSelectFromTheField($value, $locator) + { + $val = str_replace('"', '\\"', $value); + $this->getSession()->getPage()->selectFieldOption($locator, $val); + } }