webship-js 1.0.39 → 1.0.41

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 (48) hide show
  1. package/assets/config_templates/circleci-linux-chrome.conf.js +10 -1
  2. package/assets/config_templates/github-linux-chrome.conf.js +10 -1
  3. package/examples/test--when--i-scroll-functionality.html +176 -0
  4. package/lib/custom-hooks/before-after.js +30 -0
  5. package/nightwatch.conf.js +12 -3
  6. package/package.json +1 -1
  7. package/tests/features/test--given--i-am-on-homepage.feature +2 -2
  8. package/tests/features/test--then--i-should--not--see-text-in-element.feature +2 -2
  9. package/tests/features/test--then--i-should--see-text-in-element-by-attr.feature +2 -2
  10. package/tests/features/test--then--i-should--see-text-in-element.feature +2 -2
  11. package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +4 -4
  12. package/tests/features/test--then--i-should--see-text-matching-pattern.feature +5 -5
  13. package/tests/features/test--then--i-should-be-on-page.feature +2 -2
  14. package/tests/features/test--then--i-should-be-on-the-homepage.feature +2 -2
  15. package/tests/features/test--then--i-should-not-see-an-element-by-attr.feature +2 -2
  16. package/tests/features/test--then--i-should-not-see-an-element.feature +2 -2
  17. package/tests/features/test--then--i-should-see-an-element-by-attr.feature +2 -2
  18. package/tests/features/test--then--i-should-see-an-element.feature +2 -2
  19. package/tests/features/test--then--the-checkbox-is-checked.feature +2 -2
  20. package/tests/features/test--then--the-checkbox-should-be-checked.feature +2 -2
  21. package/tests/features/test--then--the-element-should-contain-cssproperty.feature +2 -2
  22. package/tests/features/test--then--the-element-should-not-contain-cssproperty.feature +2 -2
  23. package/tests/features/test--then--the-field-should-contain-value.feature +3 -3
  24. package/tests/features/test--then--the-response-should-contain.feature +3 -3
  25. package/tests/features/test--then--the-response-status-code-should-be.feature +2 -2
  26. package/tests/features/test--then--the-url-should-match.feature +3 -3
  27. package/tests/features/test--then-the-link-should-contain-by-attribute.feature +2 -3
  28. package/tests/features/test--then-the-link-should-contain.feature +2 -3
  29. package/tests/features/test--when--i-attach-file-to-feild.feature +3 -5
  30. package/tests/features/test--when--i-check-checkbox.feature +2 -3
  31. package/tests/features/test--when--i-click-link-by-attribute.feature +2 -3
  32. package/tests/features/test--when--i-click-link.feature +2 -3
  33. package/tests/features/test--when--i-fill-in-by-attr.feature +2 -2
  34. package/tests/features/test--when--i-fill-in-table-by-attr.feature +6 -6
  35. package/tests/features/test--when--i-fill-in.feature +4 -4
  36. package/tests/features/test--when--i-go-to-homepage.feature +3 -6
  37. package/tests/features/test--when--i-move-forward-backward-one-page.feature +2 -3
  38. package/tests/features/test--when--i-press-button-by-attribute.feature +2 -3
  39. package/tests/features/test--when--i-press-button.feature +7 -3
  40. package/tests/features/test--when--i-reload-page.feature +2 -3
  41. package/tests/features/test--when--i-scroll.feature +48 -0
  42. package/tests/features/test--when--i-select-option-from-dropdownlist.feature +15 -4
  43. package/tests/features/test--when--i-wait-page-is-loaded.feature +2 -3
  44. package/tests/features/test--when--i-wait-time.feature +3 -4
  45. package/tests/step-definitions/webship.js +543 -233
  46. package/examples/test--when--i-scroll-to-the-bottom.html +0 -49
  47. package/tests/features/test--when--i-scroll-to-the-bottom.feature +0 -9
  48. package/tests/features/test--when--i-select-option-from-dropdownlist-by-attr.feature +0 -16
@@ -1,112 +1,166 @@
1
- const { Given} = require('@cucumber/cucumber');
2
- const { When, Before} = require('@cucumber/cucumber');
3
- const { Then} = require('@cucumber/cucumber');
1
+ const { Given } = require('@cucumber/cucumber');
2
+ const { When } = require('@cucumber/cucumber');
3
+ const { Then } = require('@cucumber/cucumber');
4
+ require('../../lib/custom-hooks/before-after');
4
5
 
5
6
  const axios = require('axios');
6
-
7
+ const path = require('path');
7
8
 
8
9
  /**
9
10
  * Opens homepage.
10
- * Example: Given I am on homepage
11
- * Example: Given I am on the homepage
11
+ *
12
+ * Example #1: Given I am on homepage
13
+ * Example #2: Given I am on the homepage
14
+ * Example #2: Given I am on frontpage
15
+ * Example #3: Given I am on the frontpage
16
+ * Example #4: Given we are on homepage
17
+ * Example #5: Given on the homepage
18
+ * Example #6: Given on homepage
19
+ * Example #7: Given we are on the frontpage
20
+ * Example #8: Given on frontpage
21
+ *
12
22
  *
13
23
  */
14
- Given(/^(I am|we are) on( the)* homepage$/, function (pronoundCase, theCase) {
15
- return browser.url(browser.launch_url).waitForElementPresent('body', 1000);
24
+ Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
25
+ browser.url(browser.launch_url);
26
+ let defaultTime = 3000;
27
+ if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
28
+ defaultTime = browser.globals.minimum_wait_time.page;
29
+ }
30
+ return browser.waitForElementPresent('body', defaultTime);
16
31
  });
17
32
 
18
33
  /**
19
- * Open specific page
20
- * Example: Given I am on "about-us.html"
34
+ * Open specific page.
35
+ *
36
+ * Example #1: Given I am on "/about-us.html"
37
+ * Example #2: Given we are on "/about-us.html"
38
+ * Example #3: Given I am on the "/about-us.html" page
39
+ * Example #4: Given we are on the "/about-us.html" page
40
+ * Example #5: Given on "/about-us.html"
41
+ * Example #6: Given on the "/about-us.html" page
21
42
  *
22
43
  */
23
- Given(/^(I am|we are) on "([^"]*)?"$/, function (pronoundCase, url) {
24
- return browser.url(browser.launch_url + url).waitForElementPresent('body', 1000);
44
+ Given(/^(I am |we are )*on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
45
+ browser.url(browser.launch_url + url);
46
+ let defaultTime = 3000;
47
+ if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
48
+ defaultTime = browser.globals.minimum_wait_time.page;
49
+ }
50
+ return browser.waitForElementPresent('body', defaultTime);
25
51
  });
26
52
 
27
53
  /**
28
- * Go to homepage
29
- * Example: When I go to the homepage
30
- * Example: And I go to the "/"
54
+ * Go to homepage.
55
+ *
56
+ * Example #1: When I go to homepage
57
+ * Example #2: When I go to the homepage
58
+ * Example #3: When I navigate to the homepage
59
+ * Example #4: When navigating to the homepage
60
+ * Example #5: When navigating to homepage
61
+ * Example #6: When navigating to the frontpage
62
+ * Example #7: When we go to the homepage
63
+ * Example #8: When we navigate to the homepage
31
64
  *
32
65
  */
33
- When(/^(I|we)* go to( the)* homepage$/, function (pronoundCase, theCase) {
34
- return browser.url(browser.launch_url).waitForElementPresent('body', 1000);
66
+ When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
67
+ browser.url(browser.launch_url);
68
+ let defaultTime = 3000;
69
+ if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
70
+ defaultTime = browser.globals.minimum_wait_time.page;
71
+ }
72
+ return browser.waitForElementPresent('body', defaultTime);
35
73
  });
36
74
 
37
75
  /**
38
- * Go to specific page
39
- * Example: When I go to "contact-us.html"
76
+ * Go to specific page.
77
+ *
78
+ * Example #1: When I go to "/contact-us.html"
79
+ * Example #2: When I go to "/user/login"
80
+ * Example #3: When I navigate to "/admin/dashboard"
81
+ * Example #4: When navigating to "/products"
82
+ * Example #7: When we go to "/products"
83
+ * Example #8: When we navigate to "/terms"
40
84
  *
41
85
  */
42
- When(/^(I|we)* go to "([^"]*)?"$/, function (pronoundCase, url) {
43
- return browser.url(browser.launch_url + url).waitForElementPresent('body', 1000);
86
+ When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, function (pronounCase, url) {
87
+ browser.url(browser.launch_url + url);
88
+ let defaultTime = 3000;
89
+ if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
90
+ defaultTime = browser.globals.minimum_wait_time.page;
91
+ }
92
+ return browser.waitForElementPresent('body', defaultTime);
44
93
  });
45
94
 
46
95
  /**
47
96
  * Asserting a text in the page.
48
- *
49
- * Example:
50
- * - Then I should see "Welcome"
97
+ *
98
+ * Example #1: Then I should see "Welcome"
99
+ * Example #2: Then we should see "Your accounts for the group is public"
51
100
  *
52
101
  */
53
- Then(/^(I|we)* should see "([^"]*)?"$/, function (pronoundCase, expectedText) {
102
+ Then(/^(I |we )*should see "([^"]*)?"$/, function (pronounCase, expectedText) {
54
103
  return this.shouldSee = function (browser) {
55
104
  browser.assert.textContains("html", expectedText);
56
105
  };
57
106
  });
58
107
 
59
108
  /**
60
- * Asserting a text not in the page.
61
- *
62
- * Example:
63
- * - Then I should not see "Access denied"
109
+ * Asserting a text in the page.
110
+ *
111
+ * Example #1: Then I should not see "Access denied"
112
+ * Example #2: Then we should not see "Edit layout"
64
113
  *
65
114
  */
66
- Then(/^(I|we)* should not see "([^"]*)?"$/, function (pronoundCase, expectedText) {
115
+ Then(/^(I |we )*should not see "([^"]*)?"$/, function (pronounCase, expectedText) {
67
116
  return this.shouldSee = function (browser) {
68
117
  browser.assert.not.textContains("html", expectedText);
69
118
  };
70
119
  });
71
120
 
72
121
  /**
73
- * Moves forward one page in browser history
122
+ * Moves forward one page in browser history.
123
+ *
74
124
  * Example: When I move forward one page
75
125
  *
76
126
  */
77
- When(/^(I|we)* move forward one page$/, function (pronoundCase) {
127
+ When(/^(I |we )*move forward one page$/, function (pronounCase) {
78
128
  return browser.forward();
79
129
  });
80
130
 
81
131
  /**
82
- * Moves backward one page in browser history
132
+ * Moves backward one page in browser history.
133
+ *
83
134
  * Example: When I move backward one page
84
135
  *
85
136
  */
86
- When(/^(I|we)* move backward one page$/, function (pronoundCase) {
137
+ When(/^(I |we )*move backward one page$/, function (pronounCase) {
87
138
  return browser.back();
88
139
  });
89
140
 
90
141
  /**
91
- * Presses button with specified element
142
+ * Presses button with specified element.
143
+ *
92
144
  * Example: When I press "Log In"
93
- * Example: And I press "Log In"
145
+ * Example: And I press the "Log In" button
146
+ * Example: And I press the "Save as" button
94
147
  *
95
148
  */
96
- When(/^(I|we)* press "([^"]*)?"$/, function (pronoundCase, element) {
149
+ When(/^(I |we )*press( the)* "([^"]*)?"( button)*$/, function (pronounCase, theCase, element, buttonCase) {
97
150
  browser.click("[value='" + element +"']");
98
151
  });
99
152
 
100
153
  /**
101
- * Presses button with specified element
154
+ * Presses button with specified element.
155
+ *
102
156
  * Example: When I press "btn-pressid" by attr
103
157
  * Example: When I press "btn-pressid" by attribute
104
158
  * Example: And I press "Your full name" by "placeholder" attribute
105
159
  * Example: And I press "Your full name" by its "placeholder" attribute
106
- * Example: And I press "save-name" by "data-drupal-selector" attr
160
+ * Example: And I press "save-name" by "data-selector" attr
107
161
  *
108
162
  */
109
- When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, itsCase, attr, attrCase) {
163
+ When(/^(I |we )*press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
110
164
 
111
165
  const hasASpace = attrValue.indexOf(' ');
112
166
  var selector = '';
@@ -128,24 +182,26 @@ When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, func
128
182
  });
129
183
 
130
184
  /**
131
- * Clicks link with specified element
185
+ * Clicks link with specified element.
186
+ *
132
187
  * Example: When I click "Contact Us"
133
188
  * Example: And I click "aboutUs"
134
189
  *
135
190
  */
136
- When(/^(I|we)* click "([^"]*)?"$/, function (pronoundCase, item) {
191
+ When(/^(I |we )*click "([^"]*)?"$/, function (pronounCase, item) {
137
192
  return browser.click("link text", item);
138
193
  });
139
194
 
140
195
  /**
141
- * Click Link with specified element
142
- * Example: When I click "#aboutUsid" by attr
143
- * Example: When I click "aboutUsCss" by attribute
144
- * Example: And I click "aboutUsCss" by "class" attr
145
- * Example: And I click "aboutUsid" by its "id" attribute
196
+ * Click Link with specified element.
197
+ *
198
+ * Example: When I click "#about-us-id" by attr
199
+ * Example: When I click "data-selector-about" by attribute
200
+ * Example: And I click "about-us-css" by "class" attr
201
+ * Example: And I click "about-us-id" by its "id" attribute
146
202
  *
147
203
  */
148
- When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, itsCase, attr, attrCase) {
204
+ When(/^(I |we )*click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
149
205
 
150
206
  const hasASpace = attrValue.indexOf(' ');
151
207
  var selector = '';
@@ -168,33 +224,25 @@ When(/^(I|we)* click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, func
168
224
  });
169
225
 
170
226
  /**
171
- * Reloads current page
172
- * Example: When I reload page
173
- * Example: And I reload page
227
+ * Reloads current page.
174
228
  *
175
- */
176
-
177
- When(/^(I|we)* reload page$/, function (pronoundCase) {
178
- return browser.refresh(browser.getCurrentUrl());
179
- });
180
-
181
- /**
182
- * Reloads current page
183
- * Example: When I reload the page
184
- * Example: And I reload the page
229
+ * Example #1: When I reload
230
+ * Example #2: And I reload the page
231
+ * Example #3: And we reload page
232
+ * Example #4: And we reload the page
185
233
  *
186
234
  */
187
- When(/^(I|we)* reload( the)* page$/, function (pronoundCase, theCase) {
235
+ When(/^(I |we )*reload( the)*( page)*$/, function (pronounCase, theCase, pageCase) {
188
236
  return browser.refresh(browser.getCurrentUrl());
189
237
  });
190
238
 
191
-
192
239
  /**
193
240
  * Define the step of filling values in the form field specified element.
241
+ *
194
242
  * Example: When I fill in "Username" with "John Smith"
195
243
  *
196
244
  */
197
- When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, field, value) {
245
+ When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?"$/, function (pronounCase, field, value) {
198
246
  const elementField = browser.element.findByText(field, { exact: true });
199
247
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
200
248
  return browser.setValue('#' + eleAttribute.value, value);
@@ -202,14 +250,15 @@ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, fie
202
250
  });
203
251
 
204
252
  /**
205
- * Fill input type text with value by its attribute
253
+ * Fill input type text with value by its attribute.
254
+ *
206
255
  * Example: When I fill in "#uname" by attr
207
256
  * Example: When I fill in "uname" with "John Smith" by attr
208
257
  * Example: And I fill in "pwordcss" with "1234" by "class" attr
209
258
  * Example: And I fill in "Your full name" with "John Smith" by its "placeholder" attribute
210
259
  *
211
260
  */
212
- When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, txtValue, itsCase, attr, attrCase) {
261
+ When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, txtValue, itsCase, attr, attrCase) {
213
262
 
214
263
  const hasASpace = attrValue.indexOf(' ');
215
264
  var selector = '';
@@ -232,11 +281,12 @@ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attri
232
281
  });
233
282
 
234
283
  /**
235
- * Fill input type text with empty value by its Label
284
+ * Fill input type text with empty value by its Label.
285
+ *
236
286
  * Example: When I fill in "Username" with:
237
287
  *
238
288
  */
239
- When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronoundCase, field) {
289
+ When(/^(I |we )*fill in "([^"]*)?" with:$/, function (pronounCase, field) {
240
290
  const elementField = browser.element.findByText(field, { exact: true });
241
291
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
242
292
  return browser.setValue('#' + eleAttribute.value, '');
@@ -244,14 +294,15 @@ When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronoundCase, field) {
244
294
  });
245
295
 
246
296
  /**
247
- * Fill input type text with empty value by its attribute
297
+ * Fill input type text with empty value by its attribute.
298
+ *
248
299
  * Example: When I fill in "#uname" with: by attr
249
300
  * Example: When I fill in "uname" with: by attr
250
301
  * Example: And I fill in "pwordcss" with: by "class" attr
251
302
  * Example: And I fill in "Your full name" with: by its "placeholder" attribute
252
303
  *
253
304
  */
254
- When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue , itsCase, attr, attrCase) {
305
+ When(/^(I |we )*fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue , itsCase, attr, attrCase) {
255
306
 
256
307
  const hasASpace = attrValue.indexOf(' ');
257
308
  var selector = '';
@@ -273,11 +324,13 @@ When(/^(I|we)* fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)
273
324
  });
274
325
 
275
326
  /**
276
- * Fill in value for input type text by its Label
277
- * Example: When I fill in "webshipco" for "Username"
327
+ * Fill in value for input type text by its Label.
328
+ *
329
+ * Example #1: When I fill in "jon-smith" for "Username"
330
+ * Example #2: When we fill in "Testing" for "Organization options"
278
331
  *
279
332
  */
280
- When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, value, field) {
333
+ When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?"$/, function (pronounCase, value, field) {
281
334
  const elementField = browser.element.findByText(field, { exact: true });
282
335
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
283
336
  return browser.setValue('#' + eleAttribute.value, value);
@@ -285,14 +338,15 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, valu
285
338
  });
286
339
 
287
340
  /**
288
- * Fill in value for input type text by its attribute
289
- * Example: When I fill in "John Smith" for "#uname" by attr
290
- * Example: When I fill in "John Smith" for "uname" by attr
291
- * Example: And I fill in "1234" for "pwordcss" by "class" attr
292
- * Example: And I fill in "John Smith" for "Your full name" by its "placeholder" attribute
341
+ * Fill in value for input type text by its attribute.
342
+ *
343
+ * Example #1: When I fill in "John Smith" for "#uname" by attr
344
+ * Example #2: When I fill in "John Smith" for "uname" by attr
345
+ * Example #3: And I fill in "1234" for "password" by "class" attr
346
+ * Example #4: And I fill in "John Smith" for "Your full name" by its "placeholder" attribute
293
347
  *
294
348
  */
295
- When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, txtValue, attrValue, itsCase, attr, attrCase) {
349
+ When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, txtValue, attrValue, itsCase, attr, attrCase) {
296
350
 
297
351
  const hasASpace = attrValue.indexOf(' ');
298
352
  var selector = '';
@@ -315,13 +369,14 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attrib
315
369
  });
316
370
 
317
371
  /**
318
- * Fills in form input fields type text with provided table by there labels
372
+ * Fills in form input fields type text with provided table by there labels.
373
+ *
319
374
  * Example: When I fill in the following:
320
375
  * | Username | webshipco |
321
376
  * | Password | 1234 |
322
377
  */
323
378
 
324
- When(/^(I|we)* fill in( the)* following:$/, function (pronoundCase, theCase, table) {
379
+ When(/^(I |we )*fill in( the)* following:$/, function (pronounCase, theCase, table) {
325
380
 
326
381
  var elementField = browser.element.findByText(table.rawTable[0][0], { exact: true });
327
382
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
@@ -338,17 +393,18 @@ When(/^(I|we)* fill in( the)* following:$/, function (pronoundCase, theCase, tab
338
393
  });
339
394
 
340
395
  /**
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
342
- * Example: When I fill in the following: by attr
396
+ * Fill in value for input type text by its attributeFill form fields of type
397
+ * input Text with the provided table according to their attributes.
398
+ *
399
+ * Example #1: When I fill in the following: by attr
343
400
  * | #uname | John Smith |
344
- * | pwordcss | 1234 |
345
-
346
- * Example: When I fill in the following: by its "placeholder" attribute
401
+ * | password | 1234 |
402
+ *
403
+ * Example #2: When I fill in the following: by its "placeholder" attribute
347
404
  * | Your full name | John Smith |
348
405
  * | Your Password | 1234 |
349
406
  */
350
-
351
- When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, theCase, itsCase, attr, attrCase, table) {
407
+ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, theCase, itsCase, attr, attrCase, table) {
352
408
 
353
409
  var hasASpace = table.rawTable[0][0].indexOf(' ');
354
410
  var selector = '';
@@ -394,114 +450,133 @@ When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr
394
450
  });
395
451
 
396
452
  /**
397
- * Selecting the option in the dropdown list field by its text label
398
- * Example: When I select "Mercedes" from "Cars"
453
+ * Selecting the option in the dropdown list field by its text label.
399
454
  *
400
- */
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
455
+ * Example #1: When I select "Mercedes" from "Cars"
456
+ * Example #2: When I select "saab" from "#cars"
457
+ * Example #3: When I select "Mercedes" from "cars"
416
458
  *
417
459
  */
460
+ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, option, selectList) {
418
461
 
419
- When(/^(I|we)* select "([^"]*)?" from "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, option, attrValue, itsCase, attr, attrCase) {
462
+ const hasASpace = selectList.indexOf(' ');
420
463
 
421
- const hasASpace = attrValue.indexOf(' ');
422
-
423
- var selector = '';
424
- if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
425
- selector = attrValue;
464
+ let selector = '';
465
+ if((selectList.startsWith('#') || selectList.startsWith('.'))){
466
+ selector = selectList;
426
467
  }
427
- else if (!attr && hasASpace == -1){
428
- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
429
- }
430
- else if (!attr && hasASpace > -1){
431
- selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
468
+ else if (hasASpace == -1){
469
+ selector = '[name="' + selectList + '"],[id="' + selectList + '"],[class="' + selectList + '"]';
432
470
  }
433
471
  else {
434
- selector = '[' + attr + '="' + attrValue + '"]';
472
+ selector = browser.element.findByText(selectList, { exact: true });
435
473
  }
436
474
 
437
- return browser.waitForElementVisible('css selector', selector)
438
- .click(selector)
439
- .click(browser.element.findByText(option, { exact: true }))
440
- .click(selector);
475
+ let optionValue = '';
476
+ const result = option.toLowerCase();
477
+
478
+ if(result == option){
479
+ optionValue = '[value="' + option + '"]';
480
+ }
481
+ else{
482
+ optionValue = browser.element.findByText(option, { exact: true });
483
+ }
484
+
485
+ return browser.click(selector).click(optionValue).click(selector);
441
486
  });
442
487
 
443
488
  /**
444
- * Checks checkbox specified
445
- * Example: When I check "Remember me"
489
+ * Checks checkbox specified.
490
+ *
491
+ * Example #1: When I check "Remember me"
492
+ * Example #2: When we check "Put site into maintenance mode"
446
493
  *
447
494
  */
448
- When(/^(I|we)* check "([^"]*)?"$/, function (pronoundCase, item) {
449
-
495
+ When(/^(I |we )*check "([^"]*)?"$/, function (pronounCase, item) {
450
496
  browser.checkItem(item);
451
497
  });
452
498
 
453
499
  /**
454
- * Unchecks checkbox specified
455
- * Example: When I uncheck "Remember me"
500
+ * Unchecks checkbox specified.
501
+ *
502
+ * Example #1: When I uncheck "Remember me"
503
+ * Example #2: When we uncheck "Put site into maintenance mode"
456
504
  *
457
505
  */
458
- When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronoundCase, item) {
459
-
506
+ When(/^(I |we )*uncheck "([^"]*)?"$/, function (pronounCase, item) {
460
507
  browser.uncheckItem(item);
461
508
  });
462
509
 
463
510
  /**
464
- * Verify, that current page is the homepage
465
- * Example: Then I should be on homepage
466
- * Example: Then I should be on the homepage
511
+ * Verify, that current page is the homepage.
512
+ *
513
+ * Example #1: Then I should be on homepage
514
+ * Example #2: And I should be on the homepage
515
+ * Example #3: Then I should be on frontpage
516
+ * Example #4: And should be on the homepage
517
+ * Example #5: Then should be on homepage
518
+ * Example #6: And we should be on homepage
519
+ * Example #7: Then should be on frontpage
520
+ * Example #8: And we should be on the homepage
467
521
  *
468
522
  */
469
- Then(/^(I|we)* should be on( the)* homepage$/, function (pronoundCase, theCase) {
523
+ Then(/^(I |we )*should be on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
470
524
  return browser.assert.urlMatches(browser.launch_url);
471
525
  });
472
526
 
473
527
  /**
474
- * Verify, that current page is the homepage
475
- * Example: Then I should not be on homepage
528
+ * Verify, that current page is the homepage.
529
+ *
530
+ * Example #1: Then I should not be on homepage
531
+ * Example #2: And I should not be on the homepage
532
+ * Example #3: Then I should not be on frontpage
533
+ * Example #4: Then we should not be on homepage
534
+ * Example #5: Then should not be on the homepage
535
+ * Example #6: And we should not be on frontpage
536
+ * Example #7: And we should not be on the homepage
476
537
  *
477
538
  */
478
- Then(/^(I|we)* should not be on homepage$/, function (pronoundCase) {
539
+ Then(/^(I |we )*should not be on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
479
540
  return browser.assert.not.urlMatches(browser.launch_url);
480
541
  });
481
542
 
482
543
  /**
483
- * Verify, that current page is the homepage
484
- * Example: Then I should not be on the homepage
544
+ * Verify, that current page path is equal to specified path.
545
+ *
546
+ * Example #1: Then I should be on "/"
547
+ * Example #2: And I should be on "/user/login"
548
+ * Example #3: And I should be on "https://un.org"
549
+ * Example #4: Then we should be on the "/" page
550
+ * Example #5: And we should be on "/user/login"
551
+ * Example #6: And we should be on "https://google.com"
552
+ * Example #7: Then should be on the "/user/reset" page
553
+ * Example #8: And we should be on "https://x.com"
485
554
  *
486
555
  */
487
- Then(/^(I|we)* should not be on( the)* homepage$/, function (pronoundCase, theCase) {
488
- return browser.assert.not.urlMatches(browser.launch_url);
556
+ Then(/^(I |we )*should be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
557
+ return browser.assert.urlContains(url);
489
558
  });
490
559
 
491
560
  /**
492
- * Verify, that current page path is equal to specified path
493
- * Example: Then I should be on "/"
494
- * Example: And I should be on "/user/login"
495
- * Example: And I should be on "http://google.com"
561
+ * Verify, that current page path dose not equal to specified path.
562
+ *
563
+ * Example #1: Then I should not be on "/"
564
+ * Example #2: And I should not be on "/user/login"
565
+ * Example #3: And I should not be on "https://un.org"
566
+ * Example #4: Then we should not be on the "/" page
567
+ * Example #5: And we should not be on "/user/login"
568
+ * Example #6: Then we should not be on "https://google.com"
569
+ * Example #7: And should not be on "/user/reset"
570
+ * Example #8: And we should not be on the "https://x.com" page
496
571
  *
497
572
  */
498
-
499
- Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronoundCase, url) {
500
- return browser.assert.urlContains(url);
573
+ Then(/^(I |we )*should not be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
574
+ return browser.assert.not.urlContains(url);
501
575
  });
502
576
 
503
577
  /**
504
578
  * Verify, that the current link contains the specified URL.
579
+ *
505
580
  * Example: Then the "Login" link should contain "/log-in"
506
581
  *
507
582
  */
@@ -512,9 +587,10 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, el
512
587
 
513
588
  /**
514
589
  * Verify, that the current link contains the specified URL, found by its attributes.
515
- * Example: Then the "#aboutUsid" link should contain "about" by attr
516
- * Example: And the "aboutUs" link should contain "about" by its "class" attribute
517
- * Example: And the ".contactUs" link should contain "/contact-" by attr
590
+ *
591
+ * Example #1: Then the "#about-us-id" link should contain "about" by attr
592
+ * Example #2: And the "aboutUs" link should contain "about" by its "class" attribute
593
+ * Example #3: And the ".contactUs" link should contain "/contact-" by attr
518
594
  *
519
595
  */
520
596
  Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (theCase, attrValue, url, itsCase, attr, attrCase) {
@@ -539,8 +615,9 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")*
539
615
  });
540
616
 
541
617
  /**
542
- * Checks, that HTML response contains specific text
543
- * Example: Then the response should contain "Welcome visitor, How can I help you?"
618
+ * Checks, that HTML response contains specific text.
619
+ *
620
+ * Example #1: Then the response should contain "Welcome visitor, How can I help you?"
544
621
  *
545
622
  */
546
623
  Then(/^(the )*response should contain "([^"]*)?"$/, function (theCase, expectedText) {
@@ -550,8 +627,9 @@ Then(/^(the )*response should contain "([^"]*)?"$/, function (theCase, expectedT
550
627
  });
551
628
 
552
629
  /**
553
- * Checks, that HTML response contains specific text
554
- * Example: Then the response should not contain "Error: Ambiguous messages that are unclear"
630
+ * Checks, that HTML response dose not contains specific text.
631
+ *
632
+ * Example #1: Then the response should not contain "Welcome visitor, How can I help you?"
555
633
  *
556
634
  */
557
635
  Then(/^(the )*response should not contain "([^"]*)?"$/, function (theCase, expectedText) {
@@ -560,13 +638,14 @@ Then(/^(the )*response should not contain "([^"]*)?"$/, function (theCase, expec
560
638
  };
561
639
  });
562
640
 
563
-
564
641
  /**
565
- * Assert, that input text contains a specific value by its label
566
- * Example: Then I should see "John Smith" in the "Username" element
642
+ * Assert, that input text contains a specific value by its label.
643
+ *
644
+ * Example #1: Then I should see "John Smith" in the "Username" element
645
+ * Example #2: Then I should not see "Joe Smith" in the "Username" element
567
646
  *
568
647
  */
569
- Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, expectedText,theCase , element) {
648
+ Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase , element) {
570
649
  const elementField = browser.element.findByText(element, { exact: true });
571
650
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
572
651
  return this.shouldSee = function (browser) {
@@ -576,12 +655,13 @@ Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (p
576
655
  });
577
656
 
578
657
  /**
579
- * Assert, that input text contains a specific value by its attributes
658
+ * Assert, that input text contains a specific value by its attributes.
659
+ *
580
660
  * Example: Then I should see "John Smith" in the "uname" element by its "id" attr
581
661
  * Example: Then I should see "1234" in the "pwordcss" element by attr
582
662
  *
583
663
  */
584
- Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
664
+ Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
585
665
 
586
666
  const hasASpace = attrValue.indexOf(' ');
587
667
 
@@ -602,11 +682,12 @@ Then(/^(I|we)* should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([
602
682
  });
603
683
 
604
684
  /**
605
- * Assert, that input text does not contain a specific value to be by its label
685
+ * Assert, that input text does not contain a specific value to be by its label.
686
+ *
606
687
  * Example: Then I should not see "Joe Smith" in the "Username" element
607
688
  *
608
689
  */
609
- Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, expectedText, theCase, element) {
690
+ Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase, element) {
610
691
 
611
692
  const elementField = browser.element.findByText(element, { exact: true });
612
693
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
@@ -617,12 +698,13 @@ Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, functio
617
698
  });
618
699
 
619
700
  /**
620
- * Assert, that input text contains a specific value by its attributes
701
+ * Assert, that input text contains a specific value by its attributes.
702
+ *
621
703
  * Example: Then I should not see "John Smith" in the "uname" element by its "id" attr
622
704
  * Example: Then I should not see "1234" in the "pwordcss" element by attr
623
705
  *
624
706
  */
625
- Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
707
+ Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
626
708
 
627
709
  const hasASpace = attrValue.indexOf(' ');
628
710
 
@@ -643,11 +725,12 @@ Then(/^(I|we)* should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*(
643
725
  });
644
726
 
645
727
  /**
646
- * Assert, that element exists on current page by its label
728
+ * Assert, that element exists on current page by its label.
729
+ *
647
730
  * Example: Then I should see a "Username" element
648
731
  *
649
732
  */
650
- Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronoundCase, aAnCase, element) {
733
+ Then(/^(I |we )*should see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
651
734
  const elementField = browser.element.findByText(element, { exact: true });
652
735
  browser.getAttribute(elementField, 'for', function (eleAttribute) {
653
736
  return browser.verify.visible('#' + eleAttribute.value);
@@ -655,12 +738,13 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronoundCase, a
655
738
  });
656
739
 
657
740
  /**
658
- * Assert, that element exists on the current page by its attribute
741
+ * Assert, that element exists on the current page by its attribute.
742
+ *
659
743
  * Example: Then I should see a "uname" element by its "id" attr
660
744
  * Example: Then I should see a "pwordcss" element by attr
661
745
  *
662
746
  */
663
- Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, aAnCase, attrValue, itsCase, attr, attrCase) {
747
+ Then(/^(I |we )*should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
664
748
 
665
749
  const hasASpace = attrValue.indexOf(' ');
666
750
 
@@ -679,22 +763,23 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (att
679
763
  });
680
764
 
681
765
  /**
682
- * Assert, that element exists on current page by its label
766
+ * Assert, that element exists on current page by its label.
767
+ *
683
768
  * Example: Then I should not see a "Username" element
684
769
  *
685
770
  */
686
- Then(/^(I|we)* should not see (a|an) "([^"]*)?" element$/, function (pronoundCase, aAnCase, element) {
687
-
771
+ Then(/^(I |we )*should not see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
688
772
  browser.assert.not.textContains("html", element);
689
773
  });
690
774
 
691
775
  /**
692
- * Assert, that element exists on current page by its attributes
776
+ * Assert, that element exists on current page by its attributes.
777
+ *
693
778
  * Example: Then I should not see an "emailId" element by its "id" attr
694
779
  * Example: And I should not see a "countryCss" element by attr
695
780
  *
696
781
  */
697
- Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, aAnCase, attrValue, itsCase, attr, attrCase) {
782
+ Then(/^(I |we )*should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
698
783
 
699
784
  const hasASpace = attrValue.indexOf(' ');
700
785
 
@@ -713,7 +798,8 @@ Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")*
713
798
  });
714
799
 
715
800
  /**
716
- * Assert, that element contains a specific CSS style
801
+ * Assert, that element contains a specific CSS style.
802
+ *
717
803
  * Example: Then the "body" element should contain "color:white;"
718
804
  *
719
805
  */
@@ -731,10 +817,11 @@ Then(/^(the )*"([^"]*)?" element should contain "([^"]*)?"$/, function (theCase
731
817
  });
732
818
 
733
819
  /**
734
- * Assert, that element contains a specific CSS style
735
- * Example: Then the "body" element should not contain "color:white;"
736
- * Example: Then the "#uname" element should not contain "border:solid 5px red;"
737
- * Example: Then the "pword" element should not contain "font-size: 26px;"
820
+ * Assert, that element contains a specific CSS style.
821
+ *
822
+ * Example #1: Then the "body" element should not contain "color:white;"
823
+ * Example #2: Then the "#uname" element should not contain "border:solid 5px red;"
824
+ * Example #3: Then the "pword" element should not contain "font-size: 26px;"
738
825
  */
739
826
  Then(/^(the )*"([^"]*)?" element should not contain "([^"]*)?"$/, function (theCase, selector, elementCss) {
740
827
 
@@ -750,19 +837,32 @@ Then(/^(the )*"([^"]*)?" element should not contain "([^"]*)?"$/, function (theC
750
837
  });
751
838
 
752
839
  /**
753
- * Attaches file to field
754
- * Example: When I attach the file "profileIcon.jpg" to "#profileIconUpload"
840
+ * Attaches file to field.
841
+ *
842
+ * Example: When I attach the file "profileIcon.jpg" to "#profile-icon-upload"
755
843
  *
756
844
  */
757
- When(/^(I|we)* attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronoundCase, theCase, fileUrl, element) {
758
- var dirname = __dirname + '';
759
- dirname = dirname.substring(0, dirname.lastIndexOf("/"));
845
+ When(/^(I |we )*attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronounCase, theCase, fileName, element) {
846
+ // Construct local file path.
847
+ let assetsFolder;
848
+ if (browser.globals && browser.globals.assets_folder) {
849
+ assetsFolder = browser.globals.assets_folder;
850
+ } else {
851
+ assetsFolder = path.join(__dirname, '/tests/assets/');
852
+ }
760
853
 
761
- return browser.setValue(element, dirname + '/assets/' + fileUrl);
854
+ const localFilePath = path.resolve(assetsFolder, fileName);
855
+
856
+ browser.pause(5000);
857
+ browser.uploadFile(element, localFilePath);
858
+ browser.pause(10000);
859
+ return browser.setValue(element, fileName);
860
+
762
861
  });
763
862
 
764
863
  /**
765
- * Assert, that field contain a specific text
864
+ * Assert, that field contain a specific text.
865
+ *
766
866
  * Example: Then the "Username" field should contain "John Smith"
767
867
  *
768
868
  */
@@ -777,7 +877,8 @@ Then(/^(the )*"([^"]*)?" field should contain "([^"]*)?"$/, function (theCase, f
777
877
  });
778
878
 
779
879
  /**
780
- * Assert, that field does not contain a specific text
880
+ * Assert, that field does not contain a specific text.
881
+ *
781
882
  * Example: Then the "#username" field should not contain "John Smith"
782
883
  *
783
884
  */
@@ -789,7 +890,8 @@ Then(/^(the )*"([^"]*)?" field should not contain "([^"]*)?"$/, function (theCas
789
890
  });
790
891
 
791
892
  /**
792
- * Assert, that checkbox with specified element is should be checked
893
+ * Assert, that checkbox with specified element is should be checked.
894
+ *
793
895
  * Example: Then the "#PrivacyPolicy" checkbox should be checked
794
896
  *
795
897
  */
@@ -798,7 +900,8 @@ Then(/^(the )*"([^"]*)?" checkbox should be checked$/, function (theCase, checkb
798
900
  });
799
901
 
800
902
  /**
801
- * Assert, that checkbox with specified element is should not be checked
903
+ * Assert, that checkbox with specified element is should not be checked.
904
+ *
802
905
  * Example: Then the "#PrivacyPolicy" checkbox should not be checked
803
906
  *
804
907
  */
@@ -808,6 +911,7 @@ Then(/^(the )*"([^"]*)?" checkbox should not be checked$/, function (theCase, ch
808
911
 
809
912
  /**
810
913
  * Check, whether the checkbox specified is checked.
914
+ *
811
915
  * Example: Then the "#rememberMe" checkbox is checked
812
916
  *
813
917
  */
@@ -817,6 +921,7 @@ Then(/^(the )*"([^"]*)?" checkbox is checked$/, function (theCase, checkbox) {
817
921
 
818
922
  /**
819
923
  * Check, whether the checkbox specified is not checked.
924
+ *
820
925
  * Example: Then the "#rememberMe" checkbox is not checked
821
926
  *
822
927
  */
@@ -825,7 +930,8 @@ Then(/^(the )*"([^"]*)?" checkbox is not checked$/, function (theCase, checkbox)
825
930
  });
826
931
 
827
932
  /**
828
- * Assert, that checkbox with specified element should be checked
933
+ * Assert, that checkbox with specified element should be checked.
934
+ *
829
935
  * Example: Then the checkbox "#PrivacyPolicy" should be checked
830
936
  *
831
937
  */
@@ -834,7 +940,8 @@ Then(/^(the )*checkbox "([^"]*)?" should be checked$/, function (theCase, checkb
834
940
  });
835
941
 
836
942
  /**
837
- * Assert, that checkbox with specified element should not be checked
943
+ * Assert, that checkbox with specified element should not be checked.
944
+ *
838
945
  * Example: Then the checkbox "#PrivacyPolicy" should not be checked
839
946
  *
840
947
  */
@@ -843,7 +950,8 @@ Then(/^(the )*checkbox "([^"]*)?" should not be checked$/, function (theCase, ch
843
950
  });
844
951
 
845
952
  /**
846
- * Assert, that checkbox with specified element is checked
953
+ * Assert, that checkbox with specified element is checked.
954
+ *
847
955
  * Example: Then the checkbox "#rememberMe" is checked
848
956
  *
849
957
  */
@@ -852,7 +960,8 @@ Then(/^(the )*checkbox "([^"]*)?" is checked$/, function (theCase, checkbox) {
852
960
  });
853
961
 
854
962
  /**
855
- * Assert, that checkbox with specified element is not checked
963
+ * Assert, that checkbox with specified element is not checked.
964
+ *
856
965
  * Example: Then the checkbox "#rememberMe" is not checked
857
966
  *
858
967
  */
@@ -862,58 +971,93 @@ Then(/^(the )*checkbox "([^"]*)?" is not checked$/, function (theCase, checkbox)
862
971
 
863
972
  /**
864
973
  * Wait a specific number of seconds.
865
- * Example: When I wait 1 second
866
- * Example: When I wait 5 seconds
867
- * Example: When I wait 3s
974
+ *
975
+
976
+ * Example #1: When I wait 1 second
977
+ * Example #2: When I wait 5 seconds
978
+ * Example #3: When we wait 3s
979
+ * Example #4: And wait 2s
980
+ * Example #5: And wait 2 seconds
981
+ * Example #6: When we wait 1 second
982
+ * Example #7: When we wait 5 seconds
983
+ * Example #8: When we wait 4s
868
984
  *
869
985
  */
870
- When(/^(I|we)* wait (\d*)( second)*(s)*$/, function (pronoundCase, number, withWord, withS) {
986
+ When(/^(I |we )*wait (\d*)( second| seconds|s)?$/, function (pronounCase, number, withSecondWord) {
871
987
  var waitTime = number * 1000;
872
988
  return browser.pause(waitTime);
873
989
  });
874
990
 
875
991
  /**
876
992
  * Wait a max number of seconds until the element present.
877
- * Example: When I wait max of 6 seconds
993
+ *
994
+ * Example #1: When I wait max of 1 second
995
+ * Example #2: When I wait max of 5 seconds
996
+ * Example #3: When we wait max of 3s
997
+ * Example #4: And wait max of 2s
998
+ * Example #5: And wait max of 2 seconds
999
+ * Example #6: When we wait max of 1 second
1000
+ * Example #7: When we wait max of 5 seconds
1001
+ * Example #8: When we wait max of 4s
878
1002
  *
879
1003
  */
880
- When(/^(I|we)* wait max of (\d*)( second)*(s)*$/, function (pronoundCase, number, withWord, withS) {
1004
+ When(/^(I |we )*wait max of (\d*)( second| seconds|s)?$/, function (pronounCase, number, withSecondWord) {
881
1005
  var waitTime = number * 1000;
882
1006
  return browser.waitForElementPresent('body', waitTime);
883
1007
  });
884
1008
 
885
1009
  /**
886
1010
  * Wait a specific number of minutes.
887
- * Example: When I wait 1 minute
888
- * Example: When I wait 5 minutes
1011
+ *
1012
+ * Example #1: When I wait 1 minute
1013
+ * Example #2: When I wait 10 minutes
1014
+ * Example #3: When we wait 1m
1015
+ * Example #4: And wait 2s
1016
+ * Example #5: And wait 2 minutes
1017
+ * Example #6: When we wait 1 minute
1018
+ * Example #7: When we wait 10 minutes
1019
+ * Example #8: When we wait 2m
889
1020
  *
890
1021
  */
891
- When(/^(I|we)* wait (\d*)( minute)*(m)*$/, function (pronoundCase, number, withWord, withM) {
1022
+ When(/^(I |we )*wait (\d*)( minute| minutes|m)?$/, function (pronounCase, number, withMinuteWord) {
892
1023
  var waitTime = number * 1000 * 60;
893
1024
  return browser.pause(waitTime);
894
1025
  });
895
1026
 
896
1027
  /**
897
1028
  * Wait a max number of minutes until the element present.
898
- * Example: When I wait max of 6 minutes
1029
+ *
1030
+ * Example #1: When I wait 1 minute
1031
+ * Example #2: When I wait 10 minutes
1032
+ * Example #3: When we wait 1m
1033
+ * Example #4: And wait 2s
1034
+ * Example #5: And wait 2 minutes
1035
+ * Example #6: When we wait 1 minute
1036
+ * Example #7: When we wait 10 minutes
1037
+ * Example #8: When we wait 2m
899
1038
  *
900
1039
  */
901
- When(/^(I|we)* wait max of (\d*)( minute)*(m)*$/, function (pronoundCase, number, withWord, withM) {
1040
+ When(/^(I |we )*wait max of (\d*)( minute| minutes|m)?$/, function (pronounCase, number, withMinuteWord) {
902
1041
  var waitTime = number * 1000 * 60;
903
1042
  return browser.waitForElementPresent('body', waitTime);
904
1043
  });
905
1044
 
906
1045
  /**
907
1046
  * Wait until the page is loaded.
908
- * Example: When I wait until the page is loaded
1047
+ *
1048
+ * Example #1: When I wait until the page is loaded
1049
+ * Example #1: When we wait until the page is loaded
1050
+ * Example #2: When wait until page loaded
909
1051
  *
910
1052
  */
911
- When(/^(I|we)* wait until( the)* page( is)* loaded*$/, function (pronoundCase, theCase, withIs) {
1053
+ When(/^(I |we )*wait until( the)* page( is)* loaded*$/, function (pronounCase, theCase, withIs) {
912
1054
  return browser.waitForElementPresent('body', 10000);
913
1055
  });
1056
+
914
1057
  /**
915
- * Checks, that the current page response status is equal the specified code
916
- * Example: Then the response status code should be 200
1058
+ * Checks, that the current page response status is equal the specified code.
1059
+ *
1060
+ * Example #1: Then the response status code should be 200
917
1061
  *
918
1062
  */
919
1063
  Then(/^(the )*response status code should be (\d+)$/, function (theCase, expectedStatusCode) {
@@ -932,8 +1076,9 @@ Then(/^(the )*response status code should be (\d+)$/, function (theCase, expecte
932
1076
  });
933
1077
 
934
1078
  /**
935
- * Checks, that the current page response status is not equal the specified code
936
- * Example: And the response status code should not be 404
1079
+ * Checks, that the current page response status is not equal the specified code.
1080
+ *
1081
+ * Example #1: And the response status code should not be 404
937
1082
  *
938
1083
  */
939
1084
  Then(/^(the )*response status code should not be (\d+)$/, function ( theCase, expectedStatusCode) {
@@ -952,11 +1097,12 @@ Then(/^(the )*response status code should not be (\d+)$/, function ( theCase, ex
952
1097
  });
953
1098
 
954
1099
  /**
955
- * Checks, that page contains text matching specified pattern
1100
+ * Checks, that page contains text matching specified pattern.
1101
+ *
956
1102
  * Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
957
1103
  *
958
1104
  */
959
- Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronoundCase, textPattern) {
1105
+ Then(/^(I |we )*should see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
960
1106
  browser.elements('css selector', 'body', function (elements) {
961
1107
  elements.value.forEach(function (elementsObj) {
962
1108
  return browser.assert.textMatches(elementsObj, textPattern);
@@ -965,11 +1111,12 @@ Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronoundCase, te
965
1111
  });
966
1112
 
967
1113
  /**
968
- * Checks, that page not contains text matching specified pattern
969
- * Example: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
1114
+ * Checks, that page not contains text matching specified pattern.
1115
+ *
1116
+ * Example #1: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
970
1117
  *
971
1118
  */
972
- Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase, textPattern) {
1119
+ Then(/^(I |we )*should not see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
973
1120
  browser.elements('css selector', 'body', function (elements) {
974
1121
  elements.value.forEach(function (elementsObj) {
975
1122
  return browser.assert.not.textMatches(elementsObj, textPattern);
@@ -978,31 +1125,32 @@ Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase
978
1125
  });
979
1126
 
980
1127
  /**
981
- * Checks, that page contains text matching specified pattern
982
- * 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
- * //pattern of DD/MM/YYYY or DD-MM-YYYY
1128
+ * Checks, that page contains text matching specified pattern.
1129
+ *
1130
+ * Example #1: 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
1131
+ * // pattern of DD/MM/YYYY or DD-MM-YYYY
984
1132
  *
985
1133
  */
986
- Then(/^(I|we)* should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, textPattern, theCase, element) {
1134
+ Then(/^(I |we )*should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
987
1135
  return this.shouldSeePattern = function (browser) {
988
1136
  browser.assert.textMatches(element, textPattern);
989
1137
  };
990
1138
  });
991
1139
 
992
1140
  /**
993
- * Checks, that page contains text matching specified pattern
994
- * 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
- * //pattern of DD/MM/YYYY or DD-MM-YYYY
1141
+ * Checks, that page dose not contain text matching specified pattern.
1142
+ *
1143
+ * Example #1: 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
1144
+ * // pattern of DD/MM/YYYY or DD-MM-YYYY
996
1145
  *
997
1146
  */
998
- Then(/^(I|we)* should not see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronoundCase, textPattern, element) {
999
- return this.shouldSeePattern = function (browser) {
1000
- browser.assert.not.textMatches(element, textPattern);
1001
- };
1147
+ Then(/^(I |we )*should not see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
1148
+ return browser.assert.not.textMatches(element, textPattern);
1002
1149
  });
1003
1150
 
1004
1151
  /**
1005
- * Checks, that current URL Path matches regular expression
1152
+ * Checks, that current URL Path matches regular expression.
1153
+ *
1006
1154
  * Example: Then the url should match "/contact-us.html"
1007
1155
  *
1008
1156
  */
@@ -1011,7 +1159,8 @@ Then(/^(the )*url should match "([^"]*)?"$/, function (theCase, pattern) {
1011
1159
  });
1012
1160
 
1013
1161
  /**
1014
- * Checks, that current URL Path matches regular expression
1162
+ * Checks, that current URL Path matches regular expression.
1163
+ *
1015
1164
  * Example: Then the url should not match "/contact-us.html"
1016
1165
  *
1017
1166
  */
@@ -1020,10 +1169,171 @@ Then(/^(the )*url should not match "([^"]*)?"$/, function (theCase, pattern) {
1020
1169
  });
1021
1170
 
1022
1171
  /**
1023
- * Checks, Scrolls to the bottom of the current page
1024
- * Example: When I scroll to the bottom
1172
+ * Scrolls down the page by a custom number of pixels specified by the user.
1025
1173
  *
1174
+ * Example #1: And I scroll down
1175
+ * Example #2: When I scroll down 800
1176
+ * Example #3: And we scroll down 500
1177
+ * Example #4: When scrolling down 1200
1026
1178
  */
1027
- When(/^(I|we)* scroll to( the)* bottom$/, async function(pronoundCase, theCase) {
1028
- return browser.executeScript('window.scrollTo(0,document.body.scrollHeight);');
1029
- });
1179
+ When(/^(I scroll|we scroll|scrolling)? down( ([^"]*)?)*$/, function(pronounCase, value) {
1180
+ // Default scroll value
1181
+ let scrollValue = 350;
1182
+
1183
+ if (value !== null) {
1184
+ scrollValue = parseInt(String(value).trim(), 10);
1185
+
1186
+ // Validate the parsed value
1187
+ if (isNaN(scrollValue)) {
1188
+ throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
1189
+ }
1190
+
1191
+ if (scrollValue < 0) {
1192
+ throw new Error(`Scroll down value must be positive. Received: ${scrollValue}`);
1193
+ }
1194
+
1195
+ if (scrollValue > 10000) {
1196
+ console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
1197
+ }
1198
+ }
1199
+
1200
+ return browser.executeScript(`window.scrollBy(0, ${scrollValue});`);
1201
+ });
1202
+
1203
+ /**
1204
+ * Scrolls up the page by a custom number of pixels specified by the user.
1205
+ *
1206
+ * Example #1: And I scroll up
1207
+ * Example #2: When I scroll up 1000
1208
+ * Example #3: And we scrolling up 300
1209
+ * Example #4: When scrolling up 750
1210
+ *
1211
+ */
1212
+ When(/^(I scroll|we scroll|scrolling)? up( ([^"]*)?)*$/, function(pronounCase, value) {
1213
+ // Parse and validate the scroll value
1214
+ let scrollValue = 350; // default value
1215
+
1216
+ if (value !== null) {
1217
+ scrollValue = parseInt(String(value).trim(), 10);
1218
+
1219
+ // Validate the parsed value
1220
+ if (isNaN(scrollValue)) {
1221
+ throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
1222
+ }
1223
+
1224
+ if (scrollValue < 0) {
1225
+ throw new Error(`Scroll up value must be positive. Received: ${scrollValue}`);
1226
+ }
1227
+
1228
+ if (scrollValue > 10000) {
1229
+ console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
1230
+ }
1231
+ }
1232
+
1233
+ // Make the value negative for scrolling up
1234
+ return browser.executeScript(`window.scrollBy(0, -${scrollValue});`);
1235
+ });
1236
+
1237
+ /**
1238
+ * Scrolls to the very top of the current page, resetting the scroll position to zero.
1239
+ *
1240
+ * Example #1: When I scroll to top
1241
+ * Example #2: And we scrolling to the top
1242
+ * Example #3: When scrolling to the top of the page
1243
+ */
1244
+ When(/^(I scroll|we scroll|scrolling)? to( the)* top( of the page)*$/, function(pronounCase, theCase, pageCase) {
1245
+ return browser.executeScript('document.documentElement.scrollTop = 0;');
1246
+ });
1247
+
1248
+ /**
1249
+ * Scrolls to the bottom of the current page using the full document height.
1250
+ *
1251
+ * Example #1: When I scroll to the bottom
1252
+ * Example #2: And we scroll to bottom
1253
+ * Example #3: When scrolling to the bottom of the page
1254
+ */
1255
+ When(/^(I scroll|we scroll|scrolling)? to( the)* bottom( of the page)*$/, function(pronounCase, theCase, pageCase) {
1256
+ return browser.executeScript('window.scrollTo(0, document.body.scrollHeight);');
1257
+ });
1258
+
1259
+ /**
1260
+ * Scrolls to the top of a specific element identified by a CSS selector, resetting its scroll position to zero.
1261
+ *
1262
+ * Example #1: When I scroll to top of "#off-canvas"
1263
+ * Example #2: And we scroll to top of "#sidebar"
1264
+ * Example #3: When scrolling to top of "#main-container"
1265
+ */
1266
+ When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, function(pronounCase, selector) {
1267
+ // Validate selector
1268
+ if (!selector || selector.trim() === '') {
1269
+ throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
1270
+ }
1271
+
1272
+ // Validate selector format (basic check)
1273
+ if (selector.includes('"') || selector.includes("'")) {
1274
+ throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
1275
+ }
1276
+
1277
+ try {
1278
+ // Check if element exists before scrolling
1279
+ const elementExists = browser.executeScript(`
1280
+ return document.querySelector("${selector}") !== null;
1281
+ `);
1282
+
1283
+ if (!elementExists) {
1284
+ throw new Error(`Element with selector "${selector}" not found.`);
1285
+ }
1286
+
1287
+ browser.executeScript(`
1288
+ const element = document.querySelector("${selector}");
1289
+ if (element) {
1290
+ element.scrollTop = 0;
1291
+ }
1292
+ `);
1293
+
1294
+ return browser.pause(2000);
1295
+ } catch (error) {
1296
+ throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
1297
+ }
1298
+ });
1299
+
1300
+ /**
1301
+ * Scrolls to the bottom of a specific element identified by a CSS selector, moving to its maximum scroll height.
1302
+ *
1303
+ * Example #1: When I scroll to bottom of "#off-canvas"
1304
+ * Example #2: And we scrolling to bottom of "#sidebar"
1305
+ * Example #3: When scrolling to bottom of "#main-container"
1306
+ */
1307
+ When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, function(pronounCase, selector) {
1308
+ // Validate selector
1309
+ if (!selector || selector.trim() === '') {
1310
+ throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
1311
+ }
1312
+
1313
+ // Validate selector format (basic check)
1314
+ if (selector.includes('"') || selector.includes("'")) {
1315
+ throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
1316
+ }
1317
+
1318
+ try {
1319
+ // Check if element exists before scrolling
1320
+ const elementExists = browser.executeScript(`
1321
+ return document.querySelector("${selector}") !== null;
1322
+ `);
1323
+
1324
+ if (!elementExists) {
1325
+ throw new Error(`Element with selector "${selector}" not found.`);
1326
+ }
1327
+
1328
+ browser.executeScript(`
1329
+ const element = document.querySelector("${selector}");
1330
+ if (element) {
1331
+ element.scrollTop = element.scrollHeight;
1332
+ }
1333
+ `);
1334
+
1335
+ return browser.pause(2000);
1336
+ } catch (error) {
1337
+ throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
1338
+ }
1339
+ });