TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
PageTree.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Acceptance\Support\Page;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 use Facebook\WebDriver\Remote\RemoteWebElement;
19 use Facebook\WebDriver\WebDriverBy;
20 
24 class PageTree
25 {
26  // Selectors
27  public static $pageTreeFrameSelector = '#typo3-pagetree';
28  public static $pageTreeSelector = '#typo3-pagetree-treeContainer';
29  public static $treeItemSelector = '.x-tree-node-ct > .x-tree-node';
30  public static $treeItemAnchorSelector = '.x-tree-node-anchor';
31 
35  protected $tester;
36 
40  public function __construct(\AcceptanceTester $I)
41  {
42  $this->tester = $I;
43  }
44 
56  public function openPath(array $path)
57  {
58  $context = $this->getPageTreeElement();
59  foreach ($path as $pageName) {
60  $context = $this->ensureTreeNodeIsOpen($pageName, $context);
61  }
62  $context->findElement(\WebDriverBy::cssSelector(self::$treeItemAnchorSelector))->click();
63  }
64 
70  public function getPageTreeElement()
71  {
72  $I = $this->tester;
73  $I->switchToIFrame();
74  return $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
75  return $webdriver->findElement(\WebDriverBy::cssSelector(self::$pageTreeSelector));
76  });
77  }
78 
86  protected function ensureTreeNodeIsOpen(string $nodeText, RemoteWebElement $context)
87  {
88  $I = $this->tester;
89  $I->see($nodeText, self::$treeItemSelector);
90 
92  $context = $I->executeInSelenium(function () use ($nodeText, $context
93  ) {
94  return $context->findElement(\WebDriverBy::linkText($nodeText))->findElement(
95  WebDriverBy::xpath('ancestor::li[@class="x-tree-node"][1]')
96  );
97  });
98 
99  try {
100  $context->findElement(\WebDriverBy::cssSelector('.x-tree-elbow-end-plus'))->click();
101  } catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) {
102  // element not found so it may be already opened...
103  }
104 
105  return $context;
106  }
107 }