Skip to content

Commit

Permalink
Merge pull request #25994 from nextcloud/backport/25975/stable20
Browse files Browse the repository at this point in the history
[stable20] Add missing waits and asserts in acceptance tests
  • Loading branch information
rullzer authored Mar 9, 2021
2 parents df04689 + ace7b9d commit 791868f
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 53 deletions.
14 changes: 12 additions & 2 deletions tests/acceptance/features/bootstrap/AppNavigationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,24 @@ public function iSeeThatTheCurrentSectionIs($section) {
* @Then I see that the section :section is shown
*/
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
*/
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");
}
}

/**
Expand Down
18 changes: 8 additions & 10 deletions tests/acceptance/features/bootstrap/AppSettingsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,25 @@ public static function checkboxLabelInTheSettings($id) {
* @Given I open the settings
*/
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
*/
public function iToggleTheCheckboxInTheSettingsTo($id) {
$locator = self::CheckboxInTheSettings($id);

// 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();
$this->actor->find(self::checkboxLabelInTheSettings($id), 10)->click();
}

/**
* @Then I see that the settings are opened
*/
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");
}
}
}
113 changes: 83 additions & 30 deletions tests/acceptance/features/bootstrap/AppsManagementContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,89 +28,119 @@
class AppsManagementContext implements Context, ActorAwareInterface {
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
*/
public static function enableButtonForApp($app) {
return Locator::forThe()->button("Enable")->
descendantOf(self::rowForApp($app))->
describedAs("Enable button in the app list for $app");
descendantOf(self::rowForApp($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
*/
public static function downloadAndEnableButtonForApp($app) {
return Locator::forThe()->button("Download and enable")->
descendantOf(self::rowForApp($app))->
describedAs("Download & enable button in the app list for $app");
descendantOf(self::rowForApp($app))->
describedAs("Download & enable button in the app list for $app");
}

/**
* @return Locator
*/
public static function disableButtonForApp($app) {
return Locator::forThe()->button("Disable")->
descendantOf(self::rowForApp($app))->
describedAs("Disable button in the app list for $app");
descendantOf(self::rowForApp($app))->
describedAs("Disable button in the app list for $app");
}

/**
* @return Locator
*/
public static function disableButtonForAnyApp() {
return Locator::forThe()->button("Disable")->
descendantOf(self::appsList())->
describedAs("Disable button in the app list for any app");
}

/**
* @return Locator
*/
public static function bundleButton($bundle) {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input")->
describedAs("Button to enable / disable bundles");
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
*/
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");
}

/**
* @return Locator
*/
public static function emptyAppList() {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list-empty']")->
describedAs("Empty apps list view");
return Locator::forThe()->xpath("//div[@id='apps-list-empty']")->
descendantOf(self::appsList())->
describedAs("Empty apps list view");
}

/**
* @return Locator
*/
public static function appEntries() {
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='section']")->
describedAs("Entries in apps list");
return Locator::forThe()->xpath("//div[@class='section']")->
descendantOf(self::appsList())->
describedAs("Entries in apps list");
}

/**
* @return Locator
*/
public static function disabledAppEntries() {
return Locator::forThe()->button("Disable")->
descendantOf(self::appEntries())->
describedAs("Disable button in the app list");
descendantOf(self::appEntries())->
describedAs("Disable button in the app list");
}

/**
* @return Locator
*/
public static function enabledAppEntries() {
return Locator::forThe()->button("Enable")->
descendantOf(self::appEntries())->
describedAs("Enable button in the app list");
descendantOf(self::appEntries())->
describedAs("Enable button in the app list");
}

/**
* @return Locator
*/
public static function sidebar() {
return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")->
describedAs("Sidebar in apps management");
describedAs("Sidebar in apps management");
}


Expand Down Expand Up @@ -140,15 +170,19 @@ public function iDisableTheApp($app) {
*/
public function iSeeThatTheAppHasBeenEnabled($app) {
// 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()
);
}

/**
* @Then I see that the :app app has been disabled
*/
public function iSeeThatTheAppHasBeenDisabled($app) {
// 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()
);
}

/**
Expand All @@ -164,7 +198,12 @@ public function iSeeThatThereAreNoAvailableUpdates() {
* @Then /^I see that there some apps listed from the app store$/
*/
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");
}
}

/**
Expand All @@ -178,38 +217,52 @@ public function iClickOnTheApp($app) {
* @Given /^I see that there are only disabled apps$/
*/
public function iSeeThatThereAreOnlyDisabledApps() {
$buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Disable']");
PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps');
try {
$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$/
*/
public function iSeeThatThereAreOnlyEnabledApps() {
$buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Enable']");
PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps');
try {
$this->actor->find(self::enableButtonForAnyApp(), 2);

PHPUnit_Framework_Assert::fail("Found disabled apps");
} catch (NoSuchElementException $exception) {
}
}

/**
* @Given /^I see the app bundles$/
*/
public function iSeeTheAppBundles() {
$this->actor->find(self::rowForApp('Auditing / Logging'), 2);
$this->actor->find(self::rowForApp('LDAP user and group backend'), 2);
PHPUnit_Framework_Assert::assertTrue(
$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 "([^"]*)"$/
*/
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$/
*/
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()
);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions tests/acceptance/features/bootstrap/DialogContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function theDialog() {
* @return Locator
*/
public static function theDialogButton($text) {
return Locator::forThe()->xpath("//button[normalize-space() = '$text']")->
return Locator::forThe()->xpath("//button[normalize-space() = \"$text\"]")->
descendantOf(self::theDialog())->
describedAs($text . " button of the dialog");
}
Expand All @@ -54,13 +54,23 @@ public function iClickTheDialogButton($text) {
* @Then I see that the confirmation dialog is shown
*/
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
*/
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");
}
}
}
Loading

0 comments on commit 791868f

Please sign in to comment.