From f5957a05861524e328b0b8887a1eaf3e45419535 Mon Sep 17 00:00:00 2001 From: Sriram Venkatesh Date: Mon, 27 Jan 2014 10:02:56 +1300 Subject: [PATCH 1/2] Click first visable link --- .../Context/SilverStripeContext.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 32ed1be..7841a0f 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -312,4 +312,24 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex ); } + /** + * Overwritten to click the first *visable* link the DOM. + */ + public function clickLink($link) + { + $link = $this->fixStepArgument($link); + $links = $this->getSession()->getPage()->findAll('named', array( + 'link', $this->getSession()->getSelectorsHandler()->xpathLiteral($link) + )); + if($links) foreach($links as $l) { + if($l->isVisible()) { + $l->click(); + return; + } + } + throw new ElementNotFoundException( + $this->getSession(), 'link', 'id|name|label|value', $link + ); + } + } From 26f47d9d58208742154b4cd8ec09ede100fb9779 Mon Sep 17 00:00:00 2001 From: Sriram Venkatesh Date: Mon, 27 Jan 2014 10:50:20 +1300 Subject: [PATCH 2/2] General Coding Convention Changes --- .../Context/SilverStripeContext.php | 513 +++++++++--------- 1 file changed, 246 insertions(+), 267 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 7841a0f..6edc38a 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -3,15 +3,15 @@ namespace SilverStripe\BehatExtension\Context; use Behat\Behat\Context\Step, - Behat\Behat\Event\FeatureEvent, - Behat\Behat\Event\ScenarioEvent, - Behat\Behat\Event\SuiteEvent; + Behat\Behat\Event\FeatureEvent, + Behat\Behat\Event\ScenarioEvent, + Behat\Behat\Event\SuiteEvent; use Behat\Gherkin\Node\PyStringNode; use Behat\MinkExtension\Context\MinkContext; use Behat\Mink\Driver\GoutteDriver, - Behat\Mink\Driver\Selenium2Driver, - Behat\Mink\Exception\UnsupportedDriverActionException, - Behat\Mink\Exception\ElementNotFoundException; + Behat\Mink\Driver\Selenium2Driver, + Behat\Mink\Exception\UnsupportedDriverActionException, + Behat\Mink\Exception\ElementNotFoundException; use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface; @@ -27,309 +27,288 @@ require_once 'vendor/autoload.php'; */ class SilverStripeContext extends MinkContext implements SilverStripeAwareContextInterface { - protected $databaseName; + protected $databaseName; - /** - * @var Array Partial string match for step names - * that are considered to trigger Ajax request in the CMS, - * and hence need special timeout handling. - * @see \SilverStripe\BehatExtension\Context\BasicContext->handleAjaxBeforeStep(). - */ - protected $ajaxSteps; + /** + * @var Array Partial string match for step names + * that are considered to trigger Ajax request in the CMS, + * and hence need special timeout handling. + * @see \SilverStripe\BehatExtension\Context\BasicContext->handleAjaxBeforeStep(). + */ + protected $ajaxSteps; - /** - * @var Int Timeout in milliseconds, after which the interface assumes - * that an Ajax request has timed out, and continues with assertions. - */ - protected $ajaxTimeout; + /** + * @var Int Timeout in milliseconds, after which the interface assumes + * that an Ajax request has timed out, and continues with assertions. + */ + protected $ajaxTimeout; - /** - * @var String Relative URL to the SilverStripe admin interface. - */ - protected $adminUrl; + /** + * @var String Relative URL to the SilverStripe admin interface. + */ + protected $adminUrl; - /** - * @var String Relative URL to the SilverStripe login form. - */ - protected $loginUrl; + /** + * @var String Relative URL to the SilverStripe login form. + */ + protected $loginUrl; - /** - * @var String Relative path to a writeable folder where screenshots can be stored. - * If set to NULL, no screenshots will be stored. - */ - protected $screenshotPath; + /** + * @var String Relative path to a writeable folder where screenshots can be stored. + * If set to NULL, no screenshots will be stored. + */ + protected $screenshotPath; - protected $context; - + protected $context; + - /** - * Initializes context. - * Every scenario gets it's own context object. - * - * @param array $parameters context parameters (set them up through behat.yml) - */ - public function __construct(array $parameters) - { - // Initialize your context here - $this->context = $parameters; - } + /** + * Initializes context. + * Every scenario gets it's own context object. + * + * @param array $parameters context parameters (set them up through behat.yml) + */ + public function __construct(array $parameters) { + // Initialize your context here + $this->context = $parameters; + } - public function setDatabase($databaseName) - { - $this->databaseName = $databaseName; - } + public function setDatabase($databaseName) { + $this->databaseName = $databaseName; + } - public function setAjaxSteps($ajaxSteps) - { - if($ajaxSteps) $this->ajaxSteps = $ajaxSteps; - } + public function setAjaxSteps($ajaxSteps) { + if($ajaxSteps) $this->ajaxSteps = $ajaxSteps; + } - public function getAjaxSteps() - { - return $this->ajaxSteps; - } + public function getAjaxSteps() { + return $this->ajaxSteps; + } - public function setAjaxTimeout($ajaxTimeout) - { - $this->ajaxTimeout = $ajaxTimeout; - } + public function setAjaxTimeout($ajaxTimeout) { + $this->ajaxTimeout = $ajaxTimeout; + } - public function getAjaxTimeout() - { - return $this->ajaxTimeout; - } + public function getAjaxTimeout() { + return $this->ajaxTimeout; + } - public function setAdminUrl($adminUrl) - { - $this->adminUrl = $adminUrl; - } + public function setAdminUrl($adminUrl) { + $this->adminUrl = $adminUrl; + } - public function getAdminUrl() - { - return $this->adminUrl; - } + public function getAdminUrl() { + return $this->adminUrl; + } - public function setLoginUrl($loginUrl) - { - $this->loginUrl = $loginUrl; - } + public function setLoginUrl($loginUrl) { + $this->loginUrl = $loginUrl; + } - public function getLoginUrl() - { - return $this->loginUrl; - } + public function getLoginUrl() { + return $this->loginUrl; + } - public function setScreenshotPath($screenshotPath) - { - $this->screenshotPath = $screenshotPath; - } + public function setScreenshotPath($screenshotPath) { + $this->screenshotPath = $screenshotPath; + } - public function getScreenshotPath() - { - return $this->screenshotPath; - } + public function getScreenshotPath() { + return $this->screenshotPath; + } - /** - * @BeforeScenario - */ - public function before(ScenarioEvent $event) - { - if (!isset($this->databaseName)) { - throw new \LogicException( - 'Context\'s $databaseName has to be set when implementing ' - . 'SilverStripeAwareContextInterface.' - ); - } + /** + * @BeforeScenario + */ + public function before(ScenarioEvent $event) { + if (!isset($this->databaseName)) { + throw new \LogicException( + 'Context\'s $databaseName has to be set when implementing SilverStripeAwareContextInterface.' + ); + } - $url = $this->joinUrlParts($this->getBaseUrl(), '/dev/testsession/start'); - $url .= '?' . http_build_query($this->getTestSessionState()); - $this->getSession()->visit($url); + $url = $this->joinUrlParts($this->getBaseUrl(), '/dev/testsession/start'); + $url .= '?' . http_build_query($this->getTestSessionState()); + $this->getSession()->visit($url); - $page = $this->getSession()->getPage(); - $content = $page->getContent(); + $page = $this->getSession()->getPage(); + $content = $page->getContent(); - if(!preg_match('/