Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Fixed
- Accept array as possible input to `sendKeys()` method. (Unintentional BC break in 1.8.0.)
- Use relative offset when moving mouse pointer in W3C WebDriver mode.

## 1.8.0 - 2020-02-10
### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/Interactions/WebDriverActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function keyUp(WebDriverElement $element = null, $key = null)

/**
* Send keys by keyboard.
* If $element is provided, focus on that element first.
* If $element is provided, focus on that element first (using single mouse click).
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
* @param WebDriverElement $element
Expand Down
33 changes: 18 additions & 15 deletions lib/Remote/RemoteMouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
*/
class RemoteMouse implements WebDriverMouse
{
/** @internal */
const BUTTON_LEFT = 0;
/** @internal */
const BUTTON_MIDDLE = 1;
/** @internal */
const BUTTON_RIGHT = 2;

/**
* @var RemoteExecuteMethod
*/
Expand Down Expand Up @@ -54,7 +61,7 @@ public function click(WebDriverCoordinates $where = null)

$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::CLICK, [
'button' => 0,
'button' => self::BUTTON_LEFT,
]);

return $this;
Expand All @@ -78,13 +85,11 @@ public function contextClick(WebDriverCoordinates $where = null)
'actions' => array_merge($moveAction, [
[
'type' => 'pointerDown',
'duration' => 0,
'button' => 2,
'button' => self::BUTTON_RIGHT,
],
[
'type' => 'pointerUp',
'duration' => 0,
'button' => 2,
'button' => self::BUTTON_RIGHT,
],
]),
],
Expand All @@ -96,7 +101,7 @@ public function contextClick(WebDriverCoordinates $where = null)

$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::CLICK, [
'button' => 2,
'button' => self::BUTTON_RIGHT,
]);

return $this;
Expand Down Expand Up @@ -150,8 +155,7 @@ public function mouseDown(WebDriverCoordinates $where = null)
$this->createMoveAction($where),
[
'type' => 'pointerDown',
'duration' => 0,
'button' => 0,
'button' => self::BUTTON_LEFT,
],
],
],
Expand Down Expand Up @@ -229,8 +233,7 @@ public function mouseUp(WebDriverCoordinates $where = null)
'actions' => array_merge($moveAction, [
[
'type' => 'pointerUp',
'duration' => 0,
'button' => 0,
'button' => self::BUTTON_LEFT,
],
]),
],
Expand Down Expand Up @@ -270,13 +273,15 @@ private function createMoveAction(
) {
$move_action = [
'type' => 'pointerMove',
'duration' => 0,
'duration' => 100, // to simulate human delay
'x' => $x_offset === null ? 0 : $x_offset,
'y' => $y_offset === null ? 0 : $y_offset,
];

if ($where !== null) {
$move_action['origin'] = [JsonWireCompat::WEB_DRIVER_ELEMENT_IDENTIFIER => $where->getAuxiliary()];
} else {
$move_action['origin'] = 'pointer';
}

return $move_action;
Expand All @@ -290,13 +295,11 @@ private function createClickActions()
return [
[
'type' => 'pointerDown',
'duration' => 0,
'button' => 0,
'button' => self::BUTTON_LEFT,
],
[
'type' => 'pointerUp',
'duration' => 0,
'button' => 0,
'button' => self::BUTTON_LEFT,
],
];
}
Expand Down
16 changes: 4 additions & 12 deletions tests/functional/RemoteKeyboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class RemoteKeyboardTest extends WebDriverTestCase
{
use RetrieveEventsTrait;

/**
* @group exclude-firefox
* Firefox does not properly support keyboard actions:
Expand Down Expand Up @@ -55,7 +57,7 @@ public function testShouldPressSendAndReleaseKeys()
'keyup "Shift"',
'keyup "f"',
],
$this->retrieveLoggedEvents()
$this->retrieveLoggedKeyboardEvents()
);
} else {
$this->assertEquals(
Expand All @@ -79,18 +81,8 @@ public function testShouldPressSendAndReleaseKeys()
'keydown "f"',
'keyup "f"',
],
$this->retrieveLoggedEvents()
$this->retrieveLoggedKeyboardEvents()
);
}
}

/**
* @return array
*/
private function retrieveLoggedEvents()
{
$logElement = $this->driver->findElement(WebDriverBy::id('keyboardEventsLog'));

return explode("\n", $logElement->getText());
}
}
31 changes: 31 additions & 0 deletions tests/functional/RetrieveEventsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Facebook\WebDriver;

use Facebook\WebDriver\Remote\RemoteWebDriver;

trait RetrieveEventsTrait
{
/** @var RemoteWebDriver $driver */
public $driver;

/**
* @return array
*/
private function retrieveLoggedKeyboardEvents()
{
$logElement = $this->driver->findElement(WebDriverBy::id('keyboardEventsLog'));

return explode("\n", $logElement->getText());
}

/**
* @return array
*/
private function retrieveLoggedMouseEvents()
{
$logElement = $this->driver->findElement(WebDriverBy::id('mouseEventsLog'));

return explode("\n", $logElement->getText());
}
}
Loading