webship-js 1.0.38 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/config_templates/circleci-linux-chrome.conf.js +1 -0
- package/assets/config_templates/github-linux-chrome.conf.js +1 -0
- package/examples/test--when--i-scroll-functionality.html +176 -0
- package/nightwatch.conf.js +1 -0
- package/package.json +1 -1
- package/tests/features/test--given--i-am-on-homepage.feature +2 -2
- package/tests/features/test--then--i-should--not--see-text-in-element.feature +2 -2
- package/tests/features/test--then--i-should--see-text-in-element-by-attr.feature +2 -2
- package/tests/features/test--then--i-should--see-text-in-element.feature +2 -2
- package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +4 -4
- package/tests/features/test--then--i-should--see-text-matching-pattern.feature +5 -5
- package/tests/features/test--then--i-should-be-on-page.feature +2 -2
- package/tests/features/test--then--i-should-be-on-the-homepage.feature +2 -2
- package/tests/features/test--then--i-should-not-see-an-element-by-attr.feature +2 -2
- package/tests/features/test--then--i-should-not-see-an-element.feature +2 -2
- package/tests/features/test--then--i-should-see-an-element-by-attr.feature +2 -2
- package/tests/features/test--then--i-should-see-an-element.feature +2 -2
- package/tests/features/test--then--the-checkbox-is-checked.feature +2 -2
- package/tests/features/test--then--the-checkbox-should-be-checked.feature +2 -2
- package/tests/features/test--then--the-element-should-contain-cssproperty.feature +2 -2
- package/tests/features/test--then--the-element-should-not-contain-cssproperty.feature +3 -3
- package/tests/features/test--then--the-field-should-contain-value.feature +3 -3
- package/tests/features/test--then--the-response-should-contain.feature +3 -3
- package/tests/features/test--then--the-response-status-code-should-be.feature +2 -2
- package/tests/features/test--then--the-url-should-match.feature +4 -4
- package/tests/features/test--then-the-link-should-contain-by-attribute.feature +6 -7
- package/tests/features/test--then-the-link-should-contain.feature +3 -4
- package/tests/features/test--when--i-attach-file-to-feild.feature +2 -3
- package/tests/features/test--when--i-check-checkbox.feature +2 -3
- package/tests/features/test--when--i-click-link-by-attribute.feature +2 -3
- package/tests/features/test--when--i-click-link.feature +4 -5
- package/tests/features/test--when--i-fill-in-by-attr.feature +9 -9
- package/tests/features/test--when--i-fill-in-table-by-attr.feature +6 -6
- package/tests/features/test--when--i-fill-in.feature +5 -5
- package/tests/features/test--when--i-go-to-homepage.feature +3 -6
- package/tests/features/test--when--i-move-forward-backward-one-page.feature +2 -3
- package/tests/features/test--when--i-press-button-by-attribute.feature +8 -9
- package/tests/features/test--when--i-press-button.feature +7 -3
- package/tests/features/test--when--i-reload-page.feature +2 -3
- package/tests/features/test--when--i-scroll.feature +48 -0
- package/tests/features/test--when--i-select-option-from-dropdownlist.feature +17 -6
- package/tests/features/test--when--i-wait-page-is-loaded.feature +2 -3
- package/tests/features/test--when--i-wait-time.feature +12 -13
- package/tests/step-definitions/webship.js +395 -202
- package/tests/features/test--when--i-select-option-from-dropdownlist-by-attr.feature +0 -16
|
@@ -4,70 +4,57 @@ const { Then} = require('@cucumber/cucumber');
|
|
|
4
4
|
|
|
5
5
|
const axios = require('axios');
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Opens homepage.
|
|
9
|
-
* Example: Given I am on homepage
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
Given(/^(I am|we are) on homepage$/, function (pronoundCase) {
|
|
13
|
-
return browser.url(browser.launch_url);
|
|
14
|
-
});
|
|
15
7
|
|
|
16
8
|
/**
|
|
17
9
|
* Opens homepage.
|
|
10
|
+
*
|
|
11
|
+
* Example: Given I am on homepage
|
|
18
12
|
* Example: Given I am on the homepage
|
|
19
13
|
*
|
|
20
14
|
*/
|
|
21
|
-
Given(/^(I am|we are) on the homepage$/, function (
|
|
22
|
-
return browser.url(browser.launch_url);
|
|
15
|
+
Given(/^(I am|we are) on( the)* homepage$/, function (pronounCase, theCase) {
|
|
16
|
+
return browser.url(browser.launch_url).waitForElementPresent('body', 1000);
|
|
23
17
|
});
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
|
-
* Open specific page
|
|
20
|
+
* Open specific page.
|
|
21
|
+
*
|
|
27
22
|
* Example: Given I am on "about-us.html"
|
|
28
23
|
*
|
|
29
24
|
*/
|
|
30
|
-
Given(/^(I am|we are) on "([^"]*)?"$/, function (
|
|
31
|
-
return browser.url(browser.launch_url + url);
|
|
25
|
+
Given(/^(I am|we are) on "([^"]*)?"$/, function (pronounCase, url) {
|
|
26
|
+
return browser.url(browser.launch_url + url).waitForElementPresent('body', 1000);
|
|
32
27
|
});
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
|
-
* Go to homepage
|
|
36
|
-
* Example: When I go to homepage
|
|
37
|
-
* Example: And I go to "/"
|
|
30
|
+
* Go to homepage.
|
|
38
31
|
*
|
|
39
|
-
|
|
40
|
-
When(/^(I|we)* go to homepage$/, function (pronoundCase) {
|
|
41
|
-
return browser.url(browser.launch_url);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Go to homepage
|
|
32
|
+
* Example: When I go to homepage
|
|
46
33
|
* Example: When I go to the homepage
|
|
47
|
-
* Example: And I go to the "/"
|
|
48
34
|
*
|
|
49
35
|
*/
|
|
50
|
-
When(/^(I|we)* go to the homepage$/, function (
|
|
51
|
-
return browser.url(browser.launch_url);
|
|
36
|
+
When(/^(I|we)* go to( the)* homepage$/, function (pronounCase, theCase) {
|
|
37
|
+
return browser.url(browser.launch_url).waitForElementPresent('body', 1000);
|
|
52
38
|
});
|
|
53
39
|
|
|
54
40
|
/**
|
|
55
|
-
* Go to specific page
|
|
41
|
+
* Go to specific page.
|
|
42
|
+
*
|
|
56
43
|
* Example: When I go to "contact-us.html"
|
|
57
44
|
*
|
|
58
45
|
*/
|
|
59
|
-
When(/^(I|we)* go to "([^"]*)?"$/, function (
|
|
60
|
-
return browser.url(browser.launch_url + url);
|
|
46
|
+
When(/^(I|we)* go to "([^"]*)?"$/, function (pronounCase, url) {
|
|
47
|
+
return browser.url(browser.launch_url + url).waitForElementPresent('body', 1000);
|
|
61
48
|
});
|
|
62
49
|
|
|
63
50
|
/**
|
|
64
51
|
* Asserting a text in the page.
|
|
65
|
-
*
|
|
52
|
+
*
|
|
66
53
|
* Example:
|
|
67
54
|
* - Then I should see "Welcome"
|
|
68
55
|
*
|
|
69
56
|
*/
|
|
70
|
-
Then(/^(I|we)* should see "([^"]*)?"$/, function (
|
|
57
|
+
Then(/^(I|we)* should see "([^"]*)?"$/, function (pronounCase, expectedText) {
|
|
71
58
|
return this.shouldSee = function (browser) {
|
|
72
59
|
browser.assert.textContains("html", expectedText);
|
|
73
60
|
};
|
|
@@ -75,55 +62,60 @@ Then(/^(I|we)* should see "([^"]*)?"$/, function (pronoundCase, expectedText) {
|
|
|
75
62
|
|
|
76
63
|
/**
|
|
77
64
|
* Asserting a text not in the page.
|
|
78
|
-
*
|
|
65
|
+
*
|
|
79
66
|
* Example:
|
|
80
67
|
* - Then I should not see "Access denied"
|
|
81
68
|
*
|
|
82
69
|
*/
|
|
83
|
-
Then(/^(I|we)* should not see "([^"]*)?"$/, function (
|
|
70
|
+
Then(/^(I|we)* should not see "([^"]*)?"$/, function (pronounCase, expectedText) {
|
|
84
71
|
return this.shouldSee = function (browser) {
|
|
85
72
|
browser.assert.not.textContains("html", expectedText);
|
|
86
73
|
};
|
|
87
74
|
});
|
|
88
75
|
|
|
89
76
|
/**
|
|
90
|
-
* Moves forward one page in browser history
|
|
77
|
+
* Moves forward one page in browser history.
|
|
78
|
+
*
|
|
91
79
|
* Example: When I move forward one page
|
|
92
80
|
*
|
|
93
81
|
*/
|
|
94
|
-
When(/^(I|we)* move forward one page$/, function (
|
|
82
|
+
When(/^(I|we)* move forward one page$/, function (pronounCase) {
|
|
95
83
|
return browser.forward();
|
|
96
84
|
});
|
|
97
85
|
|
|
98
86
|
/**
|
|
99
|
-
* Moves backward one page in browser history
|
|
87
|
+
* Moves backward one page in browser history.
|
|
88
|
+
*
|
|
100
89
|
* Example: When I move backward one page
|
|
101
90
|
*
|
|
102
91
|
*/
|
|
103
|
-
When(/^(I|we)* move backward one page$/, function (
|
|
92
|
+
When(/^(I|we)* move backward one page$/, function (pronounCase) {
|
|
104
93
|
return browser.back();
|
|
105
94
|
});
|
|
106
95
|
|
|
107
96
|
/**
|
|
108
|
-
* Presses button with specified element
|
|
97
|
+
* Presses button with specified element.
|
|
98
|
+
*
|
|
109
99
|
* Example: When I press "Log In"
|
|
110
|
-
* Example: And I press "Log In"
|
|
100
|
+
* Example: And I press the "Log In" button
|
|
101
|
+
* Example: And I press the "Save as" button
|
|
111
102
|
*
|
|
112
103
|
*/
|
|
113
|
-
When(/^(I|we)* press "([^"]*)?"
|
|
104
|
+
When(/^(I|we)* press( the)* "([^"]*)?"( button)*$/, function (pronounCase, theCase, element, buttonCase) {
|
|
114
105
|
browser.click("[value='" + element +"']");
|
|
115
106
|
});
|
|
116
107
|
|
|
117
108
|
/**
|
|
118
|
-
* Presses button with specified element
|
|
109
|
+
* Presses button with specified element.
|
|
110
|
+
*
|
|
119
111
|
* Example: When I press "btn-pressid" by attr
|
|
120
112
|
* Example: When I press "btn-pressid" by attribute
|
|
121
113
|
* Example: And I press "Your full name" by "placeholder" attribute
|
|
122
114
|
* Example: And I press "Your full name" by its "placeholder" attribute
|
|
123
|
-
* Example: And I press "save-name" by "data-
|
|
115
|
+
* Example: And I press "save-name" by "data-selector" attr
|
|
124
116
|
*
|
|
125
117
|
*/
|
|
126
|
-
When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
118
|
+
When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
|
|
127
119
|
|
|
128
120
|
const hasASpace = attrValue.indexOf(' ');
|
|
129
121
|
var selector = '';
|
|
@@ -145,24 +137,26 @@ When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, func
|
|
|
145
137
|
});
|
|
146
138
|
|
|
147
139
|
/**
|
|
148
|
-
* Clicks link with specified element
|
|
140
|
+
* Clicks link with specified element.
|
|
141
|
+
*
|
|
149
142
|
* Example: When I click "Contact Us"
|
|
150
143
|
* Example: And I click "aboutUs"
|
|
151
144
|
*
|
|
152
145
|
*/
|
|
153
|
-
When(/^(I|we)* click "([^"]*)?"$/, function (
|
|
146
|
+
When(/^(I|we)* click "([^"]*)?"$/, function (pronounCase, item) {
|
|
154
147
|
return browser.click("link text", item);
|
|
155
148
|
});
|
|
156
149
|
|
|
157
150
|
/**
|
|
158
|
-
* Click Link with specified element
|
|
151
|
+
* Click Link with specified element.
|
|
152
|
+
*
|
|
159
153
|
* Example: When I click "#aboutUsid" by attr
|
|
160
154
|
* Example: When I click "aboutUsCss" by attribute
|
|
161
155
|
* Example: And I click "aboutUsCss" by "class" attr
|
|
162
156
|
* Example: And I click "aboutUsid" by its "id" attribute
|
|
163
157
|
*
|
|
164
158
|
*/
|
|
165
|
-
When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
159
|
+
When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
|
|
166
160
|
|
|
167
161
|
const hasASpace = attrValue.indexOf(' ');
|
|
168
162
|
var selector = '';
|
|
@@ -185,48 +179,51 @@ When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, func
|
|
|
185
179
|
});
|
|
186
180
|
|
|
187
181
|
/**
|
|
188
|
-
* Reloads current page
|
|
182
|
+
* Reloads current page.
|
|
183
|
+
*
|
|
189
184
|
* Example: When I reload page
|
|
190
185
|
* Example: And I reload page
|
|
191
186
|
*
|
|
192
187
|
*/
|
|
193
188
|
|
|
194
|
-
When(/^(I|we)* reload page$/, function (
|
|
189
|
+
When(/^(I|we)* reload page$/, function (pronounCase) {
|
|
195
190
|
return browser.refresh(browser.getCurrentUrl());
|
|
196
191
|
});
|
|
197
192
|
|
|
198
193
|
/**
|
|
199
|
-
* Reloads current page
|
|
194
|
+
* Reloads current page.
|
|
195
|
+
*
|
|
200
196
|
* Example: When I reload the page
|
|
201
197
|
* Example: And I reload the page
|
|
202
198
|
*
|
|
203
199
|
*/
|
|
204
|
-
When(/^(I|we)* reload the page$/, function (
|
|
200
|
+
When(/^(I|we)* reload( the)* page$/, function (pronounCase, theCase) {
|
|
205
201
|
return browser.refresh(browser.getCurrentUrl());
|
|
206
202
|
});
|
|
207
203
|
|
|
208
|
-
|
|
209
204
|
/**
|
|
210
205
|
* Define the step of filling values in the form field specified element.
|
|
206
|
+
*
|
|
211
207
|
* Example: When I fill in "Username" with "John Smith"
|
|
212
208
|
*
|
|
213
209
|
*/
|
|
214
|
-
When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (
|
|
215
|
-
const elementField = browser.element.findByText(field);
|
|
210
|
+
When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronounCase, field, value) {
|
|
211
|
+
const elementField = browser.element.findByText(field, { exact: true });
|
|
216
212
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
217
213
|
return browser.setValue('#' + eleAttribute.value, value);
|
|
218
214
|
});
|
|
219
215
|
});
|
|
220
216
|
|
|
221
217
|
/**
|
|
222
|
-
* Fill input type text with value by its attribute
|
|
218
|
+
* Fill input type text with value by its attribute.
|
|
219
|
+
*
|
|
223
220
|
* Example: When I fill in "#uname" by attr
|
|
224
221
|
* Example: When I fill in "uname" with "John Smith" by attr
|
|
225
222
|
* Example: And I fill in "pwordcss" with "1234" by "class" attr
|
|
226
223
|
* Example: And I fill in "Your full name" with "John Smith" by its "placeholder" attribute
|
|
227
224
|
*
|
|
228
225
|
*/
|
|
229
|
-
When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
226
|
+
When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, txtValue, itsCase, attr, attrCase) {
|
|
230
227
|
|
|
231
228
|
const hasASpace = attrValue.indexOf(' ');
|
|
232
229
|
var selector = '';
|
|
@@ -249,26 +246,28 @@ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attri
|
|
|
249
246
|
});
|
|
250
247
|
|
|
251
248
|
/**
|
|
252
|
-
* Fill input type text with empty value by its Label
|
|
249
|
+
* Fill input type text with empty value by its Label.
|
|
250
|
+
*
|
|
253
251
|
* Example: When I fill in "Username" with:
|
|
254
252
|
*
|
|
255
253
|
*/
|
|
256
|
-
When(/^(I|we)* fill in "([^"]*)?" with:$/, function (
|
|
257
|
-
const elementField = browser.element.findByText(field);
|
|
254
|
+
When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronounCase, field) {
|
|
255
|
+
const elementField = browser.element.findByText(field, { exact: true });
|
|
258
256
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
259
257
|
return browser.setValue('#' + eleAttribute.value, '');
|
|
260
258
|
});
|
|
261
259
|
});
|
|
262
260
|
|
|
263
261
|
/**
|
|
264
|
-
* Fill input type text with empty value by its attribute
|
|
262
|
+
* Fill input type text with empty value by its attribute.
|
|
263
|
+
*
|
|
265
264
|
* Example: When I fill in "#uname" with: by attr
|
|
266
265
|
* Example: When I fill in "uname" with: by attr
|
|
267
266
|
* Example: And I fill in "pwordcss" with: by "class" attr
|
|
268
267
|
* Example: And I fill in "Your full name" with: by its "placeholder" attribute
|
|
269
268
|
*
|
|
270
269
|
*/
|
|
271
|
-
When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
270
|
+
When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue , itsCase, attr, attrCase) {
|
|
272
271
|
|
|
273
272
|
const hasASpace = attrValue.indexOf(' ');
|
|
274
273
|
var selector = '';
|
|
@@ -290,26 +289,28 @@ When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)
|
|
|
290
289
|
});
|
|
291
290
|
|
|
292
291
|
/**
|
|
293
|
-
* Fill in value for input type text by its Label
|
|
294
|
-
*
|
|
292
|
+
* Fill in value for input type text by its Label.
|
|
293
|
+
*
|
|
294
|
+
* Example: When I fill in "jon-smith" for "Username"
|
|
295
295
|
*
|
|
296
296
|
*/
|
|
297
|
-
When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (
|
|
298
|
-
const elementField = browser.element.findByText(field);
|
|
297
|
+
When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronounCase, value, field) {
|
|
298
|
+
const elementField = browser.element.findByText(field, { exact: true });
|
|
299
299
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
300
300
|
return browser.setValue('#' + eleAttribute.value, value);
|
|
301
301
|
});
|
|
302
302
|
});
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
|
-
* Fill in value for input type text by its attribute
|
|
305
|
+
* Fill in value for input type text by its attribute.
|
|
306
|
+
*
|
|
306
307
|
* Example: When I fill in "John Smith" for "#uname" by attr
|
|
307
308
|
* Example: When I fill in "John Smith" for "uname" by attr
|
|
308
309
|
* Example: And I fill in "1234" for "pwordcss" by "class" attr
|
|
309
310
|
* Example: And I fill in "John Smith" for "Your full name" by its "placeholder" attribute
|
|
310
311
|
*
|
|
311
312
|
*/
|
|
312
|
-
When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
313
|
+
When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, txtValue, attrValue, itsCase, attr, attrCase) {
|
|
313
314
|
|
|
314
315
|
const hasASpace = attrValue.indexOf(' ');
|
|
315
316
|
var selector = '';
|
|
@@ -332,22 +333,23 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attrib
|
|
|
332
333
|
});
|
|
333
334
|
|
|
334
335
|
/**
|
|
335
|
-
* Fills in form input fields type text with provided table by there labels
|
|
336
|
+
* Fills in form input fields type text with provided table by there labels.
|
|
337
|
+
*
|
|
336
338
|
* Example: When I fill in the following:
|
|
337
339
|
* | Username | webshipco |
|
|
338
340
|
* | Password | 1234 |
|
|
339
341
|
*/
|
|
340
342
|
|
|
341
|
-
When(/^(I|we)* fill in the following:$/, function (
|
|
343
|
+
When(/^(I|we)* fill in( the)* following:$/, function (pronounCase, theCase, table) {
|
|
342
344
|
|
|
343
|
-
var elementField = browser.element.findByText(table.rawTable[0][0]);
|
|
345
|
+
var elementField = browser.element.findByText(table.rawTable[0][0], { exact: true });
|
|
344
346
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
345
347
|
browser.setValue('#' + eleAttribute.value, table.rawTable[0][1]);
|
|
346
348
|
});
|
|
347
349
|
|
|
348
350
|
table.rows().forEach(row => {
|
|
349
351
|
|
|
350
|
-
elementField = browser.element.findByText(row[0]);
|
|
352
|
+
elementField = browser.element.findByText(row[0], { exact: true });
|
|
351
353
|
browser.getAttribute(elementField, 'for', function (eleAttribute2) {
|
|
352
354
|
browser.setValue('#' + eleAttribute2.value, row[1]);
|
|
353
355
|
});
|
|
@@ -355,17 +357,18 @@ When(/^(I|we)* fill in the following:$/, function (pronoundCase, table) {
|
|
|
355
357
|
});
|
|
356
358
|
|
|
357
359
|
/**
|
|
358
|
-
* Fill in value for input type text by its attributeFill form fields of type
|
|
360
|
+
* Fill in value for input type text by its attributeFill form fields of type
|
|
361
|
+
* input Text with the provided table according to their attributes.
|
|
362
|
+
*
|
|
359
363
|
* Example: When I fill in the following: by attr
|
|
360
364
|
* | #uname | John Smith |
|
|
361
365
|
* | pwordcss | 1234 |
|
|
362
|
-
|
|
366
|
+
*
|
|
363
367
|
* Example: When I fill in the following: by its "placeholder" attribute
|
|
364
368
|
* | Your full name | John Smith |
|
|
365
369
|
* | Your Password | 1234 |
|
|
366
370
|
*/
|
|
367
|
-
|
|
368
|
-
When(/^(I|we)* fill in the following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, itsCase, attr, attrCase, table) {
|
|
371
|
+
When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, theCase, itsCase, attr, attrCase, table) {
|
|
369
372
|
|
|
370
373
|
var hasASpace = table.rawTable[0][0].indexOf(' ');
|
|
371
374
|
var selector = '';
|
|
@@ -413,136 +416,121 @@ When(/^(I|we)* fill in the following: by( its)*( "([^"]*)?")* (attribute|attr)$/
|
|
|
413
416
|
/**
|
|
414
417
|
* Selecting the option in the dropdown list field by its text label
|
|
415
418
|
* Example: When I select "Mercedes" from "Cars"
|
|
419
|
+
* Example: When I select "saab" from "#cars"
|
|
420
|
+
* Example: When I select "Mercedes" from "cars"
|
|
416
421
|
*
|
|
417
422
|
*/
|
|
418
|
-
When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (
|
|
423
|
+
When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, option, selectList) {
|
|
419
424
|
|
|
420
|
-
const
|
|
421
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
422
|
-
return browser.waitForElementVisible('css selector', '#' + eleAttribute.value)
|
|
423
|
-
.click('#' + eleAttribute.value)
|
|
424
|
-
.click(browser.element.findByText(option))
|
|
425
|
-
.click('#' + eleAttribute.value);
|
|
426
|
-
});
|
|
427
|
-
});
|
|
425
|
+
const hasASpace = selectList.indexOf(' ');
|
|
428
426
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
* Example: When I select "Saab" from "#cars" by attr
|
|
433
|
-
*
|
|
434
|
-
*/
|
|
435
|
-
|
|
436
|
-
When(/^(I|we)* select "([^"]*)?" from "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, option, attrValue, itsCase, attr, attrCase) {
|
|
437
|
-
|
|
438
|
-
const hasASpace = attrValue.indexOf(' ');
|
|
439
|
-
|
|
440
|
-
var selector = '';
|
|
441
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
442
|
-
selector = attrValue;
|
|
443
|
-
}
|
|
444
|
-
else if (!attr && hasASpace == -1){
|
|
445
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
427
|
+
let selector = '';
|
|
428
|
+
if((selectList.startsWith('#') || selectList.startsWith('.'))){
|
|
429
|
+
selector = selectList;
|
|
446
430
|
}
|
|
447
|
-
else if (
|
|
448
|
-
selector ='[
|
|
431
|
+
else if (hasASpace == -1){
|
|
432
|
+
selector = '[name="' + selectList + '"],[id="' + selectList + '"],[class="' + selectList + '"]';
|
|
449
433
|
}
|
|
450
434
|
else {
|
|
451
|
-
selector =
|
|
435
|
+
selector = browser.element.findByText(selectList, { exact: true });
|
|
452
436
|
}
|
|
453
437
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
438
|
+
let optionValue = '';
|
|
439
|
+
const result = option.toLowerCase();
|
|
440
|
+
|
|
441
|
+
if(result == option){
|
|
442
|
+
optionValue = '[value="' + option + '"]';
|
|
443
|
+
}
|
|
444
|
+
else{
|
|
445
|
+
optionValue = browser.element.findByText(option, { exact: true });
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return browser.click(selector).click(optionValue).click(selector);
|
|
458
449
|
});
|
|
459
450
|
|
|
460
451
|
/**
|
|
461
|
-
* Checks checkbox specified
|
|
452
|
+
* Checks checkbox specified.
|
|
453
|
+
*
|
|
462
454
|
* Example: When I check "Remember me"
|
|
463
455
|
*
|
|
464
456
|
*/
|
|
465
|
-
When(/^(I|we)* check "([^"]*)?"$/, function (
|
|
466
|
-
|
|
457
|
+
When(/^(I|we)* check "([^"]*)?"$/, function (pronounCase, item) {
|
|
467
458
|
browser.checkItem(item);
|
|
468
459
|
});
|
|
469
460
|
|
|
470
461
|
/**
|
|
471
|
-
* Unchecks checkbox specified
|
|
462
|
+
* Unchecks checkbox specified.
|
|
463
|
+
*
|
|
472
464
|
* Example: When I uncheck "Remember me"
|
|
473
465
|
*
|
|
474
466
|
*/
|
|
475
|
-
When(/^(I|we)* uncheck "([^"]*)?"$/, function (
|
|
476
|
-
|
|
467
|
+
When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronounCase, item) {
|
|
477
468
|
browser.uncheckItem(item);
|
|
478
469
|
});
|
|
479
470
|
|
|
480
471
|
/**
|
|
481
|
-
* Verify, that current page is the homepage
|
|
482
|
-
* Example: Then I should be on homepage
|
|
472
|
+
* Verify, that current page is the homepage.
|
|
483
473
|
*
|
|
484
|
-
|
|
485
|
-
Then(/^(I|we)* should be on homepage$/, function (pronoundCase) {
|
|
486
|
-
return browser.assert.urlMatches(browser.launch_url);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Verify, that current page is the homepage
|
|
474
|
+
* Example: Then I should be on homepage
|
|
491
475
|
* Example: Then I should be on the homepage
|
|
492
476
|
*
|
|
493
477
|
*/
|
|
494
|
-
Then(/^(I|we)* should be on the homepage$/, function (
|
|
478
|
+
Then(/^(I|we)* should be on( the)* homepage$/, function (pronounCase, theCase) {
|
|
495
479
|
return browser.assert.urlMatches(browser.launch_url);
|
|
496
480
|
});
|
|
497
481
|
|
|
498
482
|
/**
|
|
499
|
-
* Verify, that current page is the homepage
|
|
483
|
+
* Verify, that current page is the homepage.
|
|
484
|
+
*
|
|
500
485
|
* Example: Then I should not be on homepage
|
|
501
486
|
*
|
|
502
487
|
*/
|
|
503
|
-
Then(/^(I|we)* should not be on homepage$/, function (
|
|
488
|
+
Then(/^(I|we)* should not be on homepage$/, function (pronounCase) {
|
|
504
489
|
return browser.assert.not.urlMatches(browser.launch_url);
|
|
505
490
|
});
|
|
506
491
|
|
|
507
492
|
/**
|
|
508
|
-
* Verify, that current page is the homepage
|
|
493
|
+
* Verify, that current page is the homepage.
|
|
494
|
+
*
|
|
509
495
|
* Example: Then I should not be on the homepage
|
|
510
496
|
*
|
|
511
497
|
*/
|
|
512
|
-
Then(/^(I|we)* should not be on the homepage$/, function (
|
|
498
|
+
Then(/^(I|we)* should not be on( the)* homepage$/, function (pronounCase, theCase) {
|
|
513
499
|
return browser.assert.not.urlMatches(browser.launch_url);
|
|
514
500
|
});
|
|
515
501
|
|
|
516
502
|
/**
|
|
517
|
-
* Verify, that current page path is equal to specified path
|
|
503
|
+
* Verify, that current page path is equal to specified path.
|
|
504
|
+
*
|
|
518
505
|
* Example: Then I should be on "/"
|
|
519
506
|
* Example: And I should be on "/user/login"
|
|
520
507
|
* Example: And I should be on "http://google.com"
|
|
521
508
|
*
|
|
522
509
|
*/
|
|
523
|
-
|
|
524
|
-
Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronoundCase, url) {
|
|
510
|
+
Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronounCase, url) {
|
|
525
511
|
return browser.assert.urlContains(url);
|
|
526
512
|
});
|
|
527
513
|
|
|
528
514
|
/**
|
|
529
515
|
* Verify, that the current link contains the specified URL.
|
|
516
|
+
*
|
|
530
517
|
* Example: Then the "Login" link should contain "/log-in"
|
|
531
518
|
*
|
|
532
519
|
*/
|
|
533
|
-
Then(/^the "([^"]*)?" link should contain "([^"]*)?"$/, function (element, url) {
|
|
520
|
+
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, element, url) {
|
|
534
521
|
const elementField = browser.element.findByText(element, { exact: true });
|
|
535
522
|
return browser.assert.attributeContains(elementField, 'href', url);
|
|
536
523
|
});
|
|
537
524
|
|
|
538
525
|
/**
|
|
539
526
|
* Verify, that the current link contains the specified URL, found by its attributes.
|
|
527
|
+
*
|
|
540
528
|
* Example: Then the "#aboutUsid" link should contain "about" by attr
|
|
541
529
|
* Example: And the "aboutUs" link should contain "about" by its "class" attribute
|
|
542
530
|
* Example: And the ".contactUs" link should contain "/contact-" by attr
|
|
543
531
|
*
|
|
544
532
|
*/
|
|
545
|
-
Then(/^the "([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (attrValue, url, itsCase, attr, attrCase) {
|
|
533
|
+
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (theCase, attrValue, url, itsCase, attr, attrCase) {
|
|
546
534
|
|
|
547
535
|
const hasASpace = attrValue.indexOf(' ');
|
|
548
536
|
var selector = '';
|
|
@@ -564,22 +552,24 @@ Then(/^the "([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (at
|
|
|
564
552
|
});
|
|
565
553
|
|
|
566
554
|
/**
|
|
567
|
-
* Checks, that HTML response contains specific text
|
|
555
|
+
* Checks, that HTML response contains specific text.
|
|
556
|
+
*
|
|
568
557
|
* Example: Then the response should contain "Welcome visitor, How can I help you?"
|
|
569
558
|
*
|
|
570
559
|
*/
|
|
571
|
-
Then(/^the response should contain "([^"]*)?"$/, function (expectedText) {
|
|
560
|
+
Then(/^(the )*response should contain "([^"]*)?"$/, function (theCase, expectedText) {
|
|
572
561
|
return this.shouldSee = function (browser) {
|
|
573
562
|
browser.assert.textContains("html", expectedText);
|
|
574
563
|
};
|
|
575
564
|
});
|
|
576
565
|
|
|
577
566
|
/**
|
|
578
|
-
* Checks, that HTML response contains specific text
|
|
567
|
+
* Checks, that HTML response contains specific text.
|
|
568
|
+
*
|
|
579
569
|
* Example: Then the response should not contain "Error: Ambiguous messages that are unclear"
|
|
580
570
|
*
|
|
581
571
|
*/
|
|
582
|
-
Then(/^the response should not contain "([^"]*)?"$/, function (expectedText) {
|
|
572
|
+
Then(/^(the )*response should not contain "([^"]*)?"$/, function (theCase, expectedText) {
|
|
583
573
|
return this.shouldSee = function (browser) {
|
|
584
574
|
browser.assert.not.textContains("html", expectedText);
|
|
585
575
|
};
|
|
@@ -587,12 +577,13 @@ Then(/^the response should not contain "([^"]*)?"$/, function (expectedText) {
|
|
|
587
577
|
|
|
588
578
|
|
|
589
579
|
/**
|
|
590
|
-
* Assert, that input text contains a specific value by its label
|
|
580
|
+
* Assert, that input text contains a specific value by its label.
|
|
581
|
+
*
|
|
591
582
|
* Example: Then I should see "John Smith" in the "Username" element
|
|
592
583
|
*
|
|
593
584
|
*/
|
|
594
|
-
Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element$/, function (
|
|
595
|
-
const elementField = browser.element.findByText(element);
|
|
585
|
+
Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText,theCase , element) {
|
|
586
|
+
const elementField = browser.element.findByText(element, { exact: true });
|
|
596
587
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
597
588
|
return this.shouldSee = function (browser) {
|
|
598
589
|
browser.assert.textContains('#' + eleAttribute.value, expectedText);
|
|
@@ -601,12 +592,13 @@ Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element$/, function (pron
|
|
|
601
592
|
});
|
|
602
593
|
|
|
603
594
|
/**
|
|
604
|
-
* Assert, that input text contains a specific value by its attributes
|
|
595
|
+
* Assert, that input text contains a specific value by its attributes.
|
|
596
|
+
*
|
|
605
597
|
* Example: Then I should see "John Smith" in the "uname" element by its "id" attr
|
|
606
598
|
* Example: Then I should see "1234" in the "pwordcss" element by attr
|
|
607
599
|
*
|
|
608
600
|
*/
|
|
609
|
-
Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
601
|
+
Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
|
|
610
602
|
|
|
611
603
|
const hasASpace = attrValue.indexOf(' ');
|
|
612
604
|
|
|
@@ -627,13 +619,14 @@ Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element by( its)*( "([^"]
|
|
|
627
619
|
});
|
|
628
620
|
|
|
629
621
|
/**
|
|
630
|
-
* Assert, that input text does not contain a specific value to be by its label
|
|
622
|
+
* Assert, that input text does not contain a specific value to be by its label.
|
|
623
|
+
*
|
|
631
624
|
* Example: Then I should not see "Joe Smith" in the "Username" element
|
|
632
625
|
*
|
|
633
626
|
*/
|
|
634
|
-
Then(/^(I|we)* should not see "([^"]*)?" in the "([^"]*)?" element$/, function (
|
|
627
|
+
Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase, element) {
|
|
635
628
|
|
|
636
|
-
const elementField = browser.element.findByText(element);
|
|
629
|
+
const elementField = browser.element.findByText(element, { exact: true });
|
|
637
630
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
638
631
|
return this.shouldSee = function (browser) {
|
|
639
632
|
browser.assert.not.textContains('#' + eleAttribute.value, expectedText);
|
|
@@ -642,12 +635,13 @@ Then(/^(I|we)* should not see "([^"]*)?" in the "([^"]*)?" element$/, function (
|
|
|
642
635
|
});
|
|
643
636
|
|
|
644
637
|
/**
|
|
645
|
-
* Assert, that input text contains a specific value by its attributes
|
|
638
|
+
* Assert, that input text contains a specific value by its attributes.
|
|
639
|
+
*
|
|
646
640
|
* Example: Then I should not see "John Smith" in the "uname" element by its "id" attr
|
|
647
641
|
* Example: Then I should not see "1234" in the "pwordcss" element by attr
|
|
648
642
|
*
|
|
649
643
|
*/
|
|
650
|
-
Then(/^(I|we)* should not see "([^"]*)?" in the "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
644
|
+
Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
|
|
651
645
|
|
|
652
646
|
const hasASpace = attrValue.indexOf(' ');
|
|
653
647
|
|
|
@@ -668,11 +662,12 @@ Then(/^(I|we)* should not see "([^"]*)?" in the "([^"]*)?" element by( its)*( "(
|
|
|
668
662
|
});
|
|
669
663
|
|
|
670
664
|
/**
|
|
671
|
-
* Assert, that element exists on current page by its label
|
|
665
|
+
* Assert, that element exists on current page by its label.
|
|
666
|
+
*
|
|
672
667
|
* Example: Then I should see a "Username" element
|
|
673
668
|
*
|
|
674
669
|
*/
|
|
675
|
-
Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (
|
|
670
|
+
Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
|
|
676
671
|
const elementField = browser.element.findByText(element, { exact: true });
|
|
677
672
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
678
673
|
return browser.verify.visible('#' + eleAttribute.value);
|
|
@@ -680,12 +675,13 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronoundCase, a
|
|
|
680
675
|
});
|
|
681
676
|
|
|
682
677
|
/**
|
|
683
|
-
* Assert, that element exists on the current page by its attribute
|
|
678
|
+
* Assert, that element exists on the current page by its attribute.
|
|
679
|
+
*
|
|
684
680
|
* Example: Then I should see a "uname" element by its "id" attr
|
|
685
681
|
* Example: Then I should see a "pwordcss" element by attr
|
|
686
682
|
*
|
|
687
683
|
*/
|
|
688
|
-
Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
684
|
+
Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
|
|
689
685
|
|
|
690
686
|
const hasASpace = attrValue.indexOf(' ');
|
|
691
687
|
|
|
@@ -704,22 +700,23 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (att
|
|
|
704
700
|
});
|
|
705
701
|
|
|
706
702
|
/**
|
|
707
|
-
* Assert, that element exists on current page by its label
|
|
703
|
+
* Assert, that element exists on current page by its label.
|
|
704
|
+
*
|
|
708
705
|
* Example: Then I should not see a "Username" element
|
|
709
706
|
*
|
|
710
707
|
*/
|
|
711
|
-
Then(/^(I|we)* should not see (a|an) "([^"]*)?" element$/, function (
|
|
712
|
-
|
|
708
|
+
Then(/^(I|we)* should not see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
|
|
713
709
|
browser.assert.not.textContains("html", element);
|
|
714
710
|
});
|
|
715
711
|
|
|
716
712
|
/**
|
|
717
|
-
* Assert, that element exists on current page by its attributes
|
|
713
|
+
* Assert, that element exists on current page by its attributes.
|
|
714
|
+
*
|
|
718
715
|
* Example: Then I should not see an "emailId" element by its "id" attr
|
|
719
716
|
* Example: And I should not see a "countryCss" element by attr
|
|
720
717
|
*
|
|
721
718
|
*/
|
|
722
|
-
Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (
|
|
719
|
+
Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
|
|
723
720
|
|
|
724
721
|
const hasASpace = attrValue.indexOf(' ');
|
|
725
722
|
|
|
@@ -738,11 +735,12 @@ Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")*
|
|
|
738
735
|
});
|
|
739
736
|
|
|
740
737
|
/**
|
|
741
|
-
* Assert, that element contains a specific CSS style
|
|
738
|
+
* Assert, that element contains a specific CSS style.
|
|
739
|
+
*
|
|
742
740
|
* Example: Then the "body" element should contain "color:white;"
|
|
743
741
|
*
|
|
744
742
|
*/
|
|
745
|
-
Then(/^the "([^"]*)?" element should contain "([^"]*)?"$/, function (selector, elementCss) {
|
|
743
|
+
Then(/^(the )*"([^"]*)?" element should contain "([^"]*)?"$/, function (theCase ,selector, elementCss) {
|
|
746
744
|
|
|
747
745
|
elementCss = elementCss.replace(";", '');
|
|
748
746
|
const cssPropertyArr = elementCss.split(":");
|
|
@@ -756,12 +754,13 @@ Then(/^the "([^"]*)?" element should contain "([^"]*)?"$/, function (selector, e
|
|
|
756
754
|
});
|
|
757
755
|
|
|
758
756
|
/**
|
|
759
|
-
* Assert, that element contains a specific CSS style
|
|
757
|
+
* Assert, that element contains a specific CSS style.
|
|
758
|
+
*
|
|
760
759
|
* Example: Then the "body" element should not contain "color:white;"
|
|
761
760
|
* Example: Then the "#uname" element should not contain "border:solid 5px red;"
|
|
762
761
|
* Example: Then the "pword" element should not contain "font-size: 26px;"
|
|
763
762
|
*/
|
|
764
|
-
Then(/^the "([^"]*)?" element should not contain "([^"]*)?"$/, function (selector, elementCss) {
|
|
763
|
+
Then(/^(the )*"([^"]*)?" element should not contain "([^"]*)?"$/, function (theCase, selector, elementCss) {
|
|
765
764
|
|
|
766
765
|
elementCss = elementCss.replace(";", '');
|
|
767
766
|
const cssPropertyArr = elementCss.split(":");
|
|
@@ -775,11 +774,12 @@ Then(/^the "([^"]*)?" element should not contain "([^"]*)?"$/, function (selecto
|
|
|
775
774
|
});
|
|
776
775
|
|
|
777
776
|
/**
|
|
778
|
-
* Attaches file to field
|
|
777
|
+
* Attaches file to field.
|
|
778
|
+
*
|
|
779
779
|
* Example: When I attach the file "profileIcon.jpg" to "#profileIconUpload"
|
|
780
780
|
*
|
|
781
781
|
*/
|
|
782
|
-
When(/^(I|we)* attach the file "([^"]*)?" to "([^"]*)?"$/, function (
|
|
782
|
+
When(/^(I|we)* attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronounCase, theCase, fileUrl, element) {
|
|
783
783
|
var dirname = __dirname + '';
|
|
784
784
|
dirname = dirname.substring(0, dirname.lastIndexOf("/"));
|
|
785
785
|
|
|
@@ -787,13 +787,14 @@ When(/^(I|we)* attach the file "([^"]*)?" to "([^"]*)?"$/, function (pronoundCas
|
|
|
787
787
|
});
|
|
788
788
|
|
|
789
789
|
/**
|
|
790
|
-
* Assert, that field contain a specific text
|
|
790
|
+
* Assert, that field contain a specific text.
|
|
791
|
+
*
|
|
791
792
|
* Example: Then the "Username" field should contain "John Smith"
|
|
792
793
|
*
|
|
793
794
|
*/
|
|
794
|
-
Then(/^the "([^"]*)?" field should contain "([^"]*)?"$/, function (field, expectedText) {
|
|
795
|
+
Then(/^(the )*"([^"]*)?" field should contain "([^"]*)?"$/, function (theCase, field, expectedText) {
|
|
795
796
|
|
|
796
|
-
const elementField = browser.element.findByText(field);
|
|
797
|
+
const elementField = browser.element.findByText(field, { exact: true });
|
|
797
798
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
798
799
|
return this.shouldSee = function (browser) {
|
|
799
800
|
browser.assert.textContains('#' + eleAttribute.value, expectedText);
|
|
@@ -802,11 +803,12 @@ Then(/^the "([^"]*)?" field should contain "([^"]*)?"$/, function (field, expect
|
|
|
802
803
|
});
|
|
803
804
|
|
|
804
805
|
/**
|
|
805
|
-
* Assert, that field does not contain a specific text
|
|
806
|
+
* Assert, that field does not contain a specific text.
|
|
807
|
+
*
|
|
806
808
|
* Example: Then the "#username" field should not contain "John Smith"
|
|
807
809
|
*
|
|
808
810
|
*/
|
|
809
|
-
Then(/^the "([^"]*)?" field should not contain "([^"]*)?"$/, function (field, expectedText) {
|
|
811
|
+
Then(/^(the )*"([^"]*)?" field should not contain "([^"]*)?"$/, function (theCase, field, expectedText) {
|
|
810
812
|
|
|
811
813
|
return this.shouldSee = function (browser) {
|
|
812
814
|
browser.assert.not.textContains(field, expectedText);
|
|
@@ -814,134 +816,148 @@ Then(/^the "([^"]*)?" field should not contain "([^"]*)?"$/, function (field, ex
|
|
|
814
816
|
});
|
|
815
817
|
|
|
816
818
|
/**
|
|
817
|
-
* Assert, that checkbox with specified element is should be checked
|
|
819
|
+
* Assert, that checkbox with specified element is should be checked.
|
|
820
|
+
*
|
|
818
821
|
* Example: Then the "#PrivacyPolicy" checkbox should be checked
|
|
819
822
|
*
|
|
820
823
|
*/
|
|
821
|
-
Then(/^the "([^"]*)?" checkbox should be checked$/, function (checkbox) {
|
|
824
|
+
Then(/^(the )*"([^"]*)?" checkbox should be checked$/, function (theCase, checkbox) {
|
|
822
825
|
return browser.expect.element(checkbox).to.be.selected;
|
|
823
826
|
});
|
|
824
827
|
|
|
825
828
|
/**
|
|
826
|
-
* Assert, that checkbox with specified element is should not be checked
|
|
829
|
+
* Assert, that checkbox with specified element is should not be checked.
|
|
830
|
+
*
|
|
827
831
|
* Example: Then the "#PrivacyPolicy" checkbox should not be checked
|
|
828
832
|
*
|
|
829
833
|
*/
|
|
830
|
-
Then(/^the "([^"]*)?" checkbox should not be checked$/, function (checkbox) {
|
|
834
|
+
Then(/^(the )*"([^"]*)?" checkbox should not be checked$/, function (theCase, checkbox) {
|
|
831
835
|
return browser.expect.element(checkbox).to.not.be.selected;
|
|
832
836
|
});
|
|
833
837
|
|
|
834
838
|
/**
|
|
835
839
|
* Check, whether the checkbox specified is checked.
|
|
840
|
+
*
|
|
836
841
|
* Example: Then the "#rememberMe" checkbox is checked
|
|
837
842
|
*
|
|
838
843
|
*/
|
|
839
|
-
Then(/^the "([^"]*)?" checkbox is checked$/, function (checkbox) {
|
|
844
|
+
Then(/^(the )*"([^"]*)?" checkbox is checked$/, function (theCase, checkbox) {
|
|
840
845
|
return browser.expect.element(checkbox).to.be.selected;
|
|
841
846
|
});
|
|
842
847
|
|
|
843
848
|
/**
|
|
844
849
|
* Check, whether the checkbox specified is not checked.
|
|
850
|
+
*
|
|
845
851
|
* Example: Then the "#rememberMe" checkbox is not checked
|
|
846
852
|
*
|
|
847
853
|
*/
|
|
848
|
-
Then(/^the "([^"]*)?" checkbox is not checked$/, function (checkbox) {
|
|
854
|
+
Then(/^(the )*"([^"]*)?" checkbox is not checked$/, function (theCase, checkbox) {
|
|
849
855
|
return browser.expect.element(checkbox).to.not.be.selected;
|
|
850
856
|
});
|
|
851
857
|
|
|
852
858
|
/**
|
|
853
|
-
* Assert, that checkbox with specified element should be checked
|
|
859
|
+
* Assert, that checkbox with specified element should be checked.
|
|
860
|
+
*
|
|
854
861
|
* Example: Then the checkbox "#PrivacyPolicy" should be checked
|
|
855
862
|
*
|
|
856
863
|
*/
|
|
857
|
-
Then(/^the checkbox "([^"]*)?" should be checked$/, function (checkbox) {
|
|
864
|
+
Then(/^(the )*checkbox "([^"]*)?" should be checked$/, function (theCase, checkbox) {
|
|
858
865
|
return browser.expect.element(checkbox).to.be.selected;
|
|
859
866
|
});
|
|
860
867
|
|
|
861
868
|
/**
|
|
862
|
-
* Assert, that checkbox with specified element should not be checked
|
|
869
|
+
* Assert, that checkbox with specified element should not be checked.
|
|
870
|
+
*
|
|
863
871
|
* Example: Then the checkbox "#PrivacyPolicy" should not be checked
|
|
864
872
|
*
|
|
865
873
|
*/
|
|
866
|
-
Then(/^the checkbox "([^"]*)?" should not be checked$/, function (checkbox) {
|
|
874
|
+
Then(/^(the )*checkbox "([^"]*)?" should not be checked$/, function (theCase, checkbox) {
|
|
867
875
|
return browser.expect.element(checkbox).to.not.be.selected;
|
|
868
876
|
});
|
|
869
877
|
|
|
870
878
|
/**
|
|
871
|
-
* Assert, that checkbox with specified element is checked
|
|
879
|
+
* Assert, that checkbox with specified element is checked.
|
|
880
|
+
*
|
|
872
881
|
* Example: Then the checkbox "#rememberMe" is checked
|
|
873
882
|
*
|
|
874
883
|
*/
|
|
875
|
-
Then(/^the checkbox "([^"]*)?" is checked$/, function (checkbox) {
|
|
884
|
+
Then(/^(the )*checkbox "([^"]*)?" is checked$/, function (theCase, checkbox) {
|
|
876
885
|
return browser.expect.element(checkbox).to.be.selected;
|
|
877
886
|
});
|
|
878
887
|
|
|
879
888
|
/**
|
|
880
|
-
* Assert, that checkbox with specified element is not checked
|
|
889
|
+
* Assert, that checkbox with specified element is not checked.
|
|
890
|
+
*
|
|
881
891
|
* Example: Then the checkbox "#rememberMe" is not checked
|
|
882
892
|
*
|
|
883
893
|
*/
|
|
884
|
-
Then(/^the checkbox "([^"]*)?" is not checked$/, function (checkbox) {
|
|
894
|
+
Then(/^(the )*checkbox "([^"]*)?" is not checked$/, function (theCase, checkbox) {
|
|
885
895
|
return browser.expect.element(checkbox).to.not.be.selected;
|
|
886
896
|
});
|
|
887
897
|
|
|
888
898
|
/**
|
|
889
899
|
* Wait a specific number of seconds.
|
|
900
|
+
*
|
|
890
901
|
* Example: When I wait 1 second
|
|
891
902
|
* Example: When I wait 5 seconds
|
|
892
903
|
* Example: When I wait 3s
|
|
893
904
|
*
|
|
894
905
|
*/
|
|
895
|
-
When(/^(I|we)* wait (\d*)( second)*(s)*$/, function (
|
|
906
|
+
When(/^(I|we)* wait (\d*)( second)*(s)*$/, function (pronounCase, number, withWord, withS) {
|
|
896
907
|
var waitTime = number * 1000;
|
|
897
908
|
return browser.pause(waitTime);
|
|
898
909
|
});
|
|
899
910
|
|
|
900
911
|
/**
|
|
901
912
|
* Wait a max number of seconds until the element present.
|
|
913
|
+
*
|
|
902
914
|
* Example: When I wait max of 6 seconds
|
|
903
915
|
*
|
|
904
916
|
*/
|
|
905
|
-
When(/^(I|we)* wait max of (\d*)( second)*(s)*$/, function (
|
|
917
|
+
When(/^(I|we)* wait max of (\d*)( second)*(s)*$/, function (pronounCase, number, withWord, withS) {
|
|
906
918
|
var waitTime = number * 1000;
|
|
907
919
|
return browser.waitForElementPresent('body', waitTime);
|
|
908
920
|
});
|
|
909
921
|
|
|
910
922
|
/**
|
|
911
923
|
* Wait a specific number of minutes.
|
|
924
|
+
*
|
|
912
925
|
* Example: When I wait 1 minute
|
|
913
926
|
* Example: When I wait 5 minutes
|
|
914
927
|
*
|
|
915
928
|
*/
|
|
916
|
-
When(/^(I|we)* wait (\d*)( minute)*(m)*$/, function (
|
|
929
|
+
When(/^(I|we)* wait (\d*)( minute)*(m)*$/, function (pronounCase, number, withWord, withM) {
|
|
917
930
|
var waitTime = number * 1000 * 60;
|
|
918
931
|
return browser.pause(waitTime);
|
|
919
932
|
});
|
|
920
933
|
|
|
921
934
|
/**
|
|
922
935
|
* Wait a max number of minutes until the element present.
|
|
936
|
+
*
|
|
923
937
|
* Example: When I wait max of 6 minutes
|
|
924
938
|
*
|
|
925
939
|
*/
|
|
926
|
-
When(/^(I|we)* wait max of (\d*)( minute)*(m)*$/, function (
|
|
940
|
+
When(/^(I|we)* wait max of (\d*)( minute)*(m)*$/, function (pronounCase, number, withWord, withM) {
|
|
927
941
|
var waitTime = number * 1000 * 60;
|
|
928
942
|
return browser.waitForElementPresent('body', waitTime);
|
|
929
943
|
});
|
|
930
944
|
|
|
931
945
|
/**
|
|
932
946
|
* Wait until the page is loaded.
|
|
947
|
+
*
|
|
933
948
|
* Example: When I wait until the page is loaded
|
|
934
949
|
*
|
|
935
950
|
*/
|
|
936
|
-
When(/^(I|we)* wait until the page( is)* loaded*$/, function (
|
|
951
|
+
When(/^(I|we)* wait until( the)* page( is)* loaded*$/, function (pronounCase, theCase, withIs) {
|
|
937
952
|
return browser.waitForElementPresent('body', 10000);
|
|
938
953
|
});
|
|
939
954
|
/**
|
|
940
|
-
* Checks, that the current page response status is equal the specified code
|
|
955
|
+
* Checks, that the current page response status is equal the specified code.
|
|
956
|
+
*
|
|
941
957
|
* Example: Then the response status code should be 200
|
|
942
958
|
*
|
|
943
959
|
*/
|
|
944
|
-
Then(/^the response status code should be (\d+)$/, function (expectedStatusCode) {
|
|
960
|
+
Then(/^(the )*response status code should be (\d+)$/, function (theCase, expectedStatusCode) {
|
|
945
961
|
return browser.url(function (currentURL) {
|
|
946
962
|
axios.get(currentURL.value)
|
|
947
963
|
.then(function (response) {
|
|
@@ -957,11 +973,12 @@ Then(/^the response status code should be (\d+)$/, function (expectedStatusCode)
|
|
|
957
973
|
});
|
|
958
974
|
|
|
959
975
|
/**
|
|
960
|
-
* Checks, that the current page response status is not equal the specified code
|
|
976
|
+
* Checks, that the current page response status is not equal the specified code.
|
|
977
|
+
*
|
|
961
978
|
* Example: And the response status code should not be 404
|
|
962
979
|
*
|
|
963
980
|
*/
|
|
964
|
-
Then(/^the response status code should not be (\d+)$/, function ( expectedStatusCode) {
|
|
981
|
+
Then(/^(the )*response status code should not be (\d+)$/, function ( theCase, expectedStatusCode) {
|
|
965
982
|
return browser.url(function (currentURL) {
|
|
966
983
|
axios.get(currentURL.value)
|
|
967
984
|
.then(function (response) {
|
|
@@ -977,11 +994,12 @@ Then(/^the response status code should not be (\d+)$/, function ( expectedStatus
|
|
|
977
994
|
});
|
|
978
995
|
|
|
979
996
|
/**
|
|
980
|
-
* Checks, that page contains text matching specified pattern
|
|
997
|
+
* Checks, that page contains text matching specified pattern.
|
|
998
|
+
*
|
|
981
999
|
* Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
|
|
982
1000
|
*
|
|
983
1001
|
*/
|
|
984
|
-
Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (
|
|
1002
|
+
Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
|
|
985
1003
|
browser.elements('css selector', 'body', function (elements) {
|
|
986
1004
|
elements.value.forEach(function (elementsObj) {
|
|
987
1005
|
return browser.assert.textMatches(elementsObj, textPattern);
|
|
@@ -990,11 +1008,12 @@ Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronoundCase, te
|
|
|
990
1008
|
});
|
|
991
1009
|
|
|
992
1010
|
/**
|
|
993
|
-
* Checks, that page not contains text matching specified pattern
|
|
1011
|
+
* Checks, that page not contains text matching specified pattern.
|
|
1012
|
+
*
|
|
994
1013
|
* Example: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
|
|
995
1014
|
*
|
|
996
1015
|
*/
|
|
997
|
-
Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (
|
|
1016
|
+
Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
|
|
998
1017
|
browser.elements('css selector', 'body', function (elements) {
|
|
999
1018
|
elements.value.forEach(function (elementsObj) {
|
|
1000
1019
|
return browser.assert.not.textMatches(elementsObj, textPattern);
|
|
@@ -1003,43 +1022,217 @@ Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase
|
|
|
1003
1022
|
});
|
|
1004
1023
|
|
|
1005
1024
|
/**
|
|
1006
|
-
* Checks, that page contains text matching specified pattern
|
|
1025
|
+
* Checks, that page contains text matching specified pattern.
|
|
1026
|
+
*
|
|
1007
1027
|
* Example: Then I should see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1008
1028
|
* //pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1009
1029
|
*
|
|
1010
1030
|
*/
|
|
1011
|
-
Then(/^(I|we)* should see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (
|
|
1031
|
+
Then(/^(I|we)* should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
|
|
1012
1032
|
return this.shouldSeePattern = function (browser) {
|
|
1013
1033
|
browser.assert.textMatches(element, textPattern);
|
|
1014
1034
|
};
|
|
1015
1035
|
});
|
|
1016
1036
|
|
|
1017
1037
|
/**
|
|
1018
|
-
* Checks, that page contains text matching specified pattern
|
|
1038
|
+
* Checks, that page contains text matching specified pattern.
|
|
1039
|
+
*
|
|
1019
1040
|
* Example: Then I should not see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1020
1041
|
* //pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1021
1042
|
*
|
|
1022
1043
|
*/
|
|
1023
|
-
Then(/^(I|we)* should not see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (
|
|
1044
|
+
Then(/^(I|we)* should not see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, element) {
|
|
1024
1045
|
return this.shouldSeePattern = function (browser) {
|
|
1025
1046
|
browser.assert.not.textMatches(element, textPattern);
|
|
1026
1047
|
};
|
|
1027
1048
|
});
|
|
1028
1049
|
|
|
1029
1050
|
/**
|
|
1030
|
-
* Checks, that current URL Path matches regular expression
|
|
1051
|
+
* Checks, that current URL Path matches regular expression.
|
|
1052
|
+
*
|
|
1031
1053
|
* Example: Then the url should match "/contact-us.html"
|
|
1032
1054
|
*
|
|
1033
1055
|
*/
|
|
1034
|
-
Then(/^the url should match "([^"]*)?"$/, function (pattern) {
|
|
1056
|
+
Then(/^(the )*url should match "([^"]*)?"$/, function (theCase, pattern) {
|
|
1035
1057
|
return browser.assert.urlMatches(pattern);
|
|
1036
1058
|
});
|
|
1037
1059
|
|
|
1038
1060
|
/**
|
|
1039
|
-
* Checks, that current URL Path matches regular expression
|
|
1061
|
+
* Checks, that current URL Path matches regular expression.
|
|
1062
|
+
*
|
|
1040
1063
|
* Example: Then the url should not match "/contact-us.html"
|
|
1041
1064
|
*
|
|
1042
1065
|
*/
|
|
1043
|
-
Then(/^the url should not match "([^"]*)?"$/, function (pattern) {
|
|
1066
|
+
Then(/^(the )*url should not match "([^"]*)?"$/, function (theCase, pattern) {
|
|
1044
1067
|
return browser.assert.not.urlMatches(pattern);
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Scrolls down the page by a custom number of pixels specified by the user.
|
|
1072
|
+
*
|
|
1073
|
+
* Example #1: And I scroll down
|
|
1074
|
+
* Example #2: When I scroll down 800
|
|
1075
|
+
* Example #3: And we scroll down 500
|
|
1076
|
+
* Example #4: When scrolling down 1200
|
|
1077
|
+
*/
|
|
1078
|
+
When(/^(I|we)? (scroll|scrolling) down( ([^"]*)?)*$/, function(pronounCase, scrollAction, value) {
|
|
1079
|
+
// Default scroll value
|
|
1080
|
+
let scrollValue = 350;
|
|
1081
|
+
|
|
1082
|
+
if (value !== null) {
|
|
1083
|
+
scrollValue = parseInt(String(value).trim(), 10);
|
|
1084
|
+
|
|
1085
|
+
// Validate the parsed value
|
|
1086
|
+
if (isNaN(scrollValue)) {
|
|
1087
|
+
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (scrollValue < 0) {
|
|
1091
|
+
throw new Error(`Scroll down value must be positive. Received: ${scrollValue}`);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
if (scrollValue > 10000) {
|
|
1095
|
+
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
return browser.executeScript(`window.scrollBy(0, ${scrollValue});`);
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Scrolls up the page by a custom number of pixels specified by the user.
|
|
1104
|
+
*
|
|
1105
|
+
* Example #1: And I scroll up
|
|
1106
|
+
* Example #2: When I scroll up 1000
|
|
1107
|
+
* Example #3: And we scrolling up 300
|
|
1108
|
+
* Example #4: When scrolling up 750
|
|
1109
|
+
*
|
|
1110
|
+
*/
|
|
1111
|
+
When(/^(I|we)? (scroll|scrolling) up( ([^"]*)?)*$/, function(pronounCase, scrollAction, value) {
|
|
1112
|
+
// Parse and validate the scroll value
|
|
1113
|
+
let scrollValue = 350; // default value
|
|
1114
|
+
|
|
1115
|
+
if (value !== null) {
|
|
1116
|
+
scrollValue = parseInt(String(value).trim(), 10);
|
|
1117
|
+
|
|
1118
|
+
// Validate the parsed value
|
|
1119
|
+
if (isNaN(scrollValue)) {
|
|
1120
|
+
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
if (scrollValue < 0) {
|
|
1124
|
+
throw new Error(`Scroll up value must be positive. Received: ${scrollValue}`);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
if (scrollValue > 10000) {
|
|
1128
|
+
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// Make the value negative for scrolling up
|
|
1133
|
+
return browser.executeScript(`window.scrollBy(0, -${scrollValue});`);
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Scrolls to the very top of the current page, resetting the scroll position to zero.
|
|
1138
|
+
*
|
|
1139
|
+
* Example #1: When I scroll to top
|
|
1140
|
+
* Example #2: And we scrolling to the top
|
|
1141
|
+
* Example #3: When scrolling to the top of the page
|
|
1142
|
+
*/
|
|
1143
|
+
When(/^(I|we)* (scroll|scrolling) to( the)* top( of the page)*$/, function(pronounCase, scrollAction, theCase, pageCase) {
|
|
1144
|
+
return browser.executeScript('document.documentElement.scrollTop = 0;');
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Scrolls to the bottom of the current page using the full document height.
|
|
1149
|
+
*
|
|
1150
|
+
* Example #1: When I scroll to the bottom
|
|
1151
|
+
* Example #2: And we scroll to bottom
|
|
1152
|
+
* Example #3: When scrolling to the bottom of the page
|
|
1153
|
+
*/
|
|
1154
|
+
When(/^(I|we)* (scroll|scrolling) to( the)* bottom( of the page)*$/, function(pronounCase, scrollAction, theCase, pageCase) {
|
|
1155
|
+
return browser.executeScript('window.scrollTo(0, document.body.scrollHeight);');
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* Scrolls to the top of a specific element identified by a CSS selector, resetting its scroll position to zero.
|
|
1160
|
+
*
|
|
1161
|
+
* Example #1: When I scroll to top of "#off-canvas"
|
|
1162
|
+
* Example #2: And we scroll to top of "#sidebar"
|
|
1163
|
+
* Example #3: When scrolling to top of "#main-container"
|
|
1164
|
+
*/
|
|
1165
|
+
When(/^(I|we)* (scroll|scrolling) to top of "([^"]*)"$/, function(pronounCase, scrollAction, selector) {
|
|
1166
|
+
// Validate selector
|
|
1167
|
+
if (!selector || selector.trim() === '') {
|
|
1168
|
+
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// Validate selector format (basic check)
|
|
1172
|
+
if (selector.includes('"') || selector.includes("'")) {
|
|
1173
|
+
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
try {
|
|
1177
|
+
// Check if element exists before scrolling
|
|
1178
|
+
const elementExists = browser.executeScript(`
|
|
1179
|
+
return document.querySelector("${selector}") !== null;
|
|
1180
|
+
`);
|
|
1181
|
+
|
|
1182
|
+
if (!elementExists) {
|
|
1183
|
+
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
browser.executeScript(`
|
|
1187
|
+
const element = document.querySelector("${selector}");
|
|
1188
|
+
if (element) {
|
|
1189
|
+
element.scrollTop = 0;
|
|
1190
|
+
}
|
|
1191
|
+
`);
|
|
1192
|
+
|
|
1193
|
+
return browser.pause(2000);
|
|
1194
|
+
} catch (error) {
|
|
1195
|
+
throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Scrolls to the bottom of a specific element identified by a CSS selector, moving to its maximum scroll height.
|
|
1201
|
+
*
|
|
1202
|
+
* Example #1: When I scroll to bottom of "#off-canvas"
|
|
1203
|
+
* Example #2: And we scrolling to bottom of "#sidebar"
|
|
1204
|
+
* Example #3: When scrolling to bottom of "#main-container"
|
|
1205
|
+
*/
|
|
1206
|
+
When(/^(I|we)* (scroll|scrolling) to bottom of "([^"]*)"$/, function(pronounCase, scrollAction, selector) {
|
|
1207
|
+
// Validate selector
|
|
1208
|
+
if (!selector || selector.trim() === '') {
|
|
1209
|
+
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// Validate selector format (basic check)
|
|
1213
|
+
if (selector.includes('"') || selector.includes("'")) {
|
|
1214
|
+
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
try {
|
|
1218
|
+
// Check if element exists before scrolling
|
|
1219
|
+
const elementExists = browser.executeScript(`
|
|
1220
|
+
return document.querySelector("${selector}") !== null;
|
|
1221
|
+
`);
|
|
1222
|
+
|
|
1223
|
+
if (!elementExists) {
|
|
1224
|
+
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
browser.executeScript(`
|
|
1228
|
+
const element = document.querySelector("${selector}");
|
|
1229
|
+
if (element) {
|
|
1230
|
+
element.scrollTop = element.scrollHeight;
|
|
1231
|
+
}
|
|
1232
|
+
`);
|
|
1233
|
+
|
|
1234
|
+
return browser.pause(2000);
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
1237
|
+
}
|
|
1045
1238
|
});
|