How to use then method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

mod_choice.spec.js

Source: mod_choice.spec.js Github

copy
1// (C) Copyright 2015 Martin Dougiamas
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15describe('User can manage course choice', function() {
16
17    it('Click All sections course choice tabs', function (done) {
18        return MM.loginAsStudent().then(function () {
19            return MM.clickOnInSideMenu('My courses');
20        }).then(function () {
21            return MM.clickOn('Psychology in Cinema');
22        }).then(function () {
23            return MM.clickOn('All sections');
24        }).then(function () {
25            return MM.clickOn('Prior Knowledge assessment');
26        }).then(function() {
27            expect(MM.getView().getText()).toMatch('State your prior knowledge here:');
28        }).then(function () {
29            return MM.goBack();
30        }).then(function () {
31            return MM.clickOn("Let's make a date!");
32        }).then(function () {
33            expect(MM.getView().getText()).toMatch('Please choose the best day and time for our next evening session. You can choose more than one if');
34        }).then(function () {
35            return MM.goBack();
36        }).then(function() {
37            done();
38        });
39    });
40
41    it('Click Course welcome course choice tabs', function (done) {
42        return MM.loginAsStudent().then(function () {
43            return MM.clickOnInSideMenu('My courses');
44        }).then(function () {
45            return MM.clickOn('Psychology in Cinema');
46        }).then(function () {
47            return MM.clickOn('Course welcome');
48        }).then(function () {
49            return MM.clickOn('Prior Knowledge assessment');
50        }).then(function() {
51            expect(MM.getView().getText()).toMatch('State your prior knowledge here:');
52        }).then(function () {
53            return MM.goBack();
54        }).then(function () {
55            return MM.clickOn("Let's make a date!");
56        }).then(function () {
57            expect(MM.getView().getText()).toMatch('Please choose the best day and time for our next evening session. You can choose more than one if');
58        }).then(function () {
59            return MM.goBack();
60        }).then(function() {
61            done();
62        });
63    });
64
65    it('Click Group Projects and Individual tasks course choice tabs', function (done) {
66        return MM.loginAsStudent().then(function () {
67            return MM.clickOnInSideMenu('My courses');
68        }).then(function () {
69            return MM.clickOn('Psychology in Cinema');
70        }).then(function () {
71            return MM.clickOn('Group Projects and Individual tasks');
72        }).then(function () {
73            return MM.clickOn('Select your focus film');
74        }).then(function() {
75            expect(MM.getView().getText()).toMatch('Select here the film you wish to do your in depth group study on.');
76        }).then(function () {
77            return MM.goBack();
78        }).then(function() {
79            done();
80        });
81    });
82
83    it('User can manage Prior Knowledge assessment choices', function (done) {
84        return MM.loginAsStudent().then(function () {
85            return MM.clickOnInSideMenu('My courses');
86        }).then(function () {
87            return MM.clickOn('Psychology in Cinema');
88        }).then(function () {
89            return MM.clickOn('Course welcome');
90        }).then(function () {
91            return MM.clickOn('Prior Knowledge assessment');
92        }).then(function() {
93            return MM.clickOn('State your prior knowledge here:');
94        }).then(function () {
95            expect(MM.getView().getText()).toMatch('State your prior knowledge here:');
96        }).then(function () {
97            return MM.goBack();
98        }).then(function() {
99            return MM.clickOn('I have studied this ');
100        }).then(function() {
101            return MM.clickOn('I have a good working knowledge ');
102        }).then(function() {
103            return MM.clickOn('I have some knowledge');
104        }).then(function() {
105            return MM.clickOn('I am a complete beginner');
106        }).then(function () {
107            return MM.goBack();
108        }).then(function() {
109            done();
110        });
111    });
112
113    it("User can manage Let's make a date! assessment choices", function (done) {
114        return MM.loginAsStudent().then(function () {
115            return MM.clickOnInSideMenu('My courses');
116        }).then(function () {
117            return MM.clickOn('Psychology in Cinema');
118        }).then(function () {
119            return MM.clickOn('Course welcome');
120        }).then(function () {
121            return MM.clickOn("Let's make a date!");
122        }).then(function() {
123            return MM.clickOn('Please choose the best day and time for our next evening session.');
124        }).then(function () {
125            expect(MM.getView().getText()).toMatch('Please choose the best day and time for our next evening session.');
126        }).then(function () {
127            return MM.goBack();
128        }).then(function() {
129            return MM.clickOn('Friday at 18.00');
130        }).then(function() {
131            return MM.clickOn('Monday at 17.30');
132        }).then(function() {
133            return MM.clickOn('Wednesday at 19.00');
134        }).then(function() {
135            return $('[ng-click="save()"]').click();
136        }).then(function() {
137            return MM.clickOn('Cancel');
138        }).then(function () {
139            return MM.goBack();
140        }).then(function() {
141            done();
142        });
143    });
144
145    it("User can manage Group Projects and Individual tasks assessment choices", function (done) {
146        return MM.loginAsStudent().then(function () {
147            return MM.clickOnInSideMenu('My courses');
148        }).then(function () {
149            return MM.clickOn('Psychology in Cinema');
150        }).then(function () {
151            return MM.clickOn("Group Projects and Individual tasks");
152        }).then(function() {
153            return MM.clickOn('Select your focus film');
154        }).then(function() {
155            return MM.clickOn('Select here the film you wish to do your in depth group study on.');
156        }).then(function () {
157            expect(MM.getView().getText()).toMatch('Select here the film you wish to do your in depth group study on.');
158        }).then(function () {
159            return MM.goBack();
160        }).then(function () {
161            return MM.goBack();
162        }).then(function() {
163            done();
164        });
165    });
166
167    it('Click secondary button', function (done) {
168        return MM.loginAsStudent().then(function () {
169            return MM.clickOnInSideMenu('My courses');
170        }).then(function () {
171            return MM.clickOn('Psychology in Cinema');
172        }).then(function () {
173            return MM.clickOn("Group Projects and Individual tasks");
174        }).then(function() {
175            return MM.clickOn('Select your focus film');
176        }).then(function () {
177            return $('.secondary-buttons').click();
178        }).then(function() {
179            return MM.goBack();
180        }).then(function () {
181            done();
182        });
183    });
184
185});
186
187
Full Screen

mod_book.spec.js

Source: mod_book.spec.js Github

copy
1// (C) Copyright 2015 Martin Dougiamas
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15describe('User can manage course book', function() {
16
17    it('Click All sections course book tabs', function (done) {
18        return MM.loginAsStudent().then(function () {
19            return MM.clickOnInSideMenu('My courses');
20        }).then(function () {
21            return MM.clickOn('Psychology in Cinema');
22        }).then(function () {
23            return MM.clickOn('All sections');
24        }).then(function () {
25            return MM.clickOn('Useful links');
26        }).then(function () {
27            return MM.goBack();
28        }).then(function () {
29            return MM.clickOn('Video resources');
30        }).then(function () {
31            return MM.goBack();
32        }).then(function() {
33            done();
34        });
35    });
36
37    it('Click Background information course book tabs', function (done) {
38        return MM.loginAsStudent().then(function () {
39            return MM.clickOnInSideMenu('My courses');
40        }).then(function () {
41            return MM.clickOn('Psychology in Cinema');
42        }).then(function () {
43            return MM.clickOn('Background information');
44        }).then(function () {
45            return MM.clickOn('Useful links');
46        }).then(function () {
47            return MM.goBack();
48        }).then(function () {
49            return MM.clickOn('Video resources');
50        }).then(function () {
51            return MM.goBack();
52        }).then(function() {
53            done();
54        });
55    });
56
57    it('Can go all the useful links press next and previous icon', function (done) {
58        return MM.loginAsStudent().then(function () {
59            return MM.clickOnInSideMenu('My courses');
60        }).then(function () {
61            return MM.clickOn('Psychology in Cinema');
62        }).then(function () {
63            return MM.clickOn('Background information');
64        }).then(function () {
65            return MM.clickOn('Useful links');
66        }).then(function() {
67            expect(MM.getView().getText()).toMatch('1 A beautiful Mind');
68        }).then(function () {
69            return $('[ng-click="action(next)"]').click();
70        }).then(function() {
71            expect(MM.getView().getText()).toMatch('2 Fight Club');
72        }).then(function () {
73            return $('[ng-click="action(next)"]').click();
74        }).then(function() {
75            expect(MM.getView().getText()).toMatch('3 Spider');
76        }).then(function() {
77            return $('[ng-click="action(previous)"]').click();
78        }).then(function() {
79            return $('[ng-click="action(previous)"]').click();
80        }).then(function() {
81            expect(MM.getView().getText()).toMatch('1 A beautiful Mind');
82        }).then(function() {
83            done();
84        });
85    });
86
87    it('Click secondary button in useful links', function (done) {
88        return MM.loginAsStudent().then(function () {
89            return MM.clickOnInSideMenu('My courses');
90        }).then(function () {
91            return MM.clickOn('Psychology in Cinema');
92        }).then(function () {
93            return MM.clickOn('Background information');
94        }).then(function () {
95            return MM.clickOn('Useful links');
96        }).then(function () {
97            return $('[ng-href="http://school.demo.moodle.net/mod/book/view.php?id=707"]').click();
98        }).then(function() {
99            expect(MM.getView().getText()).toMatch('1 A beautiful Mind');
100        }).then(function () {
101            done();
102        });
103    });
104
105    it('Click secondary menu button in useful links', function (done) {
106        return MM.loginAsStudent().then(function () {
107            return MM.clickOnInSideMenu('My courses');
108        }).then(function () {
109            return MM.clickOn('Psychology in Cinema');
110        }).then(function () {
111            return MM.clickOn('Background information');
112        }).then(function () {
113            return MM.clickOn('Useful links');
114        }).then(function () {
115            return $('[ng-click="popover.show($event)"]').click();
116        }).then(function() {
117            return element(by.xpath('/html/body/div[4]/div/ion-popover-view/ion-content/div[1]/nav/ul/li[3]/a')).click();
118            expect(MM.getView().getText()).toMatch('Spider');
119        }).then(function () {
120            done();
121        });
122    });
123
124    it('Can go all the Video resources press next and previous icon', function (done) {
125        return MM.loginAsStudent().then(function () {
126            return MM.clickOnInSideMenu('My courses');
127        }).then(function () {
128            return MM.clickOn('Psychology in Cinema');
129        }).then(function () {
130            return MM.clickOn('Background information');
131        }).then(function () {
132            return MM.clickOn('Video resources');
133        }).then(function() {
134            expect(MM.getView().getText()).toMatch('1 Trailer: A beautiful mind');
135        }).then(function () {
136            return $('[ng-click="action(next)"]').click();
137        }).then(function() {
138            expect(MM.getView().getText()).toMatch('2 Trailer: Fight club');
139        }).then(function () {
140            return $('[ng-click="action(next)"]').click();
141        }).then(function() {
142            expect(MM.getView().getText()).toMatch('3 Trailer: Spider');
143        }).then(function() {
144            return $('[ng-click="action(previous)"]').click();
145        }).then(function() {
146            return $('[ng-click="action(previous)"]').click();
147        }).then(function() {
148            expect(MM.getView().getText()).toMatch('1 Trailer: A beautiful mind');
149        }).then(function() {
150            done();
151        });
152    });
153
154    it('Click secondary button in Video resources', function (done) {
155        return MM.loginAsStudent().then(function () {
156            return MM.clickOnInSideMenu('My courses');
157        }).then(function () {
158            return MM.clickOn('Psychology in Cinema');
159        }).then(function () {
160            return MM.clickOn('Background information');
161        }).then(function () {
162            return MM.clickOn('Video resources');
163        }).then(function () {
164            return $('[ng-href="http://school.demo.moodle.net/mod/book/view.php?id=708"]').click();
165        }).then(function() {
166            expect(MM.getView().getText()).toMatch('1 Trailer: A beautiful mind');
167        }).then(function () {
168            done();
169        });
170    });
171
172    it('Click secondary menu button in Video resources', function (done) {
173        return MM.loginAsStudent().then(function () {
174            return MM.clickOnInSideMenu('My courses');
175        }).then(function () {
176            return MM.clickOn('Psychology in Cinema');
177        }).then(function () {
178            return MM.clickOn('Background information');
179        }).then(function () {
180            return MM.clickOn('Video resources');
181        }).then(function () {
182            return $('[ng-click="popover.show($event)"]').click();
183        }).then(function() {
184            return element(by.xpath('/html/body/div[4]/div/ion-popover-view/ion-content/div[1]/nav/ul/li[3]/a')).click();
185            expect(MM.getView().getText()).toMatch('3 Trailer: Spider');
186        }).then(function () {
187            done();
188        });
189    });
190
191});
192
193
Full Screen

mod_forum.spec.js

Source: mod_forum.spec.js Github

copy
1// (C) Copyright 2015 Martin Dougiamas
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15describe('User can manage course forum', function() {
16
17    it('Click All sections course forum tabs', function (done) {
18        return MM.loginAsStudent().then(function () {
19            return MM.clickOnInSideMenu('My courses');
20        }).then(function () {
21            return MM.clickOn('Psychology in Cinema');
22        }).then(function () {
23            return MM.clickOn('All sections');
24        }).then(function () {
25            return MM.clickOn('Announcements from your tutor');
26        }).then(function () {
27            return MM.goBack();
28        }).then(function() {
29            done();
30        });
31    });
32
33    it('View course forum windows', function (done) {
34        return MM.loginAsStudent().then(function () {
35            return MM.clickOnInSideMenu('My courses')
36        }).then(function () {
37            return MM.clickOn('Psychology in Cinema');
38        }).then(function () {
39            return MM.clickOn('Course welcome');
40        }).then(function () {
41            return MM.clickOn('Announcements from your tutor');
42        }).then(function() {
43            expect(MM.getView().getText()).toMatch('General news and announcements');
44            expect(MM.getView().getText()).toMatch('Group Project');
45        }).then(function () {
46            return MM.clickOn('General news and announcements');
47        }).then(function () {
48            expect(MM.getView().getText()).toMatch('General news and announcements');
49        }).then(function () {
50            return MM.goBack()
51        }).then(function() {
52            done();
53        });
54    });
55
56    it('View course Forum grade test windows', function (done) {
57        return MM.loginAsStudent().then(function () {
58            return MM.clickOnInSideMenu('My courses')
59        }).then(function () {
60            return MM.clickOn('Psychology in Cinema');
61        }).then(function () {
62            return MM.clickOn('Course welcome');
63        }).then(function () {
64            return MM.clickOn('Forum grade test');
65        }).then(function() {
66            expect(MM.getView().getText()).toMatch('Add a new discussion topic');
67            expect(MM.getView().getText()).toMatch('Forum grade test');
68        }).then(function () {
69            return MM.goBack()
70        }).then(function() {
71            done();
72        });
73    });
74
75    it('Add a new discussion topic', function (done) {
76        return MM.loginAsStudent().then(function () {
77            return MM.clickOnInSideMenu('My courses')
78        }).then(function () {
79            return MM.clickOn('Psychology in Cinema');
80        }).then(function () {
81            return MM.clickOn('Course welcome');
82        }).then(function () {
83            return MM.clickOn('Forum grade test');
84        }).then(function () {
85            return MM.clickOn('Add a new discussion topic');
86        }).then(function() {
87            return $('[ng-model="newdiscussion.subject"]').sendKeys('Test Discussion Subject');
88        }).then(function() {
89            return $('[ng-model="newdiscussion.message"]').sendKeys('Test Discussion Message');
90        }).then(function() {
91            return $('[ng-click="add()"]').click();
92        }).then(function () {
93            return MM.goBack()
94        }).then(function() {
95            done();
96        });
97    });
98
99    it('Add a new Course discussion', function (done) {
100        return MM.loginAsStudent().then(function () {
101            return MM.clickOnInSideMenu('My courses')
102        }).then(function () {
103            return MM.clickOn('Psychology in Cinema');
104        }).then(function () {
105            return MM.clickOn('Analysis');
106        }).then(function () {
107            return MM.clickOn('Course discussion');
108        }).then(function () {
109            return MM.clickOn('Add a new discussion topic');
110        }).then(function() {
111            return $('[ng-model="newdiscussion.subject"]').sendKeys('Test Subject');
112        }).then(function() {
113            return $('[ng-model="newdiscussion.message"]').sendKeys('Test Message');
114        }).then(function() {
115            return $('[ng-click="add()"]').click();
116        }).then(function () {
117            return MM.goBack()
118        }).then(function() {
119            done();
120        });
121    });
122
123    it('Discussions about your group projects', function (done) {
124        return MM.loginAsStudent().then(function () {
125            return MM.clickOnInSideMenu('My courses')
126        }).then(function () {
127            return MM.clickOn('Psychology in Cinema');
128        }).then(function () {
129            return MM.clickOn('Group Projects and Individual tasks');
130        }).then(function () {
131            return MM.clickOn('Discussions about your group projects');
132        }).then(function () {
133            return MM.clickOn('Add a new discussion topic');
134        }).then(function() {
135            return $('[ng-model="newdiscussion.subject"]').sendKeys('Test Group Projects Subject');
136        }).then(function() {
137            return $('[ng-model="newdiscussion.message"]').sendKeys('Test Group Projects Message');
138        }).then(function() {
139            return $('[ng-click="add()"]').click();
140        }).then(function () {
141            return MM.goBack()
142        }).then(function() {
143            done();
144        });
145    });
146
147    it('Click secondary button', function (done) {
148        return MM.loginAsStudent().then(function () {
149            return MM.clickOnInSideMenu('My courses')
150        }).then(function () {
151            return MM.clickOn('Psychology in Cinema');
152        }).then(function () {
153            return MM.clickOn('Course welcome');
154        }).then(function () {
155            return MM.clickOn('Announcements from your tutor');
156        }).then(function () {
157            return $('.secondary-buttons').click();
158        }).then(function() {
159            return MM.goBack();
160        }).then(function () {
161            done();
162        });
163    });
164
165});
166
167
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)