‪TYPO3CMS  11.5
PageTree.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\Remote\RemoteWebDriver;
21 use Facebook\WebDriver\Remote\RemoteWebElement;
22 use Facebook\WebDriver\WebDriverBy;
23 use Facebook\WebDriver\WebDriverKeys;
25 use TYPO3\TestingFramework\Core\Acceptance\Helper\AbstractPageTree;
26 
30 class ‪PageTree extends AbstractPageTree
31 {
33 
40  {
41  $this->tester = $I;
42  $this->mouse = ‪$mouse;
43  }
44 
48  public function ‪waitForNodes(): void
49  {
50  $this->tester->waitForElement(static::$pageTreeSelector . ' ' . static::$treeItemSelector, 5);
51  }
52 
53  public function ‪closeSecondLevelPaths(): void
54  {
55  $context = $this->getPageTreeElement();
56 
57  $this->‪waitForNodes();
58 
59  // Collapse all opened paths (might be opened due to localstorage)
60  do {
61  $toggled = false;
62  try {
63  // collapse last opened node element, that is not the root (=first node)
64  $context->findElement(\Facebook\WebDriver\WebDriverBy::xpath('(.//*[position()>1 and @role="treeitem" and count(*/*[@class="chevron expanded"]) > 0])[last()]/*[@class="toggle"]'))->click();
65  $toggled = true;
66  } catch (\Facebook\WebDriver\‪Exception\NoSuchElementException $e) {
67  // element not found so it may be already opened...
68  } catch (\Facebook\WebDriver\‪Exception\ElementNotVisibleException $e) {
69  // element not found so it may be already opened...
70  } catch (\Facebook\WebDriver\‪Exception\ElementNotInteractableException $e) {
71  // another possible exception if the chevron isn't there ... depends on facebook driver version
72  }
73  } while ($toggled);
74  }
75 
76  public function ‪openPath(array $path): void
77  {
78  $this->‪closeSecondLevelPaths();
79  parent::openPath($path);
80 
81  // pagetree has 300ms timeout for double click detection, wait 350ms to wait for the click to have happened
82  $this->tester->wait(0.35);
83  }
84 
92  protected function ‪ensureTreeNodeIsOpen(string $nodeText, RemoteWebElement $context)
93  {
94  $I = $this->tester;
95  $I->see($nodeText, self::$treeItemSelector);
96 
98  $context = $I->executeInSelenium(function () use (
99  $nodeText,
100  $context
101  ) {
102  return $context->findElement(\Facebook\WebDriver\WebDriverBy::xpath('//*[text()=\'' . $nodeText . '\']/..'));
103  });
104 
105  try {
106  if ($context->getAttribute('aria-expanded') === 'false') {
107  $context->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('.toggle[visibility="visible"]'))->click();
108  }
109  } catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) {
110  // element not found so it may be already opened...
111  } catch (\Facebook\WebDriver\Exception\ElementNotVisibleException $e) {
112  // element not found so it may be already opened...
113  } catch (\Facebook\WebDriver\Exception\ElementNotInteractableException $e) {
114  // another possible exception if the chevron isn't there ... depends on facebook driver version
115  }
116 
117  return $context;
118  }
119 
123  public function ‪dragAndDropNewPage(string $pageName, string $dragNode, string $nodeEditInput): void
124  {
125  $target = $this->‪getPageXPathByPageName($pageName);
126  $pageTitle = sprintf('Dummy 1-%s-new', $pageName);
127 
128  $this->mouse->dragAndDrop($dragNode, $target);
129 
130  $this->tester->seeElement($nodeEditInput);
131 
132  // Change the new page title.
133  // We can't use $I->fillField() here since this sends a clear() to the element
134  // which drops the node creation in the tree. So we do it manually with selenium.
135  $element = $this->tester->executeInSelenium(static function (RemoteWebDriver $webdriver) use ($nodeEditInput) {
136  return $webdriver->findElement(WebDriverBy::cssSelector($nodeEditInput));
137  });
138  $element->sendKeys($pageTitle);
139 
140  $this->tester->pressKey($nodeEditInput, WebDriverKeys::ENTER);
141  $this->tester->waitForElementNotVisible($nodeEditInput);
142  $this->tester->see($pageTitle);
143  }
144 
151  public function ‪getPageXPathByPageName(string $pageName): string
152  {
153  return '//*[text()=\'' . $pageName . '\']';
154  }
155 }
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\ensureTreeNodeIsOpen
‪RemoteWebElement ensureTreeNodeIsOpen(string $nodeText, RemoteWebElement $context)
Definition: PageTree.php:92
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Mouse
Definition: Mouse.php:35
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:27
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\openPath
‪openPath(array $path)
Definition: PageTree.php:76
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\__construct
‪__construct(ApplicationTester $I, Mouse $mouse)
Definition: PageTree.php:39
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\waitForNodes
‪waitForNodes()
Definition: PageTree.php:48
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\dragAndDropNewPage
‪dragAndDropNewPage(string $pageName, string $dragNode, string $nodeEditInput)
Definition: PageTree.php:123
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\closeSecondLevelPaths
‪closeSecondLevelPaths()
Definition: PageTree.php:53
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper
Definition: Config.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\$mouse
‪Mouse $mouse
Definition: PageTree.php:32
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\getPageXPathByPageName
‪string getPageXPathByPageName(string $pageName)
Definition: PageTree.php:151