‪TYPO3CMS  11.5
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\Remote\RemoteWebDriver;
22 use Facebook\WebDriver\Remote\RemoteWebElement;
23 use Facebook\WebDriver\WebDriverKeys;
25 
30 {
38  protected function ‪runInputFieldTest(‪ApplicationTester $I, Example $testData): void
39  {
40  $fieldLabel = $testData['label'];
41  $initializedInputFieldXpath = '(//label/code[contains(text(),"[' . $fieldLabel . ']")]/..)'
42  . '[1]/parent::*//*/input[@data-formengine-input-name][@data-formengine-input-initialized]';
43 
44  // Wait until JS initialized everything
45  $I->waitForElement($initializedInputFieldXpath, 30);
46 
47  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
48  $inputField = $this->‪getInputField($formSection);
49  $hiddenField = $this->‪getHiddenField($formSection, $inputField);
50 
51  if ($testData['comment'] !== '') {
52  $I->comment($testData['comment']);
53  }
54 
55  $I->fillField($inputField, $testData['inputValue']);
56  // Change focus to trigger validation
57  $inputField->sendKeys(WebDriverKeys::TAB);
58  // Press ESC so that any opened popup (potentially from the field below) is closed
59  $inputField->sendKeys(WebDriverKeys::ESCAPE);
60  $I->waitForElementNotVisible('#t3js-ui-block');
61 
62  $I->comment('Test value of visible and hidden field');
63  $I->seeInField($inputField, $testData['expectedValue']);
64  $I->seeInField($hiddenField, $testData['expectedInternalValue']);
65 
66  $I->comment('Save the form');
67  $saveButtonLink = '//*/button[@name="_savedok"][1]';
68  $I->waitForElement($saveButtonLink, 30);
69  $I->click($saveButtonLink);
70  $I->waitForElementNotVisible('#t3js-ui-block');
71  $I->waitForElement('//*/button[@name="_savedok"][not(@disabled)][1]', 30);
72  $I->waitForElement($initializedInputFieldXpath, 30);
73 
74  // Find the fields again (after reload of iFrame)
75  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
76  $inputField = $this->‪getInputField($formSection);
77  $hiddenField = $this->‪getHiddenField($formSection, $inputField);
78 
79  // Validate save was successful
80  $I->comment('Test value of visible and hidden field');
81  $I->seeInField($inputField, $testData['expectedValue']);
82  $I->seeInField($hiddenField, $testData['expectedValueAfterSave']);
83  }
84 
91  protected function ‪getInputField(RemoteWebElement $formSection): RemoteWebElement
92  {
93  return $formSection->findElement(\Facebook\WebDriver\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
94  }
95 
103  protected function ‪getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField): RemoteWebElement
104  {
105  $hiddenFieldXPath = './/*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
106  return $formSection->findElement(\Facebook\WebDriver\WebDriverBy::xpath($hiddenFieldXPath));
107  }
108 
116  protected function ‪getFormSectionByFieldLabel(‪ApplicationTester $I, string $fieldLabel): RemoteWebElement
117  {
118  $I->comment('Get context for field "' . $fieldLabel . '"');
119  return $I->executeInSelenium(
120  static function (RemoteWebDriver $webDriver) use ($fieldLabel) {
121  return $webDriver->findElement(
122  \Facebook\WebDriver\WebDriverBy::xpath(
123  '(//label/code[contains(text(),"[' . $fieldLabel . ']")]/..)[1]/ancestor::fieldset[@class="form-section"][1]'
124  )
125  );
126  }
127  );
128  }
129 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine
Definition: AbstractElementsBasicCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:27
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\getInputField
‪RemoteWebElement getInputField(RemoteWebElement $formSection)
Definition: AbstractElementsBasicCest.php:91
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\getHiddenField
‪RemoteWebElement getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
Definition: AbstractElementsBasicCest.php:103
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\getFormSectionByFieldLabel
‪RemoteWebElement getFormSectionByFieldLabel(ApplicationTester $I, string $fieldLabel)
Definition: AbstractElementsBasicCest.php:116
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\runInputFieldTest
‪runInputFieldTest(ApplicationTester $I, Example $testData)
Definition: AbstractElementsBasicCest.php:38
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest
Definition: AbstractElementsBasicCest.php:30