Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
Added component hover action. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk authored Oct 6, 2017
1 parent abb2c9c commit de988dc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 2 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ default:
'off-canvas bottom': "#off-canvas-bottom"
'sr only': "#sr-only"
'sr only shown': "#sr-only-shown"
'hover': "#hover"
'hover content': "#hover-content"
'overlay': "#overlay"
'overlay trigger': "#overlay-trigger"
'off-canvas overlay': "#overlay-off-canvas"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function assertFocused($subject)
*
* @javascript
*/
public function assertClick($subjects)
public function iClickComponents($subjects)
{
$subjects = $this->parseComponents($subjects);

Expand All @@ -148,7 +148,7 @@ public function assertClick($subjects)
$errors = [];
foreach ($subjects as $subject) {
if (!$this->componentIsVisible($this->components[$subject])) {
$errors[] = sprintf("Unable to click on invisible component '%s' (%s)", $subject, $this->components[$subject]);
$errors[] = sprintf("Unable to click on an invisible component '%s' (%s)", $subject, $this->components[$subject]);
continue;
}

Expand All @@ -167,6 +167,45 @@ public function assertClick($subjects)
}
}

/**
* Hover the mouse over one or multiple elements.
*
* @param string $subjects Subjects as a string.
*
* @When /^(?:|I )hover (?:over?) ([a-zA-Z0-9\s,\-]+)$/
*
* @javascript
*/
public function iHoverComponents($subjects)
{
$subjects = $this->parseComponents($subjects);

if (empty($subjects)) {
throw new \Exception('No components provided');
}

$errors = [];
foreach ($subjects as $subject) {
if (!$this->componentIsVisible($this->components[$subject])) {
$errors[] = sprintf("Unable to hover over an invisible component '%s' (%s)", $subject, $this->components[$subject]);
continue;
}

$session = $this->getSession();
$xpath = $session->getSelectorsHandler()->selectorToXpath('css', $this->components[$subject]);

try {
$this->getSession()->getDriver()->mouseOver($xpath);
} catch (\Exception $e) {
$errors[] = sprintf("Unable to hover over a component '%s' (%s): %s", $subject, $this->components[$subject], $e->getMessage());
}
}

if (count($errors) > 0) {
throw new \Exception(implode("\n", $errors));
}
}

/**
* Init values required for relativity context.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/behat/features/fixtures/relative.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@
display: block;
}
}

#hover #hover-content {
display: none;
}

#hover:hover #hover-content {
display: inline;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -426,5 +434,9 @@
<div id="over-bottom">Text for over bottom</div>
</div>

<div id="hover">
Visible hover content
<span id="hover-content">Revealed hover content</span>
</div>
</body>
</html>
9 changes: 9 additions & 0 deletions tests/behat/features/positioning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ Feature: Behat relative assertions work
Then I don't see off-canvas left, off-canvas right, off-canvas top and off-canvas bottom
And I save screenshot

@javascript @phpserver
Scenario: Assert that element can be hovered
Given I am on the test page
And I see visible hover
And I don't see hover content
When I hover over hover
Then I see visible hover content
And I save screenshot

@javascript @phpserver
Scenario: Assert that overlay is clickable when visible
Given I am on the test page
Expand Down

0 comments on commit de988dc

Please sign in to comment.