Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
[Behat] Remove xPath Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Jacinto committed Jun 27, 2016
1 parent f204c59 commit e36e132
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions Features/Context/SubContext/BrowserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,11 @@
*/
namespace EzSystems\PlatformUIBundle\Features\Context\SubContext;

use EzSystems\BehatBundle\Helper\EzAssertion;
use EzSystems\PlatformUIBundle\Features\Context\PlatformUI;
use EzSystems\PlatformBehatBundle\Helper\Xpath;

class BrowserContext extends PlatformUI
{
/**
* @var \EzSystems\BehatBundle\Helper\Xpath
*/
private $xpath;

/**
* @BeforeScenario
*/
public function prepareHelpers()
{
// initialize Helpers
$this->xpath = new Xpath($this->getSession());
}

/**
* Getter for Xpath.
*
* @return \EzSystems\BehatBundle\Helper\Xpath
*/
public function getXpath()
{
return $this->xpath;
}

/**
* @Given I clicked on/at (the) :link link
* @When I click on/at (the) :link link
Expand Down Expand Up @@ -143,18 +118,17 @@ public function seeInputField($label)
*/
public function checkOption($option)
{
$fieldElements = $this->getXpath()->findFields($option);
EzAssertion::assertElementFound($option, $fieldElements, null, 'checkbox');

// this is needed for the cases where are checkboxes and radio's
// side by side, for main option the radio and the extra being the
// checkboxes values
if (strtolower($fieldElements[0]->getAttribute('type')) !== 'checkbox') {
$value = $fieldElements[0]->getAttribute('value');
$fieldElements = $this->getXpath()->findXpath("//input[@type='checkbox' and @value='$value']");
EzAssertion::assertElementFound($value, $fieldElements, null, 'checkbox');
}

$fieldElements[0]->check();
$session = $this->getSession();
$selectorsHandler = $session->getSelectorsHandler();
$literal = $selectorsHandler->xpathLiteral($option);

// To be able to work on mink 1.6 (ezplatform) & mink 1.5 (5.4+ezpublish-community) w/o deprecation exceptions
$selector = $selectorsHandler->isSelectorRegistered('named_partial') ?
$selectorsHandler->getSelector('named_partial') :
$selectorsHandler->getSelector('named');
$xpath = $selector->translateToXPath(array('field', $literal));

$fieldElement = $session->getPage()->find('xpath', $xpath);
$fieldElement->check();
}
}

0 comments on commit e36e132

Please sign in to comment.