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

Commit

Permalink
Merge pull request #535 from miguelcleverti/moveBrowserMethods
Browse files Browse the repository at this point in the history
Move browser methods into PlatformUI Context
  • Loading branch information
bdunogier committed Apr 5, 2016
2 parents 5a79c36 + 21e622b commit 5ec066c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 81 deletions.
79 changes: 0 additions & 79 deletions Features/Context/Override/CommonActions.php

This file was deleted.

2 changes: 0 additions & 2 deletions Features/Context/PlatformUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class PlatformUI extends Context
use SubContext\Authentication;
use SubContext\CommonActions;

use Override\CommonActions;

/**
* PlatformUI relative URL path.
*
Expand Down
121 changes: 121 additions & 0 deletions Features/Context/SubContext/CommonActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,129 @@
*/
namespace EzSystems\PlatformUIBundle\Features\Context\SubContext;

use EzSystems\BehatBundle\Helper\EzAssertion;

trait CommonActions
{
/**
* @Given I clicked on/at (the) :link link
* @When I click on/at (the) :link link
*
* Click a link with text ':link'
*/
public function iClickAtLink($link)
{
$this->clickElementByText($link, 'a');
}

/**
* @Given I clicked on/at (the) :button button
* @When I click on/at (the) :button button
*
* Clicks the button identified by ':button'
*/
public function iClickAtButton($button)
{
$this->clickElementByText($button, 'button');
}

/**
* @When I fill in :field with :value
* @When I set :field as empty
*
* Spin function make it possible to retry in case of failure
*/
public function fillFieldWithValue($field, $value = '')
{
$fieldNode = $this->spin(
function () use ($field) {
$fieldNode = $this->getSession()->getPage()->findField($field);
if ($fieldNode == null) {
throw new \Exception('Field not found');
}

return $fieldNode;
}
);

$this->spin(
function () use ($fieldNode, $field, $value) {
// make sure any autofocus elements don't mis-behave when setting value
$fieldNode->blur();
usleep(10 * 1000);
$fieldNode->focus();
usleep(10 * 1000);

// setting value on pre-filled inputs can cause issues, clearing before
$fieldNode->setValue('');
$fieldNode->setValue($value);

// verication that the field was really filled in correctly
$this->sleep();
$check = $this->getSession()->getPage()->findField($field)->getValue();
if ($check != $value) {
throw new \Exception('Failed to set the field value: ' . $check);
}

return true;
}
);
}

/**
* @Then I (should) see :title title/topic
*/
public function iSeeTitle($title)
{
$page = $this->getSession()->getPage();
$this->spin(
function () use ($title, $page) {
$titleElements = $page->findAll('css', 'h1, h2, h3');
foreach ($titleElements as $titleElement) {
$elementText = $titleElement->getText();
if ($elementText == $title) {
return $titleElement;
}
}
throw new \Exception("Title '$title' not found");
}
);
}

/**
* @Then I should see a :label input field
*/
public function seeInputField($label)
{
$field = $this->getSession()->getPage()->findField($label);
if (!$field) {
throw new \Exception("Field '$label' not found");
}
}

/**
* @Given I checked :label checkbox
* @When I check :label checkbox
*
* Toggles the value for the checkbox with name ':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();
}

/**
* @Given I click (on) the logo
* Clicks on the PlatformUI logo
Expand Down

0 comments on commit 5ec066c

Please sign in to comment.