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