Skip to content

Commit

Permalink
Merge pull request #28175 from owncloud/ui-tests-check-input-when-ren…
Browse files Browse the repository at this point in the history
…aming

UI tests - clear input before renaming
  • Loading branch information
individual-it authored Jun 21, 2017
2 parents 5573f77 + ba2e35a commit a9a27d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/ui/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function notificationsShouldBeDisplayedWithTheText(TableNode $table)
{
$notifications = $this->owncloudPage->getNotifications();
$tableRows=$table->getRows();
PHPUnit_Framework_Assert::assertEquals(
PHPUnit_Framework_Assert::assertGreaterThanOrEqual(
count($tableRows),
count($notifications)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private function _renameFile($fromFileName, $toFileName, Session $session)
if ($inputField === null) {
throw new ElementNotFoundException("could not find input field");
}
$inputField->setValue($toFileName);
$this->cleanInputAndSetValue($inputField, $toFileName);
$inputField->blur();
$this->waitTillElementIsNull($this->fileBusyIndicatorXpath);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Behat\Mink\Session;
use Behat\Mink\Element\NodeElement;
use WebDriver\Exception as WebDriverException;
use WebDriver\Key;

class OwncloudPage extends Page
{
Expand Down Expand Up @@ -254,4 +255,27 @@ protected function elementHasCSSValue($element, $property, $value)

return $exists;
}

/**
* sends an END key and then BACKSPACEs to delete the current value
* then sends the new value
* checks the set value and sends the Escape key + throws an exception
* if the value is not set correctly
*
* @param NodeElement $inputField
* @param string $value
* @throws \Exception
*/
protected function cleanInputAndSetValue(NodeElement $inputField, $value) {
$resultValue = $inputField->getValue();
$existingValueLength = strlen($resultValue);
$deleteSequence = Key::END . str_repeat(Key::BACKSPACE, $existingValueLength);
$inputField->setValue($deleteSequence);
$inputField->setValue($value);
$resultValue = $inputField->getValue();
if ($resultValue !== $value) {
$inputField->keyUp(27); //send escape
throw new \Exception("value of input field is not what we expect");
}
}
}

0 comments on commit a9a27d1

Please sign in to comment.