‪TYPO3CMS  ‪main
Mouse.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Facebook\WebDriver\Exception\InvalidSelectorException;
21 use Facebook\WebDriver\Interactions\Internal\WebDriverButtonReleaseAction;
22 use Facebook\WebDriver\Interactions\Internal\WebDriverClickAndHoldAction;
23 use Facebook\WebDriver\Interactions\Internal\WebDriverMouseMoveAction;
24 use Facebook\WebDriver\Interactions\WebDriverCompositeAction;
25 use Facebook\WebDriver\Remote\RemoteWebDriver;
26 use Facebook\WebDriver\Remote\RemoteWebElement;
27 use Facebook\WebDriver\WebDriverBy;
28 use Facebook\WebDriver\WebDriverMouse;
30 
34 final class ‪Mouse
35 {
37 
39  {
40  $this->tester = $I;
41  }
42 
55  public function ‪dragAndDrop(string $source, string $target): void
56  {
57  $I = ‪$this->tester;
58  $this->‪dragTo($source, $target, false);
59  $I->canSeeElement('.node-dd');
60  $this->‪release();
61  }
62 
76  public function ‪dragTo(string $source, string $target, bool $release = true): void
77  {
78  // webdriver does not support native HTML draggable
79  // (all utility methods do only emulate DOM mouse events instead
80  // of *real* browser mouse movements, that is why no drag* events
81  // will ever be generated. This issue is only properly fixable by
82  // ditching webdriver API and use devtools API => playwright.
83  // https://github.com/w3c/webdriver/issues/1488
84  // https://bugs.chromium.org/p/chromedriver/issues/detail?id=841
85  $this->tester->markTestSkipped('selenium/chromedriver does not support native HTML draggable. (We need playwright.)');
86 
87  (new WebDriverCompositeAction())
88  ->addAction(
89  new WebDriverClickAndHoldAction($this->‪getMouse(), $this->‪findElement($source))
90  )
91  ->addAction(
92  new WebDriverMouseMoveAction($this->‪getMouse(), $this->‪findElement($target))
93  )
94  ->perform();
95  if ($release) {
96  $this->‪release();
97  }
98  }
99 
103  public function ‪release(): void
104  {
105  $action = new WebDriverButtonReleaseAction($this->‪getMouse());
106  $action->perform();
107  }
108 
109  private function ‪findElement(string $selector): RemoteWebElement
110  {
111  $I = ‪$this->tester;
112  try {
113  $I->wait(0.5);
114  return $I->executeInSelenium(static function (RemoteWebDriver $webDriver) use ($selector) {
115  return $webDriver->findElement(WebDriverBy::cssSelector($selector));
116  });
117  } catch (InvalidSelectorException $exception) {
118  return $I->executeInSelenium(static function (RemoteWebDriver $webDriver) use ($selector) {
119  return $webDriver->findElement(WebDriverBy::xpath($selector));
120  });
121  }
122  }
123 
124  private function ‪getMouse(): WebDriverMouse
125  {
126  $I = ‪$this->tester;
127  return $I->executeInSelenium(static function (RemoteWebDriver $webDriver) {
128  return $webDriver->getMouse();
129  });
130  }
131 }
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse
Definition: Mouse.php:35
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\$tester
‪ApplicationTester $tester
Definition: Mouse.php:36
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\findElement
‪findElement(string $selector)
Definition: Mouse.php:109
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\dragAndDrop
‪dragAndDrop(string $source, string $target)
Definition: Mouse.php:55
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\dragTo
‪dragTo(string $source, string $target, bool $release=true)
Definition: Mouse.php:76
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\__construct
‪__construct(ApplicationTester $I)
Definition: Mouse.php:38
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\release
‪release()
Definition: Mouse.php:103
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper
Definition: AbstractTree.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\getMouse
‪getMouse()
Definition: Mouse.php:124