‪TYPO3CMS  10.4
AbstractElementsBasicCest.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 Codeception\Example;
21 use Facebook\WebDriver\Exception\UnknownErrorException;
22 use Facebook\WebDriver\Remote\RemoteWebDriver;
23 use Facebook\WebDriver\Remote\RemoteWebElement;
24 use Facebook\WebDriver\WebDriverKeys;
26 
31 {
39  protected function ‪runInputFieldTest(‪BackendTester $I, Example $testData)
40  {
41  $fieldLabel = $testData['label'];
42  $initializedInputFieldXpath = '(//label[contains(text(),"' . $fieldLabel . '")])'
43  . '[1]/parent::*//*/input[@data-formengine-input-name][@data-formengine-input-initialized]';
44 
45  // Wait until JS initialized everything
46  $I->waitForElement($initializedInputFieldXpath, 30);
47 
48  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
49  $inputField = $this->‪getInputField($formSection);
50  $hiddenField = $this->‪getHiddenField($formSection, $inputField);
51 
52  if ($testData['comment'] !== '') {
53  $I->comment($testData['comment']);
54  }
55 
56  $I->fillField($inputField, $testData['inputValue']);
57  // Change focus to trigger validation
58  $inputField->sendKeys(WebDriverKeys::TAB);
59  // Press ESC so that any opened popup (potentially from the field below) is closed
60  $inputField->sendKeys(WebDriverKeys::ESCAPE);
61  $I->waitForElementNotVisible('#t3js-ui-block');
62 
63  $I->comment('Test value of visible and hidden field');
64  $I->seeInField($inputField, $testData['expectedValue']);
65  $I->seeInField($hiddenField, $testData['expectedInternalValue']);
66 
67  $I->comment('Save the form');
68  $saveButtonLink = '//*/button[@name="_savedok"][1]';
69  $I->waitForElement($saveButtonLink, 30);
70  $I->click($saveButtonLink);
71  $I->waitForElementNotVisible('#t3js-ui-block');
72  $I->waitForElement('//*/button[@name="_savedok"][not(@disabled)][1]', 30);
73  $I->waitForElement($initializedInputFieldXpath, 30);
74 
75  // Find the fields again (after reload of iFrame)
76  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
77  $inputField = $this->‪getInputField($formSection);
78  $hiddenField = $this->‪getHiddenField($formSection, $inputField);
79 
80  // Validate save was successful
81  $I->comment('Test value of visible and hidden field');
82  $I->seeInField($inputField, $testData['expectedValue']);
83  $I->seeInField($hiddenField, $testData['expectedValueAfterSave']);
84  }
85 
92  protected function ‪getInputField(RemoteWebElement $formSection)
93  {
94  return $formSection->findElement(\Facebook\WebDriver\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
95  }
96 
104  protected function ‪getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
105  {
106  $hiddenFieldXPath = './/*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
107  return $formSection->findElement(\Facebook\WebDriver\WebDriverBy::xpath($hiddenFieldXPath));
108  }
109 
117  protected function ‪getFormSectionByFieldLabel(‪BackendTester $I, string $fieldLabel)
118  {
119  $I->comment('Get context for field "' . $fieldLabel . '"');
120  return $I->executeInSelenium(
121  function (RemoteWebDriver $webDriver) use ($fieldLabel) {
122  return $webDriver->findElement(
123  \Facebook\WebDriver\WebDriverBy::xpath(
124  '(//label[contains(text(),"' . $fieldLabel . '")])[1]/ancestor::fieldset[@class="form-section"][1]'
125  )
126  );
127  }
128  );
129  }
130 
136  protected function ‪ensureTopOfFrameIsUsedAndClickTab(‪BackendTester $I, string $tabTitle, string $referenceField)
137  {
138  try {
139  $I->click($tabTitle);
140  } catch (UnknownErrorException $exception) {
141  // this is fired if the element can't be clicked, because for example another element overlays it.
142  $this->‪scrollToTopOfFrame($I, $tabTitle, $referenceField);
143  }
144  }
145 
146  protected function ‪scrollToTopOfFrame(‪BackendTester $I, string $tabTitle, string $referenceField)
147  {
148  $formSection = $this->‪getFormSectionByFieldLabel($I, $referenceField);
149  $field = $this->‪getInputField($formSection);
150  $maxPageUp = 10;
151  do {
152  $doItAgain = false;
153  $maxPageUp--;
154  try {
155  $field->sendKeys(WebDriverKeys::PAGE_UP);
156  $I->click($tabTitle);
157  } catch (UnknownErrorException $exception) {
158  $doItAgain = true;
159  }
160  } while ($doItAgain === true && $maxPageUp > 0);
161  }
162 }
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\scrollToTopOfFrame
‪scrollToTopOfFrame(BackendTester $I, string $tabTitle, string $referenceField)
Definition: AbstractElementsBasicCest.php:146
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\getHiddenField
‪RemoteWebElement getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
Definition: AbstractElementsBasicCest.php:104
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\getFormSectionByFieldLabel
‪RemoteWebElement getFormSectionByFieldLabel(BackendTester $I, string $fieldLabel)
Definition: AbstractElementsBasicCest.php:117
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\runInputFieldTest
‪runInputFieldTest(BackendTester $I, Example $testData)
Definition: AbstractElementsBasicCest.php:39
‪TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester
Definition: BackendTester.php:27
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\ensureTopOfFrameIsUsedAndClickTab
‪ensureTopOfFrameIsUsedAndClickTab(BackendTester $I, string $tabTitle, string $referenceField)
Definition: AbstractElementsBasicCest.php:136
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\getInputField
‪RemoteWebElement getInputField(RemoteWebElement $formSection)
Definition: AbstractElementsBasicCest.php:92
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest
Definition: AbstractElementsBasicCest.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine
Definition: AbstractElementsBasicCest.php:18