TYPO3 CMS  TYPO3_8-7
AbstractElementsBasicCest.php
Go to the documentation of this file.
1 <?php
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 
22 
27 {
35  protected function runInputFieldTest(BackendTester $I, Example $testData)
36  {
37  $fieldLabel = $testData['label'];
38  $initializedInputFieldXpath = '(//label[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  // Click on the div so that any opened popup (potentially from the field below) is closed
56  $formSection->click();
57  $I->waitForElementNotVisible('#t3js-ui-block');
58 
59  $I->comment('Test value of visible and hidden field');
60  $I->canSeeInField($inputField, $testData['expectedValue']);
61  $I->canSeeInField($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->canSeeInField($inputField, $testData['expectedValue']);
79  $I->canSeeInField($hiddenField, $testData['expectedValueAfterSave']);
80  }
81 
88  protected function getInputField(RemoteWebElement $formSection)
89  {
90  return $formSection->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
91  }
92 
100  protected function getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
101  {
102  $hiddenFieldXPath = './/*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
103  return $formSection->findElement(\WebDriverBy::xpath($hiddenFieldXPath));
104  }
105 
113  protected function getFormSectionByFieldLabel(BackendTester $I, string $fieldLabel)
114  {
115  $I->comment('Get context for field "' . $fieldLabel . '"');
116  return $I->executeInSelenium(
117  function (RemoteWebDriver $webDriver) use ($fieldLabel) {
118  return $webDriver->findElement(
119  \WebDriverBy::xpath(
120  '(//label[contains(text(),"' . $fieldLabel . '")])[1]/ancestor::fieldset[@class="form-section"][1]'
121  )
122  );
123  }
124  );
125  }
126 }
getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)