‪TYPO3CMS  9.5
AbstractElementsBasicCest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Codeception\Example;
19 use Facebook\WebDriver\Exception\UnknownServerException;
20 use Facebook\WebDriver\Remote\RemoteWebDriver;
21 use Facebook\WebDriver\Remote\RemoteWebElement;
22 use Facebook\WebDriver\WebDriverKeys;
24 
29 {
36  protected ‪$triggerFocusChangeFieldLabel = 'input_22';
37 
45  protected function ‪runInputFieldTest(‪BackendTester $I, Example $testData)
46  {
47  $fieldLabel = $testData['label'];
48  $initializedInputFieldXpath = '(//label[contains(text(),"' . $fieldLabel . '")])'
49  . '[1]/parent::*//*/input[@data-formengine-input-name][@data-formengine-input-initialized]';
50 
51  // Wait until JS initialized everything
52  $I->waitForElement($initializedInputFieldXpath, 30);
53 
54  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
55  $inputField = $this->‪getInputField($formSection);
56  $hiddenField = $this->‪getHiddenField($formSection, $inputField);
57 
58  if ($testData['comment'] !== '') {
59  $I->comment($testData['comment']);
60  }
61 
62  $I->fillField($inputField, $testData['inputValue']);
63 
64  // force click into another field to trigger validation
65  $otherFormSection = $this->‪getFormSectionByFieldLabel($I, $this->triggerFocusChangeFieldLabel);
66  $otherInputField = $this->‪getInputField($otherFormSection);
67  $otherInputField->click();
68  // close any overlay triggered by the click
69  $otherInputField->sendKeys(WebDriverKeys::ESCAPE);
70 
71  $I->waitForElementNotVisible('#t3js-ui-block');
72 
73  $I->comment('Test value of visible and hidden field');
74  $I->seeInField($inputField, $testData['expectedValue']);
75  $I->seeInField($hiddenField, $testData['expectedInternalValue']);
76 
77  $I->comment('Save the form');
78  $saveButtonLink = '//*/button[@name="_savedok"][1]';
79  $I->waitForElement($saveButtonLink, 30);
80  $I->click($saveButtonLink);
81 
82  $I->waitForElementNotVisible('#t3js-ui-block');
83  $I->waitForElement('//*/button[@name="_savedok"][not(@disabled)][1]', 30);
84  $I->waitForElement($initializedInputFieldXpath, 30);
85 
86  // Find the fields again (after reload of iFrame)
87  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
88  $inputField = $this->‪getInputField($formSection);
89  $hiddenField = $this->‪getHiddenField($formSection, $inputField);
90 
91  // Validate save was successful
92  $I->comment('Test value of visible and hidden field');
93  $I->seeInField($inputField, $testData['expectedValue']);
94  $I->seeInField($hiddenField, $testData['expectedValueAfterSave']);
95  }
96 
103  protected function ‪getInputField(RemoteWebElement $formSection)
104  {
105  return $formSection->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
106  }
107 
115  protected function ‪getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
116  {
117  $hiddenFieldXPath = './/*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
118  return $formSection->findElement(\WebDriverBy::xpath($hiddenFieldXPath));
119  }
120 
128  protected function ‪getFormSectionByFieldLabel(‪BackendTester $I, string $fieldLabel)
129  {
130  $I->comment('Get context for field "' . $fieldLabel . '"');
131  return $I->executeInSelenium(
132  function (RemoteWebDriver $webDriver) use ($fieldLabel) {
133  return $webDriver->findElement(
134  \WebDriverBy::xpath(
135  '(//label[contains(text(),"' . $fieldLabel . '")])[1]/ancestor::fieldset[@class="form-section"][1]'
136  )
137  );
138  }
139  );
140  }
141 
147  protected function ‪ensureTopOfFrameIsUsedAndClickTab(‪BackendTester $I, string $tabTitle, string $referenceField)
148  {
149  try {
150  $I->click($tabTitle);
151  } catch (UnknownServerException $exception) {
152  // this is fired if the element can't be clicked, because for example another element overlays it.
153  $this->‪scrollToTopOfFrame($I, $tabTitle, $referenceField);
154  }
155  }
156 
157  protected function ‪scrollToTopOfFrame(‪BackendTester $I, string $tabTitle, string $referenceField)
158  {
159  $formSection = $this->‪getFormSectionByFieldLabel($I, $referenceField);
160  $field = $this->‪getInputField($formSection);
161  $maxPageUp = 10;
162  do {
163  $doItAgain = false;
164  $maxPageUp--;
165  try {
166  $field->sendKeys(WebDriverKeys::PAGE_UP);
167  $I->click($tabTitle);
168  } catch (UnknownServerException $exception) {
169  $doItAgain = true;
170  }
171  } while ($doItAgain === true && $maxPageUp > 0);
172  }
173 }
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\scrollToTopOfFrame
‪scrollToTopOfFrame(BackendTester $I, string $tabTitle, string $referenceField)
Definition: AbstractElementsBasicCest.php:156
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\getHiddenField
‪RemoteWebElement getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
Definition: AbstractElementsBasicCest.php:114
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\$triggerFocusChangeFieldLabel
‪string $triggerFocusChangeFieldLabel
Definition: AbstractElementsBasicCest.php:35
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\getFormSectionByFieldLabel
‪RemoteWebElement getFormSectionByFieldLabel(BackendTester $I, string $fieldLabel)
Definition: AbstractElementsBasicCest.php:127
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\runInputFieldTest
‪runInputFieldTest(BackendTester $I, Example $testData)
Definition: AbstractElementsBasicCest.php:44
‪TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester
Definition: BackendTester.php:25
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\ensureTopOfFrameIsUsedAndClickTab
‪ensureTopOfFrameIsUsedAndClickTab(BackendTester $I, string $tabTitle, string $referenceField)
Definition: AbstractElementsBasicCest.php:146
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest\getInputField
‪RemoteWebElement getInputField(RemoteWebElement $formSection)
Definition: AbstractElementsBasicCest.php:102
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine\AbstractElementsBasicCest
Definition: AbstractElementsBasicCest.php:29
‪TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine
Definition: AbstractElementsBasicCest.php:3