Skip to content

Commit b8986f7

Browse files
authored
Merge pull request #20 from NoelDeMartin/MOBILE-3320
MOBILE-3320: Add launch step, browser tab assertion, and update choice tests
2 parents 8d7872a + 3afab67 commit b8986f7

File tree

3 files changed

+227
-134
lines changed

3 files changed

+227
-134
lines changed
Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@mod @mod_choice @app @app_upto3.9.4 @javascript
1+
@mod @mod_choice @app @javascript
22
Feature: Test basic usage of choice activity in app
33
In order to participate in the choice while using the mobile app
44
As a student
@@ -17,7 +17,6 @@ Feature: Test basic usage of choice activity in app
1717
| teacher1 | C1 | editingteacher |
1818
| student1 | C1 | student |
1919

20-
@app @3.8.0
2120
Scenario: Answer a choice (multi or single, update answer) & View results
2221
Given the following "activities" exist:
2322
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
@@ -26,24 +25,23 @@ Feature: Test basic usage of choice activity in app
2625
And I log in as "student1"
2726
And I press "Course 1" near "Course overview" in the app
2827
And I press "Test single choice name" in the app
29-
And I press "Option 1" in the app
30-
And I press "Option 2" in the app
28+
And I select "Option 1" in the app
29+
And I select "Option 2" in the app
3130
And I press "Save my choice" in the app
32-
Then I should see "Are you sure"
31+
Then I should find "Are you sure" in the app
3332

3433
When I press "OK" in the app
35-
Then I should see "Option 1: 0"
36-
And I should see "Option 2: 1"
37-
And I should see "Option 3: 0"
38-
But I should not see "Remove my choice"
34+
Then I should find "Option 1: 0" in the app
35+
And I should find "Option 2: 1" in the app
36+
And I should find "Option 3: 0" in the app
37+
But I should not find "Remove my choice" in the app
3938

4039
When I press the back button in the app
4140
And I press "Test single choice name" in the app
42-
Then I should see "Option 1: 0"
43-
And I should see "Option 2: 1"
44-
And I should see "Option 3: 0"
41+
Then I should find "Option 1: 0" in the app
42+
And I should find "Option 2: 1" in the app
43+
And I should find "Option 3: 0" in the app
4544

46-
@app @3.8.0
4745
Scenario: Answer a choice (multi or single, update answer) & View results & Delete choice
4846
Given the following "activities" exist:
4947
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
@@ -52,29 +50,28 @@ Feature: Test basic usage of choice activity in app
5250
And I log in as "student1"
5351
And I press "Course 1" near "Course overview" in the app
5452
And I press "Test multi choice name" in the app
55-
And I press "Option 1" in the app
56-
And I press "Option 2" in the app
53+
And I select "Option 1" in the app
54+
And I select "Option 2" in the app
5755
And I press "Save my choice" in the app
58-
Then I should see "Option 1: 1"
59-
And I should see "Option 2: 1"
60-
And I should see "Option 3: 0"
61-
And I should see "Remove my choice"
56+
Then I should find "Option 1: 1" in the app
57+
And I should find "Option 2: 1" in the app
58+
And I should find "Option 3: 0" in the app
59+
And I should find "Remove my choice" in the app
6260

63-
When I press "Option 1" in the app
64-
And I press "Option 3" in the app
61+
When I select "Option 1" in the app
62+
And I select "Option 3" in the app
6563
And I press "Save my choice" in the app
66-
Then I should see "Option 1: 0"
67-
And I should see "Option 2: 1"
68-
And I should see "Option 3: 1"
64+
Then I should find "Option 1: 0" in the app
65+
And I should find "Option 2: 1" in the app
66+
And I should find "Option 3: 1" in the app
6967

7068
When I press "Remove my choice" in the app
71-
Then I should see "Are you sure"
69+
Then I should find "Are you sure" in the app
7270

7371
When I press "Delete" in the app
74-
Then I should see "The results are not currently viewable"
75-
But I should not see "Remove my choice"
72+
Then I should find "The results are not currently viewable" in the app
73+
But I should not find "Remove my choice" in the app
7674

77-
@app @3.8.0
7875
Scenario: Answer and change answer offline & Sync choice
7976
Given the following "activities" exist:
8077
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
@@ -83,31 +80,32 @@ Feature: Test basic usage of choice activity in app
8380
And I log in as "student1"
8481
And I press "Course 1" near "Course overview" in the app
8582
And I press "Test single choice name" in the app
86-
And I press "Option 1" in the app
83+
And I select "Option 1" in the app
8784
And I switch offline mode to "true"
88-
And I press "Option 2" in the app
85+
And I select "Option 2" in the app
8986
And I press "Save my choice" in the app
90-
Then I should see "Are you sure"
87+
Then I should find "Are you sure" in the app
9188

9289
When I press "OK" in the app
9390
And I press the back button in the app
9491
And I press "Test single choice name" in the app
95-
Then I should see "This Choice has offline data to be synchronised."
96-
But I should not see "Option 1: 0"
97-
And I should not see "Option 2: 1"
98-
And I should not see "Option 3: 0"
92+
Then I should find "This Choice has offline data to be synchronised." in the app
93+
But I should not find "Option 1: 0" in the app
94+
And I should not find "Option 2: 1" in the app
95+
And I should not find "Option 3: 0" in the app
9996

10097
When I switch offline mode to "false"
10198
And I press the back button in the app
10299
And I press "Test single choice name" in the app
103-
And I press "Display options" in the app
100+
Then I should find "Test single choice description" in the app
101+
102+
When I press "Display options" in the app
104103
And I press "Refresh" in the app
105-
Then I should see "Option 1: 0"
106-
And I should see "Option 2: 1"
107-
And I should see "Option 3: 0"
108-
But I should not see "This Choice has offline data to be synchronised."
104+
Then I should find "Option 1: 0" in the app
105+
And I should find "Option 2: 1" in the app
106+
And I should find "Option 3: 0" in the app
107+
But I should not find "This Choice has offline data to be synchronised." in the app
109108

110-
@app @3.8.0
111109
Scenario: Answer and change answer offline & Auto-sync choice
112110
Given the following "activities" exist:
113111
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
@@ -120,23 +118,22 @@ Feature: Test basic usage of choice activity in app
120118
And I switch offline mode to "true"
121119
And I press "Option 2" in the app
122120
And I press "Save my choice" in the app
123-
Then I should see "Are you sure"
121+
Then I should find "Are you sure" in the app
124122

125123
When I press "OK" in the app
126-
And I switch offline mode to "false"
127-
Then I should see "This Choice has offline data to be synchronised."
128-
But I should not see "Option 1: 0"
129-
And I should not see "Option 2: 1"
130-
And I should not see "Option 3: 0"
124+
Then I should find "This Choice has offline data to be synchronised." in the app
125+
But I should not find "Option 1: 0" in the app
126+
And I should not find "Option 2: 1" in the app
127+
And I should not find "Option 3: 0" in the app
131128

132-
When I run cron tasks in the app
129+
When I switch offline mode to "false"
130+
And I run cron tasks in the app
133131
And I wait loading to finish in the app
134-
Then I should see "Option 1: 0"
135-
And I should see "Option 2: 1"
136-
And I should see "Option 3: 0"
137-
But I should not see "This Choice has offline data to be synchronised."
132+
Then I should find "Option 1: 0" in the app
133+
And I should find "Option 2: 1" in the app
134+
And I should find "Option 3: 0" in the app
135+
But I should not find "This Choice has offline data to be synchronised." in the app
138136

139-
@app @3.8.0
140137
Scenario: Prefetch
141138
Given the following "activities" exist:
142139
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
@@ -147,35 +144,36 @@ Feature: Test basic usage of choice activity in app
147144
And I press "Course 1" near "Course overview" in the app
148145
And I press "Display options" in the app
149146
And I press "Show download options" in the app
150-
And I press "cloud download" near "Test single choice name" in the app
151-
And I switch offline mode to "true"
147+
And I press "Download" near "Test single choice name" in the app
148+
Then I should find "Downloaded" near "Test single choice name" in the app
149+
150+
When I switch offline mode to "true"
152151
And I press "Test multi choice name" in the app
153-
Then I should see "There was a problem connecting to the site. Please check your connection and try again."
152+
Then I should find "There was a problem connecting to the site. Please check your connection and try again." in the app
154153

155154
When I press "OK" in the app
156155
And I press the back button in the app
157156
And I press "Test single choice name" in the app
158157
And I press "Option 2" in the app
159158
And I press "Save my choice" in the app
160-
Then I should see "Are you sure"
159+
Then I should find "Are you sure" in the app
161160

162161
When I press "OK" in the app
163162
And I press the back button in the app
164163
And I press "Test single choice name" in the app
165-
Then I should see "This Choice has offline data to be synchronised."
166-
But I should not see "Option 1: 0"
167-
And I should not see "Option 2: 1"
168-
And I should not see "Option 3: 0"
164+
Then I should find "This Choice has offline data to be synchronised." in the app
165+
But I should not find "Option 1: 0" in the app
166+
And I should not find "Option 2: 1" in the app
167+
And I should not find "Option 3: 0" in the app
169168

170169
When I switch offline mode to "false"
171170
And I press the back button in the app
172171
And I press "Test single choice name" in the app
173-
Then I should see "Option 1: 0"
174-
And I should see "Option 2: 1"
175-
And I should see "Option 3: 0"
176-
But I should not see "This Choice has offline data to be synchronised."
172+
Then I should find "Option 1: 0" in the app
173+
And I should find "Option 2: 1" in the app
174+
And I should find "Option 3: 0" in the app
175+
But I should not find "This Choice has offline data to be synchronised." in the app
177176

178-
@app @3.8.0
179177
Scenario: Download students choice in text format
180178
# Submit answer as student
181179
Given the following "activities" exist:
@@ -194,10 +192,13 @@ Feature: Test basic usage of choice activity in app
194192
And I log in as "teacher1"
195193
And I press "Course 1" near "Course overview" in the app
196194
And I press "Choice name" in the app
197-
And I press "Display options" in the app
195+
Then I should find "Test choice description" in the app
196+
197+
When I press "Display options" in the app
198198
And I press "Open in browser" in the app
199199
And I switch to the browser tab opened by the app
200200
And I log in as "teacher1"
201201
And I press "Actions menu"
202202
And I follow "View 1 responses"
203203
And I press "Download in text format"
204+
# TODO Then I should find "..." in the downloads folder

tests/behat/app_behat_runtime.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,32 @@
326326
return elements;
327327
};
328328

329+
/**
330+
* Given a list of elements, get the top ancestors among all of them.
331+
*
332+
* This will remote duplicates and drop any elements nested within each other.
333+
*
334+
* @param {Array} elements Elements list.
335+
* @return {Array} Top ancestors.
336+
*/
337+
var getTopAncestors = function(elements) {
338+
const uniqueElements = new Set(elements);
339+
340+
for (const element of uniqueElements) {
341+
for (otherElement of uniqueElements) {
342+
if (otherElement === element) {
343+
continue;
344+
}
345+
346+
if (element.contains(otherElement)) {
347+
uniqueElements.delete(otherElement);
348+
}
349+
}
350+
}
351+
352+
return [...uniqueElements];
353+
};
354+
329355
/**
330356
* Function to find elements based on their text or Aria label.
331357
*
@@ -343,10 +369,16 @@
343369
if (nearElements.length === 0) {
344370
throw new Error('There was no match for near text')
345371
} else if (nearElements.length > 1) {
346-
throw new Error('Too many matches for near text');
347-
}
372+
const nearElementsAncestors = getTopAncestors(nearElements);
348373

349-
container = nearElements[0].parentElement;
374+
if (nearElementsAncestors.length > 1) {
375+
throw new Error('Too many matches for near text');
376+
}
377+
378+
container = nearElementsAncestors[0].parentElement;
379+
} else {
380+
container = nearElements[0].parentElement;
381+
}
350382
}
351383

352384
do {

0 commit comments

Comments
 (0)