From 7598ab592bd8f09c4c78517e811e67ce7d4da9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 3 May 2023 14:13:40 +0200 Subject: [PATCH] we still need custom driver class as the fork is tested with old FIrefox --- src/Behat/Context.php | 4 +-- src/Behat/MinkSeleniumDriver.php | 43 ++++++++++++++++++++++++++++++++ src/Behat/MinkSession.php | 10 ++++++-- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/Behat/MinkSeleniumDriver.php diff --git a/src/Behat/Context.php b/src/Behat/Context.php index 7ef0e738b4..74dd7e7661 100644 --- a/src/Behat/Context.php +++ b/src/Behat/Context.php @@ -22,9 +22,7 @@ class Context extends RawMinkContext implements BehatContext public function getSession($name = null): MinkSession { - $session = $this->getMink()->getSession($name); - - return new MinkSession($session->getDriver(), $session->getSelectorsHandler()); + return new MinkSession($this->getMink()->getSession($name)); } public function assertSession($name = null): WebAssert diff --git a/src/Behat/MinkSeleniumDriver.php b/src/Behat/MinkSeleniumDriver.php new file mode 100644 index 0000000000..c46f61c552 --- /dev/null +++ b/src/Behat/MinkSeleniumDriver.php @@ -0,0 +1,43 @@ + $v) { + $this->{$k} = $v; + } + }, $this, $class)(); + } + } + + public function getText($xpath): string + { + // HTMLElement::innerText returns rendered text as when copied to the clipboard + // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText + // https://github.com/minkphp/MinkSelenium2Driver/pull/327 + // https://github.com/minkphp/MinkSelenium2Driver/pull/328 + return $this->executeJsOnXpath($xpath, 'return {{ELEMENT}}.innerText;'); + } + + protected function mouseOverElement(WebDriverElement $element): void + { + // move the element into the viewport + // needed at least for Firefox as Selenium moveto does move the mouse cursor only + $this->executeScript('arguments[0].scrollIntoView({ behaviour: \'instant\', block: \'center\', inline: \'center\' })', [$element]); + + $this->getWebDriverSession()->moveto(['element' => $element->getID()]); + } +} diff --git a/src/Behat/MinkSession.php b/src/Behat/MinkSession.php index d7ec59abed..b838e71dbc 100644 --- a/src/Behat/MinkSession.php +++ b/src/Behat/MinkSession.php @@ -5,13 +5,19 @@ namespace Atk4\Ui\Behat; use Atk4\Core\WarnDynamicPropertyTrait; -use Behat\Mink\Driver\Selenium2Driver; class MinkSession extends \Behat\Mink\Session { use WarnDynamicPropertyTrait; - public function getDriver(): Selenium2Driver + public function __construct(\Behat\Mink\Session $session) + { + $driver = new MinkSeleniumDriver($session->getDriver()); // @phpstan-ignore-line + + parent::__construct($driver, $session->getSelectorsHandler()); + } + + public function getDriver(): MinkSeleniumDriver { return parent::getDriver(); // @phpstan-ignore-line }