‪TYPO3CMS  11.5
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 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  (new WebDriverCompositeAction())
79  ->addAction(
80  new WebDriverClickAndHoldAction($this->‪getMouse(), $this->‪findElement($source))
81  )
82  ->addAction(
83  new WebDriverMouseMoveAction($this->‪getMouse(), $this->‪findElement($target))
84  )
85  ->perform();
86  if ($release) {
87  $this->‪release();
88  }
89  }
90 
94  public function ‪release(): void
95  {
96  $action = new WebDriverButtonReleaseAction($this->‪getMouse());
97  $action->perform();
98  }
99 
100  protected function ‪findElement(string $selector): RemoteWebElement
101  {
102  $I = ‪$this->tester;
103  try {
104  $I->wait(0.5);
105  return $I->executeInSelenium(static function (RemoteWebDriver $webDriver) use ($selector) {
106  return $webDriver->findElement(WebDriverBy::cssSelector($selector));
107  });
108  } catch (InvalidSelectorException $exception) {
109  return $I->executeInSelenium(static function (RemoteWebDriver $webDriver) use ($selector) {
110  return $webDriver->findElement(WebDriverBy::xpath($selector));
111  });
112  }
113  }
114 
115  protected function ‪getMouse(): WebDriverMouse
116  {
117  $I = ‪$this->tester;
118  return $I->executeInSelenium(static function (RemoteWebDriver $webDriver) {
119  return $webDriver->getMouse();
120  });
121  }
122 }
‪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:27
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\findElement
‪findElement(string $selector)
Definition: Mouse.php:100
‪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:94
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper
Definition: Config.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\getMouse
‪getMouse()
Definition: Mouse.php:115