Skip to content

Commit ecb6438

Browse files
authored
Merge pull request #25993 from nextcloud/backport/25975/stable21
[stable21] Add missing waits and asserts in acceptance tests
2 parents 6842530 + 8185c46 commit ecb6438

6 files changed

+158
-53
lines changed

tests/acceptance/features/bootstrap/AppNavigationContext.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,24 @@ public function iSeeThatTheCurrentSectionIs($section) {
112112
* @Then I see that the section :section is shown
113113
*/
114114
public function iSeeThatTheSectionIsShown($section) {
115-
WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section));
115+
if (!WaitFor::elementToBeEventuallyShown(
116+
$this->actor,
117+
self::appNavigationSectionItemFor($section),
118+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
119+
PHPUnit_Framework_Assert::fail("The section $section in the app navigation is not shown yet after $timeout seconds");
120+
}
116121
}
117122

118123
/**
119124
* @Then I see that the section :section is not shown
120125
*/
121126
public function iSeeThatTheSectionIsNotShown($section) {
122-
WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section));
127+
if (!WaitFor::elementToBeEventuallyNotShown(
128+
$this->actor,
129+
self::appNavigationSectionItemFor($section),
130+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
131+
PHPUnit_Framework_Assert::fail("The section $section in the app navigation is still shown after $timeout seconds");
132+
}
123133
}
124134

125135
/**

tests/acceptance/features/bootstrap/AppSettingsContext.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,25 @@ public static function checkboxLabelInTheSettings($id) {
7474
* @Given I open the settings
7575
*/
7676
public function iOpenTheSettings() {
77-
$this->actor->find(self::appSettingsOpenButton())->click();
77+
$this->actor->find(self::appSettingsOpenButton(), 10)->click();
7878
}
7979

8080
/**
8181
* @Given I toggle the :id checkbox in the settings
8282
*/
8383
public function iToggleTheCheckboxInTheSettingsTo($id) {
84-
$locator = self::CheckboxInTheSettings($id);
85-
86-
// If locator is not visible, fallback to label
87-
if (!$this->actor->find(self::CheckboxInTheSettings($id))->isVisible()) {
88-
$locator = self::checkboxLabelInTheSettings($id);
89-
}
90-
91-
$this->actor->find($locator)->click();
84+
$this->actor->find(self::checkboxLabelInTheSettings($id), 10)->click();
9285
}
9386

9487
/**
9588
* @Then I see that the settings are opened
9689
*/
9790
public function iSeeThatTheSettingsAreOpened() {
98-
WaitFor::elementToBeEventuallyShown($this->actor, self::appSettingsContent());
91+
if (!WaitFor::elementToBeEventuallyShown(
92+
$this->actor,
93+
self::appSettingsContent(),
94+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
95+
PHPUnit_Framework_Assert::fail("The app settings are not open yet after $timeout seconds");
96+
}
9997
}
10098
}

tests/acceptance/features/bootstrap/AppsManagementContext.php

+83-30
Original file line numberDiff line numberDiff line change
@@ -28,89 +28,119 @@
2828
class AppsManagementContext implements Context, ActorAwareInterface {
2929
use ActorAware;
3030

31+
/**
32+
* @return Locator
33+
*/
34+
public static function appsList() {
35+
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list']")->
36+
describedAs("Apps list in Apps Management");
37+
}
38+
3139
/**
3240
* @return Locator
3341
*/
3442
public static function enableButtonForApp($app) {
3543
return Locator::forThe()->button("Enable")->
36-
descendantOf(self::rowForApp($app))->
37-
describedAs("Enable button in the app list for $app");
44+
descendantOf(self::rowForApp($app))->
45+
describedAs("Enable button in the app list for $app");
46+
}
47+
48+
/**
49+
* @return Locator
50+
*/
51+
public static function enableButtonForAnyApp() {
52+
return Locator::forThe()->button("Enable")->
53+
descendantOf(self::appsList())->
54+
describedAs("Enable button in the app list for any app");
3855
}
3956

4057
/**
4158
* @return Locator
4259
*/
4360
public static function downloadAndEnableButtonForApp($app) {
4461
return Locator::forThe()->button("Download and enable")->
45-
descendantOf(self::rowForApp($app))->
46-
describedAs("Download & enable button in the app list for $app");
62+
descendantOf(self::rowForApp($app))->
63+
describedAs("Download & enable button in the app list for $app");
4764
}
4865

4966
/**
5067
* @return Locator
5168
*/
5269
public static function disableButtonForApp($app) {
5370
return Locator::forThe()->button("Disable")->
54-
descendantOf(self::rowForApp($app))->
55-
describedAs("Disable button in the app list for $app");
71+
descendantOf(self::rowForApp($app))->
72+
describedAs("Disable button in the app list for $app");
73+
}
74+
75+
/**
76+
* @return Locator
77+
*/
78+
public static function disableButtonForAnyApp() {
79+
return Locator::forThe()->button("Disable")->
80+
descendantOf(self::appsList())->
81+
describedAs("Disable button in the app list for any app");
5682
}
5783

5884
/**
5985
* @return Locator
6086
*/
61-
public static function bundleButton($bundle) {
62-
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input")->
63-
describedAs("Button to enable / disable bundles");
87+
public static function enableAllBundleButton($bundle) {
88+
return Locator::forThe()->xpath("//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input[@value='Enable all']")->
89+
descendantOf(self::appsList())->
90+
describedAs("Button to enable bundles");
6491
}
6592

6693
/**
6794
* @return Locator
6895
*/
6996
public static function rowForApp($app) {
70-
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='app-name'][normalize-space() = '$app']/..")->
97+
return Locator::forThe()->xpath("//div[@class='app-name'][normalize-space() = '$app']/..")->
98+
descendantOf(self::appsList())->
7199
describedAs("Row for app $app in Apps Management");
72100
}
73101

74102
/**
75103
* @return Locator
76104
*/
77105
public static function emptyAppList() {
78-
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list-empty']")->
79-
describedAs("Empty apps list view");
106+
return Locator::forThe()->xpath("//div[@id='apps-list-empty']")->
107+
descendantOf(self::appsList())->
108+
describedAs("Empty apps list view");
80109
}
81110

82111
/**
83112
* @return Locator
84113
*/
85114
public static function appEntries() {
86-
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@class='section']")->
87-
describedAs("Entries in apps list");
115+
return Locator::forThe()->xpath("//div[@class='section']")->
116+
descendantOf(self::appsList())->
117+
describedAs("Entries in apps list");
88118
}
89119

90120
/**
91121
* @return Locator
92122
*/
93123
public static function disabledAppEntries() {
94124
return Locator::forThe()->button("Disable")->
95-
descendantOf(self::appEntries())->
96-
describedAs("Disable button in the app list");
125+
descendantOf(self::appEntries())->
126+
describedAs("Disable button in the app list");
97127
}
98128

99129
/**
100130
* @return Locator
101131
*/
102132
public static function enabledAppEntries() {
103133
return Locator::forThe()->button("Enable")->
104-
descendantOf(self::appEntries())->
105-
describedAs("Enable button in the app list");
134+
descendantOf(self::appEntries())->
135+
describedAs("Enable button in the app list");
106136
}
107137

108138
/**
109139
* @return Locator
110140
*/
111141
public static function sidebar() {
112142
return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")->
113-
describedAs("Sidebar in apps management");
143+
describedAs("Sidebar in apps management");
114144
}
115145

116146

@@ -140,15 +170,19 @@ public function iDisableTheApp($app) {
140170
*/
141171
public function iSeeThatTheAppHasBeenEnabled($app) {
142172
// TODO: Find a way to check if the enable button is removed
143-
$this->actor->find(self::disableButtonForApp($app), 10);
173+
PHPUnit_Framework_Assert::assertTrue(
174+
$this->actor->find(self::disableButtonForApp($app), 10)->isVisible()
175+
);
144176
}
145177

146178
/**
147179
* @Then I see that the :app app has been disabled
148180
*/
149181
public function iSeeThatTheAppHasBeenDisabled($app) {
150182
// TODO: Find a way to check if the disable button is removed
151-
$this->actor->find(self::enableButtonForApp($app), 10);
183+
PHPUnit_Framework_Assert::assertTrue(
184+
$this->actor->find(self::enableButtonForApp($app), 10)->isVisible()
185+
);
152186
}
153187

154188
/**
@@ -164,7 +198,12 @@ public function iSeeThatThereAreNoAvailableUpdates() {
164198
* @Then /^I see that there some apps listed from the app store$/
165199
*/
166200
public function iSeeThatThereSomeAppsListedFromTheAppStore() {
167-
WaitFor::elementToBeEventuallyShown($this->actor, self::appEntries(), 10);
201+
if (!WaitFor::elementToBeEventuallyShown(
202+
$this->actor,
203+
self::appEntries(),
204+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
205+
PHPUnit_Framework_Assert::fail("The apps from the app store were not shown yet after $timeout seconds");
206+
}
168207
}
169208

170209
/**
@@ -178,38 +217,52 @@ public function iClickOnTheApp($app) {
178217
* @Given /^I see that there are only disabled apps$/
179218
*/
180219
public function iSeeThatThereAreOnlyDisabledApps() {
181-
$buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Disable']");
182-
PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps');
220+
try {
221+
$this->actor->find(self::disableButtonForAnyApp(), 2);
222+
223+
PHPUnit_Framework_Assert::fail("Found enabled apps");
224+
} catch (NoSuchElementException $exception) {
225+
}
183226
}
184227

185228
/**
186229
* @Given /^I see that there are only enabled apps$/
187230
*/
188231
public function iSeeThatThereAreOnlyEnabledApps() {
189-
$buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Enable']");
190-
PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps');
232+
try {
233+
$this->actor->find(self::enableButtonForAnyApp(), 2);
234+
235+
PHPUnit_Framework_Assert::fail("Found disabled apps");
236+
} catch (NoSuchElementException $exception) {
237+
}
191238
}
192239

193240
/**
194241
* @Given /^I see the app bundles$/
195242
*/
196243
public function iSeeTheAppBundles() {
197-
$this->actor->find(self::rowForApp('Auditing / Logging'), 2);
198-
$this->actor->find(self::rowForApp('LDAP user and group backend'), 2);
244+
PHPUnit_Framework_Assert::assertTrue(
245+
$this->actor->find(self::rowForApp('Auditing / Logging'), 2)->isVisible()
246+
);
247+
PHPUnit_Framework_Assert::assertTrue(
248+
$this->actor->find(self::rowForApp('LDAP user and group backend'), 2)->isVisible()
249+
);
199250
}
200251

201252
/**
202253
* @When /^I enable all apps from the "([^"]*)"$/
203254
*/
204255
public function iEnableAllAppsFromThe($bundle) {
205-
$this->actor->find(self::bundleButton($bundle), 2)->click();
256+
$this->actor->find(self::enableAllBundleButton($bundle), 2)->click();
206257
}
207258

208259
/**
209260
* @Given /^I see that the "([^"]*)" is disabled$/
210261
*/
211262
public function iSeeThatTheIsDisabled($bundle) {
212-
PHPUnit\Framework\Assert::assertEquals('Enable all', $this->actor->find(self::bundleButton($bundle))->getValue());
263+
PHPUnit_Framework_Assert::assertTrue(
264+
$this->actor->find(self::enableAllBundleButton($bundle), 2)->isVisible()
265+
);
213266
}
214267

215268
/**

tests/acceptance/features/bootstrap/DialogContext.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function theDialog() {
3838
* @return Locator
3939
*/
4040
public static function theDialogButton($text) {
41-
return Locator::forThe()->xpath("//button[normalize-space() = '$text']")->
41+
return Locator::forThe()->xpath("//button[normalize-space() = \"$text\"]")->
4242
descendantOf(self::theDialog())->
4343
describedAs($text . " button of the dialog");
4444
}
@@ -54,13 +54,23 @@ public function iClickTheDialogButton($text) {
5454
* @Then I see that the confirmation dialog is shown
5555
*/
5656
public function iSeeThatTheConfirmationDialogIsShown() {
57-
WaitFor::elementToBeEventuallyShown($this->actor, self::theDialog());
57+
if (!WaitFor::elementToBeEventuallyShown(
58+
$this->actor,
59+
self::theDialog(),
60+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
61+
PHPUnit_Framework_Assert::fail("The confirmation dialog was not shown yet after $timeout seconds");
62+
}
5863
}
5964

6065
/**
6166
* @Then I see that the confirmation dialog is not shown
6267
*/
6368
public function iSeeThatTheConfirmationDialogIsNotShown() {
64-
WaitFor::elementToBeEventuallyNotShown($this->actor, self::theDialog());
69+
if (!WaitFor::elementToBeEventuallyNotShown(
70+
$this->actor,
71+
self::theDialog(),
72+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
73+
PHPUnit_Framework_Assert::fail("The confirmation dialog is still shown after $timeout seconds");
74+
}
6575
}
6676
}

0 commit comments

Comments
 (0)