Skip to content

Commit

Permalink
Merge pull request #183 from aik099/151-use-css-selector-directly-in-…
Browse files Browse the repository at this point in the history
…selenium-selector

Use "CssSelector" directly in "SeleniumSelector"
  • Loading branch information
Alexander Obuhovich committed Jun 24, 2016
2 parents 19d35e6 + eafa040 commit a65fbbf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion library/QATools/QATools/PageObject/PageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function setSession(Session $session)
$selectors_handler = $session->getSelectorsHandler();

if ( !$selectors_handler->isSelectorRegistered('se') ) {
$selectors_handler->registerSelector('se', new SeleniumSelector($selectors_handler));
$selectors_handler->registerSelector('se', new SeleniumSelector());
}

$this->_session = $session;
Expand Down
16 changes: 7 additions & 9 deletions library/QATools/QATools/PageObject/SeleniumSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace QATools\QATools\PageObject;


use Behat\Mink\Selector\CssSelector;
use Behat\Mink\Selector\SelectorInterface;
use Behat\Mink\Selector\SelectorsHandler;
use Behat\Mink\Selector\Xpath\Escaper;
use QATools\QATools\PageObject\Exception\ElementException;

Expand All @@ -27,11 +27,11 @@ class SeleniumSelector implements SelectorInterface
{

/**
* Reference to selectors handler, where this selector was registered.
* Reference to CSS selector.
*
* @var SelectorsHandler
* @var CssSelector
*/
private $_handler;
private $_cssSelector;

/**
* The XPath escaper.
Expand All @@ -42,12 +42,10 @@ class SeleniumSelector implements SelectorInterface

/**
* Creates instance of SeleniumSelector class.
*
* @param SelectorsHandler $selectors_handler Mink selectors handler.
*/
public function __construct(SelectorsHandler $selectors_handler)
public function __construct()
{
$this->_handler = $selectors_handler;
$this->_cssSelector = new CssSelector();
$this->_xpathEscaper = new Escaper();
}

Expand Down Expand Up @@ -77,7 +75,7 @@ public function translateToXPath($locator)
return "descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), " . $locator . ')]';
}
elseif ( $selector == How::CSS ) {
return $this->_handler->selectorToXpath('css', $locator);
return $this->_cssSelector->translateToXPath($locator);
}
elseif ( $selector == How::ID ) {
return 'descendant-or-self::*[@id = ' . $this->_xpathEscaper->escapeLiteral($locator) . ']';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function setUp()
*/
protected function createElement(array $selector)
{
$selenium_selector = new SeleniumSelector(new SelectorsHandler());
$selenium_selector = new SeleniumSelector();
$xpath = $selenium_selector->translateToXPath($selector);

$web_element = new WebElement(new NodeElement($xpath, $this->session));
Expand Down
4 changes: 1 addition & 3 deletions tests/QATools/QATools/PageObject/SeleniumSelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class SeleniumSelectorTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$selectors_handler = new SelectorsHandler();

$this->selector = new SeleniumSelector($selectors_handler);
$this->selector = new SeleniumSelector();
}

/**
Expand Down

0 comments on commit a65fbbf

Please sign in to comment.