Merge pull request #25994 from nextcloud/backport/25975/stable20

[stable20] Add missing waits and asserts in acceptance tests
This commit is contained in:
Roeland Jago Douma 2021-03-09 09:34:25 +01:00 committed by GitHub
commit 791868fa25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 158 additions and 53 deletions

View File

@ -112,14 +112,24 @@ class AppNavigationContext implements Context, ActorAwareInterface {
* @Then I see that the section :section is shown * @Then I see that the section :section is shown
*/ */
public function iSeeThatTheSectionIsShown($section) { public function iSeeThatTheSectionIsShown($section) {
WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section)); if (!WaitFor::elementToBeEventuallyShown(
$this->actor,
self::appNavigationSectionItemFor($section),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The section $section in the app navigation is not shown yet after $timeout seconds");
}
} }
/** /**
* @Then I see that the section :section is not shown * @Then I see that the section :section is not shown
*/ */
public function iSeeThatTheSectionIsNotShown($section) { public function iSeeThatTheSectionIsNotShown($section) {
WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section)); if (!WaitFor::elementToBeEventuallyNotShown(
$this->actor,
self::appNavigationSectionItemFor($section),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The section $section in the app navigation is still shown after $timeout seconds");
}
} }
/** /**

View File

@ -74,27 +74,25 @@ class AppSettingsContext implements Context, ActorAwareInterface {
* @Given I open the settings * @Given I open the settings
*/ */
public function iOpenTheSettings() { public function iOpenTheSettings() {
$this->actor->find(self::appSettingsOpenButton())->click(); $this->actor->find(self::appSettingsOpenButton(), 10)->click();
} }
/** /**
* @Given I toggle the :id checkbox in the settings * @Given I toggle the :id checkbox in the settings
*/ */
public function iToggleTheCheckboxInTheSettingsTo($id) { public function iToggleTheCheckboxInTheSettingsTo($id) {
$locator = self::CheckboxInTheSettings($id); $this->actor->find(self::checkboxLabelInTheSettings($id), 10)->click();
// If locator is not visible, fallback to label
if (!$this->actor->find(self::CheckboxInTheSettings($id))->isVisible()) {
$locator = self::checkboxLabelInTheSettings($id);
}
$this->actor->find($locator)->click();
} }
/** /**
* @Then I see that the settings are opened * @Then I see that the settings are opened
*/ */
public function iSeeThatTheSettingsAreOpened() { public function iSeeThatTheSettingsAreOpened() {
WaitFor::elementToBeEventuallyShown($this->actor, self::appSettingsContent()); if (!WaitFor::elementToBeEventuallyShown(
$this->actor,
self::appSettingsContent(),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The app settings are not open yet after $timeout seconds");
}
} }
} }

View File

@ -28,6 +28,14 @@ use Behat\Behat\Context\Context;
class AppsManagementContext implements Context, ActorAwareInterface { class AppsManagementContext implements Context, ActorAwareInterface {
use ActorAware; use ActorAware;
/**
* @return Locator
*/
public static function appsList() {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list']")->
describedAs("Apps list in Apps Management");
}
/** /**
* @return Locator * @return Locator
*/ */
@ -37,6 +45,15 @@ class AppsManagementContext implements Context, ActorAwareInterface {
describedAs("Enable button in the app list for $app"); describedAs("Enable button in the app list for $app");
} }
/**
* @return Locator
*/
public static function enableButtonForAnyApp() {
return Locator::forThe()->button("Enable")->
descendantOf(self::appsList())->
describedAs("Enable button in the app list for any app");
}
/** /**
* @return Locator * @return Locator
*/ */
@ -58,16 +75,27 @@ class AppsManagementContext implements Context, ActorAwareInterface {
/** /**
* @return Locator * @return Locator
*/ */
public static function bundleButton($bundle) { public static function disableButtonForAnyApp() {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input")-> return Locator::forThe()->button("Disable")->
describedAs("Button to enable / disable bundles"); descendantOf(self::appsList())->
describedAs("Disable button in the app list for any app");
}
/**
* @return Locator
*/
public static function enableAllBundleButton($bundle) {
return Locator::forThe()->xpath("//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input[@value='Enable all']")->
descendantOf(self::appsList())->
describedAs("Button to enable bundles");
} }
/** /**
* @return Locator * @return Locator
*/ */
public static function rowForApp($app) { public static function rowForApp($app) {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='app-name'][normalize-space() = '$app']/..")-> return Locator::forThe()->xpath("//div[@class='app-name'][normalize-space() = '$app']/..")->
descendantOf(self::appsList())->
describedAs("Row for app $app in Apps Management"); describedAs("Row for app $app in Apps Management");
} }
@ -75,7 +103,8 @@ class AppsManagementContext implements Context, ActorAwareInterface {
* @return Locator * @return Locator
*/ */
public static function emptyAppList() { public static function emptyAppList() {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list-empty']")-> return Locator::forThe()->xpath("//div[@id='apps-list-empty']")->
descendantOf(self::appsList())->
describedAs("Empty apps list view"); describedAs("Empty apps list view");
} }
@ -83,7 +112,8 @@ class AppsManagementContext implements Context, ActorAwareInterface {
* @return Locator * @return Locator
*/ */
public static function appEntries() { public static function appEntries() {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='section']")-> return Locator::forThe()->xpath("//div[@class='section']")->
descendantOf(self::appsList())->
describedAs("Entries in apps list"); describedAs("Entries in apps list");
} }
@ -140,7 +170,9 @@ class AppsManagementContext implements Context, ActorAwareInterface {
*/ */
public function iSeeThatTheAppHasBeenEnabled($app) { public function iSeeThatTheAppHasBeenEnabled($app) {
// TODO: Find a way to check if the enable button is removed // TODO: Find a way to check if the enable button is removed
$this->actor->find(self::disableButtonForApp($app), 10); PHPUnit_Framework_Assert::assertTrue(
$this->actor->find(self::disableButtonForApp($app), 10)->isVisible()
);
} }
/** /**
@ -148,7 +180,9 @@ class AppsManagementContext implements Context, ActorAwareInterface {
*/ */
public function iSeeThatTheAppHasBeenDisabled($app) { public function iSeeThatTheAppHasBeenDisabled($app) {
// TODO: Find a way to check if the disable button is removed // TODO: Find a way to check if the disable button is removed
$this->actor->find(self::enableButtonForApp($app), 10); PHPUnit_Framework_Assert::assertTrue(
$this->actor->find(self::enableButtonForApp($app), 10)->isVisible()
);
} }
/** /**
@ -164,7 +198,12 @@ class AppsManagementContext implements Context, ActorAwareInterface {
* @Then /^I see that there some apps listed from the app store$/ * @Then /^I see that there some apps listed from the app store$/
*/ */
public function iSeeThatThereSomeAppsListedFromTheAppStore() { public function iSeeThatThereSomeAppsListedFromTheAppStore() {
WaitFor::elementToBeEventuallyShown($this->actor, self::appEntries(), 10); if (!WaitFor::elementToBeEventuallyShown(
$this->actor,
self::appEntries(),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The apps from the app store were not shown yet after $timeout seconds");
}
} }
/** /**
@ -178,38 +217,52 @@ class AppsManagementContext implements Context, ActorAwareInterface {
* @Given /^I see that there are only disabled apps$/ * @Given /^I see that there are only disabled apps$/
*/ */
public function iSeeThatThereAreOnlyDisabledApps() { public function iSeeThatThereAreOnlyDisabledApps() {
$buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Disable']"); try {
PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps'); $this->actor->find(self::disableButtonForAnyApp(), 2);
PHPUnit_Framework_Assert::fail("Found enabled apps");
} catch (NoSuchElementException $exception) {
}
} }
/** /**
* @Given /^I see that there are only enabled apps$/ * @Given /^I see that there are only enabled apps$/
*/ */
public function iSeeThatThereAreOnlyEnabledApps() { public function iSeeThatThereAreOnlyEnabledApps() {
$buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Enable']"); try {
PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps'); $this->actor->find(self::enableButtonForAnyApp(), 2);
PHPUnit_Framework_Assert::fail("Found disabled apps");
} catch (NoSuchElementException $exception) {
}
} }
/** /**
* @Given /^I see the app bundles$/ * @Given /^I see the app bundles$/
*/ */
public function iSeeTheAppBundles() { public function iSeeTheAppBundles() {
$this->actor->find(self::rowForApp('Auditing / Logging'), 2); PHPUnit_Framework_Assert::assertTrue(
$this->actor->find(self::rowForApp('LDAP user and group backend'), 2); $this->actor->find(self::rowForApp('Auditing / Logging'), 2)->isVisible()
);
PHPUnit_Framework_Assert::assertTrue(
$this->actor->find(self::rowForApp('LDAP user and group backend'), 2)->isVisible()
);
} }
/** /**
* @When /^I enable all apps from the "([^"]*)"$/ * @When /^I enable all apps from the "([^"]*)"$/
*/ */
public function iEnableAllAppsFromThe($bundle) { public function iEnableAllAppsFromThe($bundle) {
$this->actor->find(self::bundleButton($bundle), 2)->click(); $this->actor->find(self::enableAllBundleButton($bundle), 2)->click();
} }
/** /**
* @Given /^I see that the "([^"]*)" is disabled$/ * @Given /^I see that the "([^"]*)" is disabled$/
*/ */
public function iSeeThatTheIsDisabled($bundle) { public function iSeeThatTheIsDisabled($bundle) {
PHPUnit\Framework\Assert::assertEquals('Enable all', $this->actor->find(self::bundleButton($bundle))->getValue()); PHPUnit_Framework_Assert::assertTrue(
$this->actor->find(self::enableAllBundleButton($bundle), 2)->isVisible()
);
} }
/** /**

View File

@ -38,7 +38,7 @@ class DialogContext implements Context, ActorAwareInterface {
* @return Locator * @return Locator
*/ */
public static function theDialogButton($text) { public static function theDialogButton($text) {
return Locator::forThe()->xpath("//button[normalize-space() = '$text']")-> return Locator::forThe()->xpath("//button[normalize-space() = \"$text\"]")->
descendantOf(self::theDialog())-> descendantOf(self::theDialog())->
describedAs($text . " button of the dialog"); describedAs($text . " button of the dialog");
} }
@ -54,13 +54,23 @@ class DialogContext implements Context, ActorAwareInterface {
* @Then I see that the confirmation dialog is shown * @Then I see that the confirmation dialog is shown
*/ */
public function iSeeThatTheConfirmationDialogIsShown() { public function iSeeThatTheConfirmationDialogIsShown() {
WaitFor::elementToBeEventuallyShown($this->actor, self::theDialog()); if (!WaitFor::elementToBeEventuallyShown(
$this->actor,
self::theDialog(),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The confirmation dialog was not shown yet after $timeout seconds");
}
} }
/** /**
* @Then I see that the confirmation dialog is not shown * @Then I see that the confirmation dialog is not shown
*/ */
public function iSeeThatTheConfirmationDialogIsNotShown() { public function iSeeThatTheConfirmationDialogIsNotShown() {
WaitFor::elementToBeEventuallyNotShown($this->actor, self::theDialog()); if (!WaitFor::elementToBeEventuallyNotShown(
$this->actor,
self::theDialog(),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The confirmation dialog is still shown after $timeout seconds");
}
} }
} }

View File

@ -176,21 +176,21 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @When I click the New user button * @When I click the New user button
*/ */
public function iClickTheNewUserButton() { public function iClickTheNewUserButton() {
$this->actor->find(self::newUserButton())->click(); $this->actor->find(self::newUserButton(), 10)->click();
} }
/** /**
* @When I click the :action action in the :user actions menu * @When I click the :action action in the :user actions menu
*/ */
public function iClickTheAction($action, $user) { public function iClickTheAction($action, $user) {
$this->actor->find(self::theAction($action, $user))->click(); $this->actor->find(self::theAction($action, $user), 10)->click();
} }
/** /**
* @When I open the actions menu for the user :user * @When I open the actions menu for the user :user
*/ */
public function iOpenTheActionsMenuOf($user) { public function iOpenTheActionsMenuOf($user) {
$this->actor->find(self::actionsMenuOf($user))->click(); $this->actor->find(self::actionsMenuOf($user), 10)->click();
} }
/** /**
@ -267,14 +267,24 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @Then I see that the list of users contains the user :user * @Then I see that the list of users contains the user :user
*/ */
public function iSeeThatTheListOfUsersContainsTheUser($user) { public function iSeeThatTheListOfUsersContainsTheUser($user) {
WaitFor::elementToBeEventuallyShown($this->actor, self::rowForUser($user)); if (!WaitFor::elementToBeEventuallyShown(
$this->actor,
self::rowForUser($user),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The user $user in the list of users is not shown yet after $timeout seconds");
}
} }
/** /**
* @Then I see that the list of users does not contains the user :user * @Then I see that the list of users does not contains the user :user
*/ */
public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) { public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) {
WaitFor::elementToBeEventuallyNotShown($this->actor, self::rowForUser($user)); if (!WaitFor::elementToBeEventuallyNotShown(
$this->actor,
self::rowForUser($user),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The user $user in the list of users is still shown after $timeout seconds");
}
} }
/** /**
@ -321,8 +331,26 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @Then I see that the :cell cell for user :user is done loading * @Then I see that the :cell cell for user :user is done loading
*/ */
public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) { public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) {
WaitFor::elementToBeEventuallyShown($this->actor, self::classCellForUser($cell . ' icon-loading-small', $user)); // It could happen that the cell for the user was done loading and thus
WaitFor::elementToBeEventuallyNotShown($this->actor, self::classCellForUser($cell . ' icon-loading-small', $user)); // the loading icon hidden again even before finding the loading icon
// started. Therefore, if the loading icon could not be found it is just
// assumed that it was already hidden again. Nevertheless, this check
// should be done anyway to ensure that the following scenario steps are
// not executed before the cell for the user was done loading.
try {
$this->actor->find(self::classCellForUser($cell . ' icon-loading-small', $user), 1);
} catch (NoSuchElementException $exception) {
echo "The loading icon for user $user was not found after " . (1 * $this->actor->getFindTimeoutMultiplier()) . " seconds, assumming that it was shown and hidden again before the check started and continuing";
return;
}
if (!WaitFor::elementToBeEventuallyNotShown(
$this->actor,
self::classCellForUser($cell . ' icon-loading-small', $user),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The loading icon for user $user is still shown after $timeout seconds");
}
} }
/** /**
@ -337,6 +365,11 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @Then I see that the edit mode is on for user :user * @Then I see that the edit mode is on for user :user
*/ */
public function iSeeThatTheEditModeIsOn($user) { public function iSeeThatTheEditModeIsOn($user) {
WaitFor::elementToBeEventuallyShown($this->actor, self::editModeOn($user)); if (!WaitFor::elementToBeEventuallyShown(
$this->actor,
self::editModeOn($user),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The edit mode for user $user in the list of users is not on yet after $timeout seconds");
}
} }
} }

View File

@ -30,6 +30,7 @@ Feature: users
And I open the actions menu for the user user0 And I open the actions menu for the user user0
And I see that the "Delete user" action in the user0 actions menu is shown And I see that the "Delete user" action in the user0 actions menu is shown
When I click the "Delete user" action in the user0 actions menu When I click the "Delete user" action in the user0 actions menu
And I click the "Delete user0's account" button of the confirmation dialog
Then I see that the list of users does not contains the user user0 Then I see that the list of users does not contains the user user0
Scenario: disable a user Scenario: disable a user