‪TYPO3CMS  10.4
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 {
39  protected ‪$tester;
40 
41  public function ‪__construct(‪BackendTester $I)
42  {
43  $this->tester = $I;
44  }
45 
58  public function ‪dragAndDrop(string $source, string $target): void
59  {
60  $I = ‪$this->tester;
61  $this->‪dragTo($source, $target, false);
62  $I->canSeeElement('.node-dd');
63  $this->‪release();
64  }
65 
79  public function ‪dragTo(string $source, string $target, bool $release = true): void
80  {
81  (new WebDriverCompositeAction())
82  ->addAction(
83  new WebDriverClickAndHoldAction($this->‪getMouse(), $this->‪findElement($source))
84  )
85  ->addAction(
86  new WebDriverMouseMoveAction($this->‪getMouse(), $this->‪findElement($target))
87  )
88  ->perform();
89  if ($release) {
90  $this->‪release();
91  }
92  }
93 
97  public function ‪release(): void
98  {
99  $action = new WebDriverButtonReleaseAction($this->‪getMouse());
100  $action->perform();
101  }
102 
103  protected function ‪findElement(string $selector): RemoteWebElement
104  {
105  $I = ‪$this->tester;
106  try {
107  return $I->executeInSelenium(function (RemoteWebDriver $webDriver) use ($selector) {
108  return $webDriver->findElement(WebDriverBy::cssSelector($selector));
109  });
110  } catch (InvalidSelectorException $exception) {
111  return $I->executeInSelenium(function (RemoteWebDriver $webDriver) use ($selector) {
112  return $webDriver->findElement(WebDriverBy::xpath($selector));
113  });
114  }
115  }
116 
117  protected function ‪getMouse(): WebDriverMouse
118  {
119  $I = ‪$this->tester;
120  return $I->executeInSelenium(function (RemoteWebDriver $webDriver) {
121  return $webDriver->getMouse();
122  });
123  }
124 }
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse
Definition: Mouse.php:35
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\findElement
‪findElement(string $selector)
Definition: Mouse.php:102
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\dragAndDrop
‪dragAndDrop(string $source, string $target)
Definition: Mouse.php:57
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\$tester
‪BackendTester $tester
Definition: Mouse.php:38
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\__construct
‪__construct(BackendTester $I)
Definition: Mouse.php:40
‪TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester
Definition: BackendTester.php:27
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\dragTo
‪dragTo(string $source, string $target, bool $release=true)
Definition: Mouse.php:78
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\release
‪release()
Definition: Mouse.php:96
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper
Definition: Config.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse\getMouse
‪getMouse()
Definition: Mouse.php:116