webship-js 1.0.39 → 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.
Files changed (44) hide show
  1. package/examples/test--when--i-scroll-functionality.html +176 -0
  2. package/package.json +1 -1
  3. package/tests/features/test--given--i-am-on-homepage.feature +2 -2
  4. package/tests/features/test--then--i-should--not--see-text-in-element.feature +2 -2
  5. package/tests/features/test--then--i-should--see-text-in-element-by-attr.feature +2 -2
  6. package/tests/features/test--then--i-should--see-text-in-element.feature +2 -2
  7. package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +4 -4
  8. package/tests/features/test--then--i-should--see-text-matching-pattern.feature +5 -5
  9. package/tests/features/test--then--i-should-be-on-page.feature +2 -2
  10. package/tests/features/test--then--i-should-be-on-the-homepage.feature +2 -2
  11. package/tests/features/test--then--i-should-not-see-an-element-by-attr.feature +2 -2
  12. package/tests/features/test--then--i-should-not-see-an-element.feature +2 -2
  13. package/tests/features/test--then--i-should-see-an-element-by-attr.feature +2 -2
  14. package/tests/features/test--then--i-should-see-an-element.feature +2 -2
  15. package/tests/features/test--then--the-checkbox-is-checked.feature +2 -2
  16. package/tests/features/test--then--the-checkbox-should-be-checked.feature +2 -2
  17. package/tests/features/test--then--the-element-should-contain-cssproperty.feature +2 -2
  18. package/tests/features/test--then--the-element-should-not-contain-cssproperty.feature +2 -2
  19. package/tests/features/test--then--the-field-should-contain-value.feature +3 -3
  20. package/tests/features/test--then--the-response-should-contain.feature +3 -3
  21. package/tests/features/test--then--the-response-status-code-should-be.feature +2 -2
  22. package/tests/features/test--then--the-url-should-match.feature +3 -3
  23. package/tests/features/test--then-the-link-should-contain-by-attribute.feature +2 -3
  24. package/tests/features/test--then-the-link-should-contain.feature +2 -3
  25. package/tests/features/test--when--i-attach-file-to-feild.feature +2 -3
  26. package/tests/features/test--when--i-check-checkbox.feature +2 -3
  27. package/tests/features/test--when--i-click-link-by-attribute.feature +2 -3
  28. package/tests/features/test--when--i-click-link.feature +2 -3
  29. package/tests/features/test--when--i-fill-in-by-attr.feature +2 -2
  30. package/tests/features/test--when--i-fill-in-table-by-attr.feature +6 -6
  31. package/tests/features/test--when--i-fill-in.feature +4 -4
  32. package/tests/features/test--when--i-go-to-homepage.feature +3 -6
  33. package/tests/features/test--when--i-move-forward-backward-one-page.feature +2 -3
  34. package/tests/features/test--when--i-press-button-by-attribute.feature +2 -3
  35. package/tests/features/test--when--i-press-button.feature +7 -3
  36. package/tests/features/test--when--i-reload-page.feature +2 -3
  37. package/tests/features/test--when--i-scroll.feature +48 -0
  38. package/tests/features/test--when--i-select-option-from-dropdownlist.feature +15 -4
  39. package/tests/features/test--when--i-wait-page-is-loaded.feature +2 -3
  40. package/tests/features/test--when--i-wait-time.feature +3 -4
  41. package/tests/step-definitions/webship.js +358 -149
  42. package/examples/test--when--i-scroll-to-the-bottom.html +0 -49
  43. package/tests/features/test--when--i-scroll-to-the-bottom.feature +0 -9
  44. package/tests/features/test--when--i-select-option-from-dropdownlist-by-attr.feature +0 -16
@@ -7,50 +7,54 @@ const axios = require('axios');
7
7
 
8
8
  /**
9
9
  * Opens homepage.
10
+ *
10
11
  * Example: Given I am on homepage
11
12
  * Example: Given I am on the homepage
12
13
  *
13
14
  */
14
- Given(/^(I am|we are) on( the)* homepage$/, function (pronoundCase, theCase) {
15
+ Given(/^(I am|we are) on( the)* homepage$/, function (pronounCase, theCase) {
15
16
  return browser.url(browser.launch_url).waitForElementPresent('body', 1000);
16
17
  });
17
18
 
18
19
  /**
19
- * Open specific page
20
+ * Open specific page.
21
+ *
20
22
  * Example: Given I am on "about-us.html"
21
23
  *
22
24
  */
23
- Given(/^(I am|we are) on "([^"]*)?"$/, function (pronoundCase, url) {
25
+ Given(/^(I am|we are) on "([^"]*)?"$/, function (pronounCase, url) {
24
26
  return browser.url(browser.launch_url + url).waitForElementPresent('body', 1000);
25
27
  });
26
28
 
27
29
  /**
28
- * Go to homepage
30
+ * Go to homepage.
31
+ *
32
+ * Example: When I go to homepage
29
33
  * Example: When I go to the homepage
30
- * Example: And I go to the "/"
31
34
  *
32
35
  */
33
- When(/^(I|we)* go to( the)* homepage$/, function (pronoundCase, theCase) {
36
+ When(/^(I|we)* go to( the)* homepage$/, function (pronounCase, theCase) {
34
37
  return browser.url(browser.launch_url).waitForElementPresent('body', 1000);
35
38
  });
36
39
 
37
40
  /**
38
- * Go to specific page
41
+ * Go to specific page.
42
+ *
39
43
  * Example: When I go to "contact-us.html"
40
44
  *
41
45
  */
42
- When(/^(I|we)* go to "([^"]*)?"$/, function (pronoundCase, url) {
46
+ When(/^(I|we)* go to "([^"]*)?"$/, function (pronounCase, url) {
43
47
  return browser.url(browser.launch_url + url).waitForElementPresent('body', 1000);
44
48
  });
45
49
 
46
50
  /**
47
51
  * Asserting a text in the page.
48
- *
52
+ *
49
53
  * Example:
50
54
  * - Then I should see "Welcome"
51
55
  *
52
56
  */
53
- Then(/^(I|we)* should see "([^"]*)?"$/, function (pronoundCase, expectedText) {
57
+ Then(/^(I|we)* should see "([^"]*)?"$/, function (pronounCase, expectedText) {
54
58
  return this.shouldSee = function (browser) {
55
59
  browser.assert.textContains("html", expectedText);
56
60
  };
@@ -58,55 +62,60 @@ Then(/^(I|we)* should see "([^"]*)?"$/, function (pronoundCase, expectedText) {
58
62
 
59
63
  /**
60
64
  * Asserting a text not in the page.
61
- *
65
+ *
62
66
  * Example:
63
67
  * - Then I should not see "Access denied"
64
68
  *
65
69
  */
66
- Then(/^(I|we)* should not see "([^"]*)?"$/, function (pronoundCase, expectedText) {
70
+ Then(/^(I|we)* should not see "([^"]*)?"$/, function (pronounCase, expectedText) {
67
71
  return this.shouldSee = function (browser) {
68
72
  browser.assert.not.textContains("html", expectedText);
69
73
  };
70
74
  });
71
75
 
72
76
  /**
73
- * Moves forward one page in browser history
77
+ * Moves forward one page in browser history.
78
+ *
74
79
  * Example: When I move forward one page
75
80
  *
76
81
  */
77
- When(/^(I|we)* move forward one page$/, function (pronoundCase) {
82
+ When(/^(I|we)* move forward one page$/, function (pronounCase) {
78
83
  return browser.forward();
79
84
  });
80
85
 
81
86
  /**
82
- * Moves backward one page in browser history
87
+ * Moves backward one page in browser history.
88
+ *
83
89
  * Example: When I move backward one page
84
90
  *
85
91
  */
86
- When(/^(I|we)* move backward one page$/, function (pronoundCase) {
92
+ When(/^(I|we)* move backward one page$/, function (pronounCase) {
87
93
  return browser.back();
88
94
  });
89
95
 
90
96
  /**
91
- * Presses button with specified element
97
+ * Presses button with specified element.
98
+ *
92
99
  * Example: When I press "Log In"
93
- * Example: And I press "Log In"
100
+ * Example: And I press the "Log In" button
101
+ * Example: And I press the "Save as" button
94
102
  *
95
103
  */
96
- When(/^(I|we)* press "([^"]*)?"$/, function (pronoundCase, element) {
104
+ When(/^(I|we)* press( the)* "([^"]*)?"( button)*$/, function (pronounCase, theCase, element, buttonCase) {
97
105
  browser.click("[value='" + element +"']");
98
106
  });
99
107
 
100
108
  /**
101
- * Presses button with specified element
109
+ * Presses button with specified element.
110
+ *
102
111
  * Example: When I press "btn-pressid" by attr
103
112
  * Example: When I press "btn-pressid" by attribute
104
113
  * Example: And I press "Your full name" by "placeholder" attribute
105
114
  * Example: And I press "Your full name" by its "placeholder" attribute
106
- * Example: And I press "save-name" by "data-drupal-selector" attr
115
+ * Example: And I press "save-name" by "data-selector" attr
107
116
  *
108
117
  */
109
- When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, itsCase, attr, attrCase) {
118
+ When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
110
119
 
111
120
  const hasASpace = attrValue.indexOf(' ');
112
121
  var selector = '';
@@ -128,24 +137,26 @@ When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, func
128
137
  });
129
138
 
130
139
  /**
131
- * Clicks link with specified element
140
+ * Clicks link with specified element.
141
+ *
132
142
  * Example: When I click "Contact Us"
133
143
  * Example: And I click "aboutUs"
134
144
  *
135
145
  */
136
- When(/^(I|we)* click "([^"]*)?"$/, function (pronoundCase, item) {
146
+ When(/^(I|we)* click "([^"]*)?"$/, function (pronounCase, item) {
137
147
  return browser.click("link text", item);
138
148
  });
139
149
 
140
150
  /**
141
- * Click Link with specified element
151
+ * Click Link with specified element.
152
+ *
142
153
  * Example: When I click "#aboutUsid" by attr
143
154
  * Example: When I click "aboutUsCss" by attribute
144
155
  * Example: And I click "aboutUsCss" by "class" attr
145
156
  * Example: And I click "aboutUsid" by its "id" attribute
146
157
  *
147
158
  */
148
- When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, itsCase, attr, attrCase) {
159
+ When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
149
160
 
150
161
  const hasASpace = attrValue.indexOf(' ');
151
162
  var selector = '';
@@ -168,33 +179,35 @@ When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, func
168
179
  });
169
180
 
170
181
  /**
171
- * Reloads current page
182
+ * Reloads current page.
183
+ *
172
184
  * Example: When I reload page
173
185
  * Example: And I reload page
174
186
  *
175
187
  */
176
188
 
177
- When(/^(I|we)* reload page$/, function (pronoundCase) {
189
+ When(/^(I|we)* reload page$/, function (pronounCase) {
178
190
  return browser.refresh(browser.getCurrentUrl());
179
191
  });
180
192
 
181
193
  /**
182
- * Reloads current page
194
+ * Reloads current page.
195
+ *
183
196
  * Example: When I reload the page
184
197
  * Example: And I reload the page
185
198
  *
186
199
  */
187
- When(/^(I|we)* reload( the)* page$/, function (pronoundCase, theCase) {
200
+ When(/^(I|we)* reload( the)* page$/, function (pronounCase, theCase) {
188
201
  return browser.refresh(browser.getCurrentUrl());
189
202
  });
190
203
 
191
-
192
204
  /**
193
205
  * Define the step of filling values in the form field specified element.
206
+ *
194
207
  * Example: When I fill in "Username" with "John Smith"
195
208
  *
196
209
  */
197
- When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, field, value) {
210
+ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronounCase, field, value) {
198
211
  const elementField = browser.element.findByText(field, { exact: true });
199
212
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
200
213
  return browser.setValue('#' + eleAttribute.value, value);
@@ -202,14 +215,15 @@ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, fie
202
215
  });
203
216
 
204
217
  /**
205
- * Fill input type text with value by its attribute
218
+ * Fill input type text with value by its attribute.
219
+ *
206
220
  * Example: When I fill in "#uname" by attr
207
221
  * Example: When I fill in "uname" with "John Smith" by attr
208
222
  * Example: And I fill in "pwordcss" with "1234" by "class" attr
209
223
  * Example: And I fill in "Your full name" with "John Smith" by its "placeholder" attribute
210
224
  *
211
225
  */
212
- When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, txtValue, itsCase, attr, attrCase) {
226
+ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, txtValue, itsCase, attr, attrCase) {
213
227
 
214
228
  const hasASpace = attrValue.indexOf(' ');
215
229
  var selector = '';
@@ -232,11 +246,12 @@ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attri
232
246
  });
233
247
 
234
248
  /**
235
- * Fill input type text with empty value by its Label
249
+ * Fill input type text with empty value by its Label.
250
+ *
236
251
  * Example: When I fill in "Username" with:
237
252
  *
238
253
  */
239
- When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronoundCase, field) {
254
+ When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronounCase, field) {
240
255
  const elementField = browser.element.findByText(field, { exact: true });
241
256
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
242
257
  return browser.setValue('#' + eleAttribute.value, '');
@@ -244,14 +259,15 @@ When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronoundCase, field) {
244
259
  });
245
260
 
246
261
  /**
247
- * Fill input type text with empty value by its attribute
262
+ * Fill input type text with empty value by its attribute.
263
+ *
248
264
  * Example: When I fill in "#uname" with: by attr
249
265
  * Example: When I fill in "uname" with: by attr
250
266
  * Example: And I fill in "pwordcss" with: by "class" attr
251
267
  * Example: And I fill in "Your full name" with: by its "placeholder" attribute
252
268
  *
253
269
  */
254
- When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue , itsCase, attr, attrCase) {
270
+ When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue , itsCase, attr, attrCase) {
255
271
 
256
272
  const hasASpace = attrValue.indexOf(' ');
257
273
  var selector = '';
@@ -273,11 +289,12 @@ When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)
273
289
  });
274
290
 
275
291
  /**
276
- * Fill in value for input type text by its Label
277
- * Example: When I fill in "webshipco" for "Username"
292
+ * Fill in value for input type text by its Label.
293
+ *
294
+ * Example: When I fill in "jon-smith" for "Username"
278
295
  *
279
296
  */
280
- When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, value, field) {
297
+ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronounCase, value, field) {
281
298
  const elementField = browser.element.findByText(field, { exact: true });
282
299
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
283
300
  return browser.setValue('#' + eleAttribute.value, value);
@@ -285,14 +302,15 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, valu
285
302
  });
286
303
 
287
304
  /**
288
- * Fill in value for input type text by its attribute
305
+ * Fill in value for input type text by its attribute.
306
+ *
289
307
  * Example: When I fill in "John Smith" for "#uname" by attr
290
308
  * Example: When I fill in "John Smith" for "uname" by attr
291
309
  * Example: And I fill in "1234" for "pwordcss" by "class" attr
292
310
  * Example: And I fill in "John Smith" for "Your full name" by its "placeholder" attribute
293
311
  *
294
312
  */
295
- When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, txtValue, attrValue, itsCase, attr, attrCase) {
313
+ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, txtValue, attrValue, itsCase, attr, attrCase) {
296
314
 
297
315
  const hasASpace = attrValue.indexOf(' ');
298
316
  var selector = '';
@@ -315,13 +333,14 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attrib
315
333
  });
316
334
 
317
335
  /**
318
- * 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
+ *
319
338
  * Example: When I fill in the following:
320
339
  * | Username | webshipco |
321
340
  * | Password | 1234 |
322
341
  */
323
342
 
324
- When(/^(I|we)* fill in( the)* following:$/, function (pronoundCase, theCase, table) {
343
+ When(/^(I|we)* fill in( the)* following:$/, function (pronounCase, theCase, table) {
325
344
 
326
345
  var elementField = browser.element.findByText(table.rawTable[0][0], { exact: true });
327
346
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
@@ -338,17 +357,18 @@ When(/^(I|we)* fill in( the)* following:$/, function (pronoundCase, theCase, tab
338
357
  });
339
358
 
340
359
  /**
341
- * Fill in value for input type text by its attributeFill form fields of type input Text with the provided table according to their attributes
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
+ *
342
363
  * Example: When I fill in the following: by attr
343
364
  * | #uname | John Smith |
344
365
  * | pwordcss | 1234 |
345
-
366
+ *
346
367
  * Example: When I fill in the following: by its "placeholder" attribute
347
368
  * | Your full name | John Smith |
348
369
  * | Your Password | 1234 |
349
370
  */
350
-
351
- When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, theCase, itsCase, attr, attrCase, table) {
371
+ When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, theCase, itsCase, attr, attrCase, table) {
352
372
 
353
373
  var hasASpace = table.rawTable[0][0].indexOf(' ');
354
374
  var selector = '';
@@ -396,112 +416,104 @@ When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr
396
416
  /**
397
417
  * Selecting the option in the dropdown list field by its text label
398
418
  * Example: When I select "Mercedes" from "Cars"
419
+ * Example: When I select "saab" from "#cars"
420
+ * Example: When I select "Mercedes" from "cars"
399
421
  *
400
422
  */
401
- When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronoundCase, option, dropdownlist) {
402
-
403
- const elementField = browser.element.findByText(dropdownlist, { exact: true });
404
- browser.getAttribute(elementField, 'for', function (eleAttribute) {
405
- return browser.waitForElementVisible('css selector', '#' + eleAttribute.value)
406
- .click('#' + eleAttribute.value)
407
- .click(browser.element.findByText(option, { exact: true }))
408
- .click('#' + eleAttribute.value);
409
- });
410
- });
411
-
412
- /**
413
- * Selects option in select field
414
- * Example: When I select "Mercedes" from "cars" its "id" attr
415
- * Example: When I select "Saab" from "#cars" by attr
416
- *
417
- */
418
-
419
- When(/^(I|we)* select "([^"]*)?" from "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, option, attrValue, itsCase, attr, attrCase) {
423
+ When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, option, selectList) {
420
424
 
421
- const hasASpace = attrValue.indexOf(' ');
425
+ const hasASpace = selectList.indexOf(' ');
422
426
 
423
- var selector = '';
424
- if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
425
- selector = attrValue;
426
- }
427
- else if (!attr && hasASpace == -1){
428
- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
427
+ let selector = '';
428
+ if((selectList.startsWith('#') || selectList.startsWith('.'))){
429
+ selector = selectList;
429
430
  }
430
- else if (!attr && hasASpace > -1){
431
- selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
431
+ else if (hasASpace == -1){
432
+ selector = '[name="' + selectList + '"],[id="' + selectList + '"],[class="' + selectList + '"]';
432
433
  }
433
434
  else {
434
- selector = '[' + attr + '="' + attrValue + '"]';
435
+ selector = browser.element.findByText(selectList, { exact: true });
435
436
  }
436
437
 
437
- return browser.waitForElementVisible('css selector', selector)
438
- .click(selector)
439
- .click(browser.element.findByText(option, { exact: true }))
440
- .click(selector);
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);
441
449
  });
442
450
 
443
451
  /**
444
- * Checks checkbox specified
452
+ * Checks checkbox specified.
453
+ *
445
454
  * Example: When I check "Remember me"
446
455
  *
447
456
  */
448
- When(/^(I|we)* check "([^"]*)?"$/, function (pronoundCase, item) {
449
-
457
+ When(/^(I|we)* check "([^"]*)?"$/, function (pronounCase, item) {
450
458
  browser.checkItem(item);
451
459
  });
452
460
 
453
461
  /**
454
- * Unchecks checkbox specified
462
+ * Unchecks checkbox specified.
463
+ *
455
464
  * Example: When I uncheck "Remember me"
456
465
  *
457
466
  */
458
- When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronoundCase, item) {
459
-
467
+ When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronounCase, item) {
460
468
  browser.uncheckItem(item);
461
469
  });
462
470
 
463
471
  /**
464
- * Verify, that current page is the homepage
472
+ * Verify, that current page is the homepage.
473
+ *
465
474
  * Example: Then I should be on homepage
466
475
  * Example: Then I should be on the homepage
467
476
  *
468
477
  */
469
- Then(/^(I|we)* should be on( the)* homepage$/, function (pronoundCase, theCase) {
478
+ Then(/^(I|we)* should be on( the)* homepage$/, function (pronounCase, theCase) {
470
479
  return browser.assert.urlMatches(browser.launch_url);
471
480
  });
472
481
 
473
482
  /**
474
- * Verify, that current page is the homepage
483
+ * Verify, that current page is the homepage.
484
+ *
475
485
  * Example: Then I should not be on homepage
476
486
  *
477
487
  */
478
- Then(/^(I|we)* should not be on homepage$/, function (pronoundCase) {
488
+ Then(/^(I|we)* should not be on homepage$/, function (pronounCase) {
479
489
  return browser.assert.not.urlMatches(browser.launch_url);
480
490
  });
481
491
 
482
492
  /**
483
- * Verify, that current page is the homepage
493
+ * Verify, that current page is the homepage.
494
+ *
484
495
  * Example: Then I should not be on the homepage
485
496
  *
486
497
  */
487
- Then(/^(I|we)* should not be on( the)* homepage$/, function (pronoundCase, theCase) {
498
+ Then(/^(I|we)* should not be on( the)* homepage$/, function (pronounCase, theCase) {
488
499
  return browser.assert.not.urlMatches(browser.launch_url);
489
500
  });
490
501
 
491
502
  /**
492
- * Verify, that current page path is equal to specified path
503
+ * Verify, that current page path is equal to specified path.
504
+ *
493
505
  * Example: Then I should be on "/"
494
506
  * Example: And I should be on "/user/login"
495
507
  * Example: And I should be on "http://google.com"
496
508
  *
497
509
  */
498
-
499
- Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronoundCase, url) {
510
+ Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronounCase, url) {
500
511
  return browser.assert.urlContains(url);
501
512
  });
502
513
 
503
514
  /**
504
515
  * Verify, that the current link contains the specified URL.
516
+ *
505
517
  * Example: Then the "Login" link should contain "/log-in"
506
518
  *
507
519
  */
@@ -512,6 +524,7 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, el
512
524
 
513
525
  /**
514
526
  * Verify, that the current link contains the specified URL, found by its attributes.
527
+ *
515
528
  * Example: Then the "#aboutUsid" link should contain "about" by attr
516
529
  * Example: And the "aboutUs" link should contain "about" by its "class" attribute
517
530
  * Example: And the ".contactUs" link should contain "/contact-" by attr
@@ -539,7 +552,8 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")*
539
552
  });
540
553
 
541
554
  /**
542
- * Checks, that HTML response contains specific text
555
+ * Checks, that HTML response contains specific text.
556
+ *
543
557
  * Example: Then the response should contain "Welcome visitor, How can I help you?"
544
558
  *
545
559
  */
@@ -550,7 +564,8 @@ Then(/^(the )*response should contain "([^"]*)?"$/, function (theCase, expectedT
550
564
  });
551
565
 
552
566
  /**
553
- * Checks, that HTML response contains specific text
567
+ * Checks, that HTML response contains specific text.
568
+ *
554
569
  * Example: Then the response should not contain "Error: Ambiguous messages that are unclear"
555
570
  *
556
571
  */
@@ -562,11 +577,12 @@ Then(/^(the )*response should not contain "([^"]*)?"$/, function (theCase, expec
562
577
 
563
578
 
564
579
  /**
565
- * Assert, that input text contains a specific value by its label
580
+ * Assert, that input text contains a specific value by its label.
581
+ *
566
582
  * Example: Then I should see "John Smith" in the "Username" element
567
583
  *
568
584
  */
569
- Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, expectedText,theCase , element) {
585
+ Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText,theCase , element) {
570
586
  const elementField = browser.element.findByText(element, { exact: true });
571
587
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
572
588
  return this.shouldSee = function (browser) {
@@ -576,12 +592,13 @@ Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (p
576
592
  });
577
593
 
578
594
  /**
579
- * Assert, that input text contains a specific value by its attributes
595
+ * Assert, that input text contains a specific value by its attributes.
596
+ *
580
597
  * Example: Then I should see "John Smith" in the "uname" element by its "id" attr
581
598
  * Example: Then I should see "1234" in the "pwordcss" element by attr
582
599
  *
583
600
  */
584
- Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
601
+ Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
585
602
 
586
603
  const hasASpace = attrValue.indexOf(' ');
587
604
 
@@ -602,11 +619,12 @@ Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([
602
619
  });
603
620
 
604
621
  /**
605
- * 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
+ *
606
624
  * Example: Then I should not see "Joe Smith" in the "Username" element
607
625
  *
608
626
  */
609
- Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, expectedText, theCase, element) {
627
+ Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase, element) {
610
628
 
611
629
  const elementField = browser.element.findByText(element, { exact: true });
612
630
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
@@ -617,12 +635,13 @@ Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, functio
617
635
  });
618
636
 
619
637
  /**
620
- * Assert, that input text contains a specific value by its attributes
638
+ * Assert, that input text contains a specific value by its attributes.
639
+ *
621
640
  * Example: Then I should not see "John Smith" in the "uname" element by its "id" attr
622
641
  * Example: Then I should not see "1234" in the "pwordcss" element by attr
623
642
  *
624
643
  */
625
- Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
644
+ Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
626
645
 
627
646
  const hasASpace = attrValue.indexOf(' ');
628
647
 
@@ -643,11 +662,12 @@ Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*(
643
662
  });
644
663
 
645
664
  /**
646
- * Assert, that element exists on current page by its label
665
+ * Assert, that element exists on current page by its label.
666
+ *
647
667
  * Example: Then I should see a "Username" element
648
668
  *
649
669
  */
650
- Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronoundCase, aAnCase, element) {
670
+ Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
651
671
  const elementField = browser.element.findByText(element, { exact: true });
652
672
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
653
673
  return browser.verify.visible('#' + eleAttribute.value);
@@ -655,12 +675,13 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronoundCase, a
655
675
  });
656
676
 
657
677
  /**
658
- * Assert, that element exists on the current page by its attribute
678
+ * Assert, that element exists on the current page by its attribute.
679
+ *
659
680
  * Example: Then I should see a "uname" element by its "id" attr
660
681
  * Example: Then I should see a "pwordcss" element by attr
661
682
  *
662
683
  */
663
- Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, aAnCase, attrValue, itsCase, attr, attrCase) {
684
+ Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
664
685
 
665
686
  const hasASpace = attrValue.indexOf(' ');
666
687
 
@@ -679,22 +700,23 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (att
679
700
  });
680
701
 
681
702
  /**
682
- * Assert, that element exists on current page by its label
703
+ * Assert, that element exists on current page by its label.
704
+ *
683
705
  * Example: Then I should not see a "Username" element
684
706
  *
685
707
  */
686
- Then(/^(I|we)* should not see (a|an) "([^"]*)?" element$/, function (pronoundCase, aAnCase, element) {
687
-
708
+ Then(/^(I|we)* should not see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
688
709
  browser.assert.not.textContains("html", element);
689
710
  });
690
711
 
691
712
  /**
692
- * Assert, that element exists on current page by its attributes
713
+ * Assert, that element exists on current page by its attributes.
714
+ *
693
715
  * Example: Then I should not see an "emailId" element by its "id" attr
694
716
  * Example: And I should not see a "countryCss" element by attr
695
717
  *
696
718
  */
697
- Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, aAnCase, attrValue, itsCase, attr, attrCase) {
719
+ Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
698
720
 
699
721
  const hasASpace = attrValue.indexOf(' ');
700
722
 
@@ -713,7 +735,8 @@ Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")*
713
735
  });
714
736
 
715
737
  /**
716
- * Assert, that element contains a specific CSS style
738
+ * Assert, that element contains a specific CSS style.
739
+ *
717
740
  * Example: Then the "body" element should contain "color:white;"
718
741
  *
719
742
  */
@@ -731,7 +754,8 @@ Then(/^(the )*"([^"]*)?" element should contain "([^"]*)?"$/, function (theCase
731
754
  });
732
755
 
733
756
  /**
734
- * Assert, that element contains a specific CSS style
757
+ * Assert, that element contains a specific CSS style.
758
+ *
735
759
  * Example: Then the "body" element should not contain "color:white;"
736
760
  * Example: Then the "#uname" element should not contain "border:solid 5px red;"
737
761
  * Example: Then the "pword" element should not contain "font-size: 26px;"
@@ -750,11 +774,12 @@ Then(/^(the )*"([^"]*)?" element should not contain "([^"]*)?"$/, function (theC
750
774
  });
751
775
 
752
776
  /**
753
- * Attaches file to field
777
+ * Attaches file to field.
778
+ *
754
779
  * Example: When I attach the file "profileIcon.jpg" to "#profileIconUpload"
755
780
  *
756
781
  */
757
- When(/^(I|we)* attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronoundCase, theCase, fileUrl, element) {
782
+ When(/^(I|we)* attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronounCase, theCase, fileUrl, element) {
758
783
  var dirname = __dirname + '';
759
784
  dirname = dirname.substring(0, dirname.lastIndexOf("/"));
760
785
 
@@ -762,7 +787,8 @@ When(/^(I|we)* attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronound
762
787
  });
763
788
 
764
789
  /**
765
- * Assert, that field contain a specific text
790
+ * Assert, that field contain a specific text.
791
+ *
766
792
  * Example: Then the "Username" field should contain "John Smith"
767
793
  *
768
794
  */
@@ -777,7 +803,8 @@ Then(/^(the )*"([^"]*)?" field should contain "([^"]*)?"$/, function (theCase, f
777
803
  });
778
804
 
779
805
  /**
780
- * Assert, that field does not contain a specific text
806
+ * Assert, that field does not contain a specific text.
807
+ *
781
808
  * Example: Then the "#username" field should not contain "John Smith"
782
809
  *
783
810
  */
@@ -789,7 +816,8 @@ Then(/^(the )*"([^"]*)?" field should not contain "([^"]*)?"$/, function (theCas
789
816
  });
790
817
 
791
818
  /**
792
- * Assert, that checkbox with specified element is should be checked
819
+ * Assert, that checkbox with specified element is should be checked.
820
+ *
793
821
  * Example: Then the "#PrivacyPolicy" checkbox should be checked
794
822
  *
795
823
  */
@@ -798,7 +826,8 @@ Then(/^(the )*"([^"]*)?" checkbox should be checked$/, function (theCase, checkb
798
826
  });
799
827
 
800
828
  /**
801
- * Assert, that checkbox with specified element is should not be checked
829
+ * Assert, that checkbox with specified element is should not be checked.
830
+ *
802
831
  * Example: Then the "#PrivacyPolicy" checkbox should not be checked
803
832
  *
804
833
  */
@@ -808,6 +837,7 @@ Then(/^(the )*"([^"]*)?" checkbox should not be checked$/, function (theCase, ch
808
837
 
809
838
  /**
810
839
  * Check, whether the checkbox specified is checked.
840
+ *
811
841
  * Example: Then the "#rememberMe" checkbox is checked
812
842
  *
813
843
  */
@@ -817,6 +847,7 @@ Then(/^(the )*"([^"]*)?" checkbox is checked$/, function (theCase, checkbox) {
817
847
 
818
848
  /**
819
849
  * Check, whether the checkbox specified is not checked.
850
+ *
820
851
  * Example: Then the "#rememberMe" checkbox is not checked
821
852
  *
822
853
  */
@@ -825,7 +856,8 @@ Then(/^(the )*"([^"]*)?" checkbox is not checked$/, function (theCase, checkbox)
825
856
  });
826
857
 
827
858
  /**
828
- * Assert, that checkbox with specified element should be checked
859
+ * Assert, that checkbox with specified element should be checked.
860
+ *
829
861
  * Example: Then the checkbox "#PrivacyPolicy" should be checked
830
862
  *
831
863
  */
@@ -834,7 +866,8 @@ Then(/^(the )*checkbox "([^"]*)?" should be checked$/, function (theCase, checkb
834
866
  });
835
867
 
836
868
  /**
837
- * Assert, that checkbox with specified element should not be checked
869
+ * Assert, that checkbox with specified element should not be checked.
870
+ *
838
871
  * Example: Then the checkbox "#PrivacyPolicy" should not be checked
839
872
  *
840
873
  */
@@ -843,7 +876,8 @@ Then(/^(the )*checkbox "([^"]*)?" should not be checked$/, function (theCase, ch
843
876
  });
844
877
 
845
878
  /**
846
- * Assert, that checkbox with specified element is checked
879
+ * Assert, that checkbox with specified element is checked.
880
+ *
847
881
  * Example: Then the checkbox "#rememberMe" is checked
848
882
  *
849
883
  */
@@ -852,7 +886,8 @@ Then(/^(the )*checkbox "([^"]*)?" is checked$/, function (theCase, checkbox) {
852
886
  });
853
887
 
854
888
  /**
855
- * Assert, that checkbox with specified element is not checked
889
+ * Assert, that checkbox with specified element is not checked.
890
+ *
856
891
  * Example: Then the checkbox "#rememberMe" is not checked
857
892
  *
858
893
  */
@@ -862,57 +897,63 @@ Then(/^(the )*checkbox "([^"]*)?" is not checked$/, function (theCase, checkbox)
862
897
 
863
898
  /**
864
899
  * Wait a specific number of seconds.
900
+ *
865
901
  * Example: When I wait 1 second
866
902
  * Example: When I wait 5 seconds
867
903
  * Example: When I wait 3s
868
904
  *
869
905
  */
870
- When(/^(I|we)* wait (\d*)( second)*(s)*$/, function (pronoundCase, number, withWord, withS) {
906
+ When(/^(I|we)* wait (\d*)( second)*(s)*$/, function (pronounCase, number, withWord, withS) {
871
907
  var waitTime = number * 1000;
872
908
  return browser.pause(waitTime);
873
909
  });
874
910
 
875
911
  /**
876
912
  * Wait a max number of seconds until the element present.
913
+ *
877
914
  * Example: When I wait max of 6 seconds
878
915
  *
879
916
  */
880
- When(/^(I|we)* wait max of (\d*)( second)*(s)*$/, function (pronoundCase, number, withWord, withS) {
917
+ When(/^(I|we)* wait max of (\d*)( second)*(s)*$/, function (pronounCase, number, withWord, withS) {
881
918
  var waitTime = number * 1000;
882
919
  return browser.waitForElementPresent('body', waitTime);
883
920
  });
884
921
 
885
922
  /**
886
923
  * Wait a specific number of minutes.
924
+ *
887
925
  * Example: When I wait 1 minute
888
926
  * Example: When I wait 5 minutes
889
927
  *
890
928
  */
891
- When(/^(I|we)* wait (\d*)( minute)*(m)*$/, function (pronoundCase, number, withWord, withM) {
929
+ When(/^(I|we)* wait (\d*)( minute)*(m)*$/, function (pronounCase, number, withWord, withM) {
892
930
  var waitTime = number * 1000 * 60;
893
931
  return browser.pause(waitTime);
894
932
  });
895
933
 
896
934
  /**
897
935
  * Wait a max number of minutes until the element present.
936
+ *
898
937
  * Example: When I wait max of 6 minutes
899
938
  *
900
939
  */
901
- When(/^(I|we)* wait max of (\d*)( minute)*(m)*$/, function (pronoundCase, number, withWord, withM) {
940
+ When(/^(I|we)* wait max of (\d*)( minute)*(m)*$/, function (pronounCase, number, withWord, withM) {
902
941
  var waitTime = number * 1000 * 60;
903
942
  return browser.waitForElementPresent('body', waitTime);
904
943
  });
905
944
 
906
945
  /**
907
946
  * Wait until the page is loaded.
947
+ *
908
948
  * Example: When I wait until the page is loaded
909
949
  *
910
950
  */
911
- When(/^(I|we)* wait until( the)* page( is)* loaded*$/, function (pronoundCase, theCase, withIs) {
951
+ When(/^(I|we)* wait until( the)* page( is)* loaded*$/, function (pronounCase, theCase, withIs) {
912
952
  return browser.waitForElementPresent('body', 10000);
913
953
  });
914
954
  /**
915
- * 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
+ *
916
957
  * Example: Then the response status code should be 200
917
958
  *
918
959
  */
@@ -932,7 +973,8 @@ Then(/^(the )*response status code should be (\d+)$/, function (theCase, expecte
932
973
  });
933
974
 
934
975
  /**
935
- * 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
+ *
936
978
  * Example: And the response status code should not be 404
937
979
  *
938
980
  */
@@ -952,11 +994,12 @@ Then(/^(the )*response status code should not be (\d+)$/, function ( theCase, ex
952
994
  });
953
995
 
954
996
  /**
955
- * Checks, that page contains text matching specified pattern
997
+ * Checks, that page contains text matching specified pattern.
998
+ *
956
999
  * Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
957
1000
  *
958
1001
  */
959
- Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronoundCase, textPattern) {
1002
+ Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
960
1003
  browser.elements('css selector', 'body', function (elements) {
961
1004
  elements.value.forEach(function (elementsObj) {
962
1005
  return browser.assert.textMatches(elementsObj, textPattern);
@@ -965,11 +1008,12 @@ Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronoundCase, te
965
1008
  });
966
1009
 
967
1010
  /**
968
- * Checks, that page not contains text matching specified pattern
1011
+ * Checks, that page not contains text matching specified pattern.
1012
+ *
969
1013
  * Example: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
970
1014
  *
971
1015
  */
972
- Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase, textPattern) {
1016
+ Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
973
1017
  browser.elements('css selector', 'body', function (elements) {
974
1018
  elements.value.forEach(function (elementsObj) {
975
1019
  return browser.assert.not.textMatches(elementsObj, textPattern);
@@ -978,31 +1022,34 @@ Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase
978
1022
  });
979
1023
 
980
1024
  /**
981
- * Checks, that page contains text matching specified pattern
1025
+ * Checks, that page contains text matching specified pattern.
1026
+ *
982
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
983
1028
  * //pattern of DD/MM/YYYY or DD-MM-YYYY
984
1029
  *
985
1030
  */
986
- Then(/^(I|we)* should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, textPattern, theCase, element) {
1031
+ Then(/^(I|we)* should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
987
1032
  return this.shouldSeePattern = function (browser) {
988
1033
  browser.assert.textMatches(element, textPattern);
989
1034
  };
990
1035
  });
991
1036
 
992
1037
  /**
993
- * Checks, that page contains text matching specified pattern
1038
+ * Checks, that page contains text matching specified pattern.
1039
+ *
994
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
995
1041
  * //pattern of DD/MM/YYYY or DD-MM-YYYY
996
1042
  *
997
1043
  */
998
- Then(/^(I|we)* should not see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, textPattern, element) {
1044
+ Then(/^(I|we)* should not see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, element) {
999
1045
  return this.shouldSeePattern = function (browser) {
1000
1046
  browser.assert.not.textMatches(element, textPattern);
1001
1047
  };
1002
1048
  });
1003
1049
 
1004
1050
  /**
1005
- * Checks, that current URL Path matches regular expression
1051
+ * Checks, that current URL Path matches regular expression.
1052
+ *
1006
1053
  * Example: Then the url should match "/contact-us.html"
1007
1054
  *
1008
1055
  */
@@ -1011,7 +1058,8 @@ Then(/^(the )*url should match "([^"]*)?"$/, function (theCase, pattern) {
1011
1058
  });
1012
1059
 
1013
1060
  /**
1014
- * Checks, that current URL Path matches regular expression
1061
+ * Checks, that current URL Path matches regular expression.
1062
+ *
1015
1063
  * Example: Then the url should not match "/contact-us.html"
1016
1064
  *
1017
1065
  */
@@ -1020,10 +1068,171 @@ Then(/^(the )*url should not match "([^"]*)?"$/, function (theCase, pattern) {
1020
1068
  });
1021
1069
 
1022
1070
  /**
1023
- * Checks, Scrolls to the bottom of the current page
1024
- * Example: When I scroll to the bottom
1071
+ * Scrolls down the page by a custom number of pixels specified by the user.
1025
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
1026
1077
  */
1027
- When(/^(I|we)* scroll to( the)* bottom$/, async function(pronoundCase, theCase) {
1028
- return browser.executeScript('window.scrollTo(0,document.body.scrollHeight);');
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
+ }
1029
1238
  });