From b2ff3e73ada6154614b72bfa8fca2b6b578f6354 Mon Sep 17 00:00:00 2001 From: scott1702 Date: Thu, 22 Oct 2015 16:13:47 +1300 Subject: [PATCH] Add double click action --- README.md | 2 +- .../BehatExtension/Context/BasicContext.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2d0b8aa..e006b2d 100644 --- a/README.md +++ b/README.md @@ -584,7 +584,7 @@ It's based on the `vendor/bin/behat -di @cms` output. Given /^I press the "([^"]*)" button$/ - Given /^I click "([^"]*)" in the "([^"]*)" element$/ + Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element$/ Given /^I type "([^"]*)" into the dialog$/ diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index a6ee63b..0283810 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -381,18 +381,20 @@ JS; } /** - * @Given /^I click "([^"]*)" in the "([^"]*)" element$/ + * @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element$/ */ - public function iClickInTheElement($text, $selector) { + public function iClickInTheElement($clickType, $text, $selector) { + $clickTypeMap = array( + "double click" => "doubleclick", + "click" => "click" + ); $page = $this->getSession()->getPage(); - $parentElement = $page->find('css', $selector); assertNotNull($parentElement, sprintf('"%s" element not found', $selector)); - $element = $parentElement->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); assertNotNull($element, sprintf('"%s" not found', $text)); - - $element->click(); + $clickTypeFn = $clickTypeMap[$clickType]; + $element->$clickTypeFn(); } /**