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

ISAICP-4633 #1301

Merged
merged 5 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 46 additions & 2 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Exception\ResponseTextException;
use Drupal\Component\Serialization\Yaml;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Drupal\joinup\HtmlManipulator;
use Drupal\joinup\KeyboardEventKeyCodes as Key;
use Drupal\joinup\KeyboardEventKeyCodes as BrowserKey;
use Drupal\joinup\Traits\BrowserCapabilityDetectionTrait;
use Drupal\joinup\Traits\ContextualLinksTrait;
use Drupal\joinup\Traits\EntityTrait;
use Drupal\joinup\Traits\TraversingTrait;
use Drupal\joinup\Traits\UserTrait;
use Drupal\joinup\Traits\UtilityTrait;
use LoversOfBehat\TableExtension\Hook\Scope\AfterTableFetchScope;
use WebDriver\Exception;
use WebDriver\Key;

/**
* Defines generic step definitions.
Expand Down Expand Up @@ -656,7 +659,7 @@ public function moveSlider($label, $direction) {
if (!in_array($direction, ['left', 'right'])) {
throw new \Exception("The direction $direction is currently not supported. Use either 'left' or 'right'.");
}
$key = $direction === 'left' ? Key::LEFT_ARROW : Key::RIGHT_ARROW;
$key = $direction === 'left' ? BrowserKey::LEFT_ARROW : BrowserKey::RIGHT_ARROW;

// Locate the slider starting from the label:
// - Find the label with the given label text.
Expand Down Expand Up @@ -1233,4 +1236,45 @@ public static function stripScreenReaderElements(AfterTableFetchScope $scope) {
$scope->setHtml($html_manipulator->removeElements('.visually-hidden')->html());
}

/**
* Fills in the autocomplete field with the given text.
*
* This differs from MinkContext::fillField() in that this will no remove the
* focus on the field after entering the text, so that the autocomplete
* results will not disappear. The final action taken on the field will be the
* "keyup" event for the last character.
*
* @param string $field
* The ID, name, label or value of the autocomplete field to fill in.
* @param string $value
* The text to type in the autocomplete field.
*
* @When I type :value in the :field autocomplete field
*/
public function fillAutoCompleteField(string $field, string $value): void {
$this->assertJavaScriptEnabledBrowser();

$driver = $this->getSession()->getDriver();
if (!$driver instanceof Selenium2Driver) {
throw new \RuntimeException("Only Selenium is currently supported for typing in autocomplete fields.");
}

$xpath = $this->getSession()->getSelectorsHandler()->selectorToXpath('named', ['field', $field]);
try {
$element = $driver->getWebDriverSession()->element('xpath', $xpath);
}
catch (Exception $e) {
throw new \RuntimeException("Field with locator '$field' was not found in the page.");
}

// Clear any existing data in the field before typing the new data.
$value = str_repeat(Key::BACKSPACE . Key::DELETE, strlen($element->attribute('value'))) . $value;

// Fill in the field by directly using the postValue() method of the
// webdriver. This executes the keystrokes that make up the text but will
// not remove focus from the field so the autocomplete results remain
// visible and can be inspected.
$element->postValue(['value' => [$value]]);
}

}
10 changes: 5 additions & 5 deletions tests/features/joinup_discussion/discussion.invite.feature
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,35 @@ Feature: Invite members to subscribe to discussions
Then I should see the error message "Please add at least one user."

# Try to filter by first name.
When I fill in "E-mail" with "sha"
When I type "sha" in the "E-mail" autocomplete field
Then I wait until the page contains the text "Shaquila Paternoster (paternoster)"
And I should see the text "Shannon Hargrave (theacuteone)"
But I should not see the text "Lynwood Crawford (Lynwood Crawford)"
And I should not see the text "Glory Ruskin (Glory Ruskin)"

## Try to filter by last name.
When I fill in "E-mail" with "raw"
When I type "raw" in the "E-mail" autocomplete field
Then I wait until the page contains the text "Lynwood Crawford (Lynwood Crawford)"
But I should not see the text "Shaquila Paternoster (paternoster)"
And I should not see the text "Shannon Hargrave (theacuteone)"
And I should not see the text "Glory Ruskin (Glory Ruskin)"

## Try to filter by e-mail address.
When I fill in "E-mail" with "hr"
When I type "hr" in the "E-mail" autocomplete field
Then I wait until the page contains the text "Glory Ruskin (Glory Ruskin)"
And I should see the text "Shannon Hargrave (theacuteone)"
But I should not see the text "Lynwood Crawford (Lynwood Crawford)"
And I should not see the text "Shaquila Paternoster (paternoster)"

## Try fo filter by username.
When I fill in "E-mail" with "acute"
When I type "acute" in the "E-mail" autocomplete field
Then I wait until the page contains the text "Shannon Hargrave (theacuteone)"
But I should see the text "Glory Ruskin (Glory Ruskin)"
And I should not see the text "Lynwood Crawford (Lynwood Crawford)"
And I should not see the text "Shaquila Paternoster (paternoster)"

## Try to filter on a combination of first name and last name.
When I fill in "E-mail" with "or"
When I type "or" in the "E-mail" autocomplete field
Then I wait until the page contains the text "Lynwood Crawford (Lynwood Crawford)"
And I should see the text "Glory Ruskin (Glory Ruskin)"
But I should not see the text "Shannon Hargrave (theacuteone)"
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Traits/UtilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function explodeCommaSeparatedStepArgument($argument) {
/**
* Checks that we are running on a JavaScript-enabled browser.
*
* @throws \Behat\Mink\Exception\UnsupportedDriverActionException
* @throws \RuntimeException
* Thrown when not running on a JS-enabled browser.
*/
protected function assertJavaScriptEnabledBrowser() {
Expand All @@ -41,7 +41,7 @@ protected function assertJavaScriptEnabledBrowser() {
}
catch (UnsupportedDriverActionException $e) {
// Show a helpful error message.
throw new UnsupportedDriverActionException('This test needs to run on a real browser like Selenium or PhantomJS. Please add the "@javascript" tag to the scenario.', $driver);
throw new \RuntimeException('This test needs to run on a real browser using Selenium or similar. Please add the "@javascript" tag to the scenario.', $driver);
}
}

Expand Down