webship-js 1.0.23 → 1.0.25

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 (33) hide show
  1. package/.github/workflows/github-actions.yml +29 -8
  2. package/README.md +4 -7
  3. package/assets/config_templates/circleci-linux-chrome.conf.js +8 -3
  4. package/bitbucket-pipelines.yml +1 -1
  5. package/examples/test--then--i-should--see-text-in-element.html +48 -0
  6. package/examples/test--when--i-check-uncheck-checkbox.html +5 -3
  7. package/lib/custom-assertions/checkboxChecked.js +33 -0
  8. package/lib/custom-assertions/elementContainsCss.js +32 -0
  9. package/lib/custom-assertions/elementContainsText.js +32 -0
  10. package/lib/custom-assertions/responseStatus.js +1 -1
  11. package/lib/custom-assertions/shouldVisible.js +1 -1
  12. package/lib/custom-assertions/textMatching.js +32 -0
  13. package/lib/custom-commands/checkItem.js +21 -16
  14. package/lib/custom-commands/uncheckItem.js +21 -16
  15. package/nightwatch.conf.js +5 -1
  16. package/package.json +14 -14
  17. package/tests/features/test--then--i-should--not--see-text-in-element.feature +8 -8
  18. package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +0 -5
  19. package/tests/features/test--then--the-checkbox-is-checked.feature +9 -9
  20. package/tests/features/test--then--the-checkbox-should-be-checked.feature +3 -3
  21. package/tests/features/test--then--the-element-should_not-contain-cssproperty.feature +2 -2
  22. package/tests/features/test--then--the-field-should-contain-value.feature +4 -4
  23. package/tests/features/test--then--the-response-status-code-should-be.feature +4 -4
  24. package/tests/features/test--when--i-attach-file-to-feild.feature +5 -5
  25. package/tests/features/test--when--i-check-checkbox.feature +14 -9
  26. package/tests/features/test--when--i-click-link.feature +1 -7
  27. package/tests/features/test--when--i-fill-in.feature +7 -7
  28. package/tests/features/test--when--i-go-to-homepage.feature +10 -0
  29. package/tests/features/test--when--i-move-forward-backward-one-page.feature +2 -2
  30. package/tests/features/test--when--i-select-option-from-dropdownlist.feature +1 -1
  31. package/tests/step-definitions/webship.js +371 -102
  32. package/lib/custom-assertions/backToHomepage.js +0 -15
  33. package/tests/features/test--when--i-uncheck-checkbox.feature +0 -18
@@ -1,17 +1,24 @@
1
- const { Given } = require('@cucumber/cucumber');
2
- const { When, Before } = require('@cucumber/cucumber');
3
- const { Then } = require('@cucumber/cucumber');
4
- const { endsWith } = require('lodash');
1
+ const { Given} = require('@cucumber/cucumber');
2
+ const { When, Before} = require('@cucumber/cucumber');
3
+ const { Then} = require('@cucumber/cucumber');
5
4
 
6
5
  const request = require('request');
7
6
 
8
7
  /**
9
8
  * Opens homepage.
10
9
  * Example: Given I am on homepage
10
+ *
11
+ */
12
+ Given(/^(I am|we are) on homepage$/, function (pronoundCase) {
13
+ return browser.url(browser.launch_url);
14
+ });
15
+
16
+ /**
17
+ * Opens homepage.
11
18
  * Example: Given I am on the homepage
12
19
  *
13
20
  */
14
- Given(/^(I am|we are) on( the)* homepage$/, function (pronoundCase, theCase) {
21
+ Given(/^(I am|we are) on the homepage$/, function (pronoundCase) {
15
22
  return browser.url(browser.launch_url);
16
23
  });
17
24
 
@@ -26,11 +33,21 @@ Given(/^(I am|we are) on "([^"]*)?"$/, function (pronoundCase, url) {
26
33
 
27
34
  /**
28
35
  * Go to homepage
29
- * Example: When I go to the homepage
36
+ * Example: When I go to homepage
30
37
  * Example: And I go to "/"
31
38
  *
32
39
  */
33
- When(/^(I|we)* go to( the)* homepage$/, function (pronoundCase, theCase) {
40
+ When(/^(I|we)* go to homepage$/, function (pronoundCase) {
41
+ return browser.url(browser.launch_url);
42
+ });
43
+
44
+ /**
45
+ * Go to homepage
46
+ * Example: When I go to the homepage
47
+ * Example: And I go to the "/"
48
+ *
49
+ */
50
+ When(/^(I|we)* go to the homepage$/, function (pronoundCase) {
34
51
  return browser.url(browser.launch_url);
35
52
  });
36
53
 
@@ -48,15 +65,25 @@ When(/^(I|we)* go to "([^"]*)?"$/, function (pronoundCase, url) {
48
65
  *
49
66
  * Example:
50
67
  * - Then I should see "Welcome"
68
+ *
69
+ */
70
+ Then(/^(I|we)* should see "([^"]*)?"$/, function (pronoundCase, expectedText) {
71
+ browser.assert.textContains("html", expectedText);
72
+ });
73
+
74
+ /**
75
+ * Asserting a text not in the page.
76
+ *
77
+ * Example:
51
78
  * - Then I should not see "Access denied"
52
79
  *
53
80
  */
54
- Then(/^(I|we)* should( not)* see "([^"]*)?"$/, function (pronoundCase, negativeCase, expectedText) {
55
- return browser.assert.elementContainsText(negativeCase, expectedText, "html");
81
+ Then(/^(I|we)* should not see "([^"]*)?"$/, function (pronoundCase, expectedText) {
82
+ browser.assert.not.textContains("html", expectedText);
56
83
  });
57
84
 
58
85
  /**
59
- * Moves forward one page in history
86
+ * Moves forward one page in browser history
60
87
  * Example: When I move forward one page
61
88
  *
62
89
  */
@@ -65,7 +92,7 @@ When(/^(I|we)* move forward one page$/, function (pronoundCase) {
65
92
  });
66
93
 
67
94
  /**
68
- * Moves backward one page in history
95
+ * Moves backward one page in browser history
69
96
  * Example: When I move backward one page
70
97
  *
71
98
  */
@@ -74,23 +101,33 @@ When(/^(I|we)* move backward one page$/, function (pronoundCase) {
74
101
  });
75
102
 
76
103
  /**
77
- * Presses button with specified id|class|name|value
104
+ * Presses button with specified element
78
105
  * Example: When I press "Log In"
79
106
  * Example: And I press "Log In"
80
107
  *
81
108
  */
82
- When(/^(I|we)* press "([^"]*)?"$/, function (pronoundCase, elementValue) {
83
- return browser.press(elementValue);
109
+ When(/^(I|we)* press "([^"]*)?"$/, function (pronoundCase, element) {
110
+ browser.click('[value="' + element + '"]');
84
111
  });
85
112
 
86
113
  /**
87
- * Clicks link with specified id|class|name|text
114
+ * Clicks link with specified element
88
115
  * Example: When I click "Contact Us"
89
116
  * Example: And I click "aboutUs"
90
117
  *
91
118
  */
92
119
  When(/^(I|we)* click "([^"]*)?"$/, function (pronoundCase, item) {
93
- browser.clickLink(item);
120
+ return browser.click("link text", item);
121
+ });
122
+
123
+ /**
124
+ * Reloads current page
125
+ * Example: When I reload page
126
+ * Example: And I reload page
127
+ *
128
+ */
129
+ When(/^(I|we)* reload page$/, function (pronoundCase) {
130
+ return browser.refresh(browser.getCurrentUrl());
94
131
  });
95
132
 
96
133
  /**
@@ -99,35 +136,36 @@ When(/^(I|we)* click "([^"]*)?"$/, function (pronoundCase, item) {
99
136
  * Example: And I reload the page
100
137
  *
101
138
  */
102
- When(/^(I|we)* reload( the)* page$/, function (pronoundCase, theCase) {
139
+ When(/^(I|we)* reload the page$/, function (pronoundCase) {
103
140
  return browser.refresh(browser.getCurrentUrl());
104
141
  });
105
142
 
143
+
106
144
  /**
107
- * Define the step of filling values in the form field specified by id|class|name|label.
145
+ * Define the step of filling values in the form field specified element.
108
146
  * Example: When I fill in "Username" with "John Smith"
109
147
  *
110
148
  */
111
149
  When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, field, value) {
112
- browser.fillTextInput(field, value);
150
+ browser.setValue(field, value);
113
151
  });
114
152
 
115
153
  /**
116
- * Fills in form field with specified id|class|name|label
154
+ * Fills in form field with specified element
117
155
  * Example: When I fill in "username" with:
118
156
  *
119
157
  */
120
158
  When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronoundCase, field) {
121
- browser.fillTextInput(field, '');
159
+ browser.setValue(field, '');
122
160
  });
123
161
 
124
162
  /**
125
- * Fills in form field with specified id|class|name|label
163
+ * Fills in form field with specified element
126
164
  * Example: And I fill in "webshipco" for "username"
127
165
  *
128
166
  */
129
167
  When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, value, field) {
130
- browser.fillTextInput(field, value);
168
+ browser.setValue(field, value);
131
169
  });
132
170
 
133
171
  /**
@@ -142,37 +180,50 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, valu
142
180
  */
143
181
  When(/^(I|we)* fill in the following:$/, function (pronoundCase, table) {
144
182
 
145
- browser.fillTextInput(table.rawTable[0][0], table.rawTable[0][1]);
183
+ browser.setValue(table.rawTable[0][0], table.rawTable[0][1]);
146
184
  table.rows().forEach(row => {
147
- browser.fillTextInput(row[0], row[1]);
185
+ browser.setValue(row[0], row[1]);
186
+ // browser.fillTextInput(row[0], row[1]);
148
187
  });
149
188
  });
150
189
 
151
190
  /**
152
- * Selects option in select field with specified id|class|name|label
191
+ * Selects option in select field
153
192
  * Example: When I select "mercedes" from "Cars"
154
193
  *
155
194
  */
156
195
  When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronoundCase, option, dropdownlist) {
157
- browser.selectOption(option, dropdownlist);
196
+
197
+ return browser.click('select' + dropdownlist + ' option[value=' + option + ']');
158
198
  });
159
199
 
160
200
  /**
161
- * Checks checkbox specified by id|class|name|label
201
+ * Checks checkbox specified
162
202
  * Example: When I check "Remember me"
163
203
  *
164
204
  */
165
205
  When(/^(I|we)* check "([^"]*)?"$/, function (pronoundCase, item) {
166
- browser.checkItem(item);
206
+
207
+ browser.click(item);
167
208
  });
168
209
 
169
210
  /**
170
- * Unchecks checkbox specified by id|class|name|label
211
+ * Unchecks checkbox specified
171
212
  * Example: When I uncheck "Remember me"
172
213
  *
173
214
  */
174
215
  When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronoundCase, item) {
175
- browser.uncheckItem(item);
216
+
217
+ browser.click(item);
218
+ });
219
+
220
+ /**
221
+ * Verify, that current page is the homepage
222
+ * Example: Then I should be on homepage
223
+ *
224
+ */
225
+ Then(/^(I|we)* should be on homepage$/, function (pronoundCase) {
226
+ return browser.assert.urlMatches(browser.launch_url);
176
227
  });
177
228
 
178
229
  /**
@@ -180,12 +231,30 @@ When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronoundCase, item) {
180
231
  * Example: Then I should be on the homepage
181
232
  *
182
233
  */
183
- Then(/^(I|we)* should( not)* be on( the)* homepage$/, function (pronoundCase, negativeCase, theCase) {
184
- return browser.assert.backToHomepage(negativeCase);
234
+ Then(/^(I|we)* should be on the homepage$/, function (pronoundCase) {
235
+ return browser.assert.urlMatches(browser.launch_url);
185
236
  });
186
237
 
187
238
  /**
188
- * Verify, that current page path is equal to specified
239
+ * Verify, that current page is the homepage
240
+ * Example: Then I should not be on homepage
241
+ *
242
+ */
243
+ Then(/^(I|we)* should not be on homepage$/, function (pronoundCase) {
244
+ return browser.assert.not.urlMatches(browser.launch_url);
245
+ });
246
+
247
+ /**
248
+ * Verify, that current page is the homepage
249
+ * Example: Then I should not be on the homepage
250
+ *
251
+ */
252
+ Then(/^(I|we)* should not be on the homepage$/, function (pronoundCase) {
253
+ return browser.assert.not.urlMatches(browser.launch_url);
254
+ });
255
+
256
+ /**
257
+ * Verify, that current page path is equal to specified path
189
258
  * Example: Then I should be on "/"
190
259
  * Example: And I should be on "/user/login"
191
260
  * Example: And I should be on "http://google.com"
@@ -196,133 +265,303 @@ Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronoundCase, url) {
196
265
  });
197
266
 
198
267
  /**
199
- * Checks, that HTML response contains specific text specified by id|class|name|label
268
+ * Checks, that HTML response contains specific text
200
269
  * Example: Then the response should contain "Welcome visitor, How can I help you?"
270
+ *
271
+ */
272
+ Then(/^the response should contain "([^"]*)?"$/, function (expectedText) {
273
+ return this.shouldSee = function (browser) {
274
+ browser.assert.textContains("html", expectedText);
275
+ };
276
+ });
277
+
278
+ /**
279
+ * Checks, that HTML response contains specific text
201
280
  * Example: Then the response should not contain "Error: Ambiguous messages that are unclear"
202
281
  *
203
282
  */
204
- Then(/^the response should( not)* contain "([^"]*)?"$/, function (negativeCase, expectedText) {
205
- return browser.assert.elementContainsText(negativeCase, expectedText, 'html');
283
+ Then(/^the response should not contain "([^"]*)?"$/, function (expectedText) {
284
+ return this.shouldSee = function (browser) {
285
+ browser.assert.not.textContains("html", expectedText);
286
+ };
287
+ });
288
+
289
+
290
+ /**
291
+ * Assert, that element contains a specific text value
292
+ * Example: Then I should see "John Smith" in the "#username" element
293
+ *
294
+ */
295
+ Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, expectedText, element) {
296
+ return this.shouldSee = function (browser) {
297
+ browser.assert.textContains(element, expectedText);
298
+ };
206
299
  });
207
300
 
208
301
  /**
209
- * Assert, that element contains a specific text value specified by id|class|name|label
210
- * Example: Then I should see "John Smith" in the "Username" element
211
- * Example: Then I should see "Joe Smith" in the "Username" element
302
+ * Assert, that element contains a specific text value
303
+ * Example: Then I should not see "Joe Smith" in the "#username" element
212
304
  *
213
305
  */
214
- Then(/^(I|we)* should( not)* see "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, negativeCase, expectedText, element) {
215
- return browser.assert.elementContainsText(negativeCase, expectedText, element);
306
+ Then(/^(I|we)* should not see "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, expectedText, element) {
307
+
308
+ return this.shouldSee = function (browser) {
309
+ browser.assert.not.textContains(element, expectedText);
310
+ };
216
311
  });
217
312
 
218
313
  /**
219
- * Assert, that element exists on page specified by id|class|name|label
314
+ * Assert, that element exists on current page
220
315
  * Example: Then I should see a "body" element
221
- * Example: Then I should see an "Email" element
316
+ *
317
+ */
318
+ Then(/^(I|we)* should see a "([^"]*)?" element$/, function (pronoundCase, element) {
319
+ return browser.verify.visible(element);
320
+ });
321
+
322
+ /**
323
+ * Assert, that element exists on current page
324
+ * Example: Then I should see an "#email" element
325
+ *
326
+ */
327
+ Then(/^(I|we)* should see an "([^"]*)?" element$/, function (pronoundCase, element) {
328
+ return browser.verify.visible(element);
329
+ });
330
+
331
+ /**
332
+ * Assert, that element not exists on current page
333
+ * Example: Then I should not see a "#username" element
334
+ *
335
+ */
336
+ Then(/^(I|we)* should not see a "([^"]*)?" element$/, function (pronoundCase, element) {
337
+ return browser.verify.not.visible(element);
338
+ });
339
+
340
+ /**
341
+ * Assert, that element not exists on current page
222
342
  * Example: Then I should not see a "Username" element
223
- * Example: Then I should not see an "img" element
224
343
  *
225
344
  */
226
- Then(/^(I|we)* should( not)* see a(n)* "([^"]*)?" element$/, function (pronoundCase, negativeCase, identification, element) {
227
- return browser.assert.shouldVisible(negativeCase, element);
345
+ Then(/^(I|we)* should not see a "([^"]*)?" element$/, function (pronoundCase, element) {
346
+ return browser.verify.not.visible(element);
347
+ });
348
+
349
+ /**
350
+ * Assert, that element exists on current page
351
+ * Example: Then I should not see an "#img" element
352
+ *
353
+ */
354
+ Then(/^(I|we)* should not see an "([^"]*)?" element$/, function (pronoundCase, element) {
355
+ return browser.verify.not.visible(element);
228
356
  });
229
357
 
230
358
  /**
231
- * Assert, that element contains a specific CSS style specified by id|class|name|label|tag.
359
+ * Assert, that element contains a specific CSS style
232
360
  * Example: Then the "body" element should contain "color:white;"
233
361
  *
234
362
  */
235
- Then(/^the "([^"]*)?" element should( not)* contain "([^"]*)?"$/, function (element, negativeCase, elementCss) {
236
- return browser.assert.elementContainsCss(element, negativeCase, elementCss);
363
+ Then(/^the "([^"]*)?" element should contain "([^"]*)?"$/, function (element, elementCss) {
364
+
365
+ elementCss = elementCss.replace(";", '');
366
+ const cssPropertyArr = elementCss.split(":");
367
+
368
+ const cssProperty = cssPropertyArr[0].trim();
369
+ const propertyVal = cssPropertyArr[1].trim();
370
+
371
+ this.checkCss = function (browser) {
372
+ browser.assert.cssProperty(element, cssProperty, propertyVal);
373
+ };
237
374
  });
238
375
 
239
376
  /**
240
- * Attaches file to field with specified id|class|name|label
377
+ * Assert, that element contains a specific CSS style
378
+ * Example: Then the "body" element should not contain "color:white;"
379
+ *
380
+ */
381
+ Then(/^the "([^"]*)?" element should not contain "([^"]*)?"$/, function (element, elementCss) {
382
+
383
+ elementCss = elementCss.replace(";", '');
384
+ const cssPropertyArr = elementCss.split(":");
385
+
386
+ const cssProperty = cssPropertyArr[0].trim();
387
+ const propertyVal = cssPropertyArr[1].trim();
388
+
389
+ this.checkCss = function (browser) {
390
+ browser.assert.not.cssProperty(element, cssProperty, propertyVal);
391
+ };
392
+ });
393
+
394
+ /**
395
+ * Attaches file to field
241
396
  * Example: When I attach the file "profileIcon.jpg" to "profileIconUpload"
242
397
  *
243
398
  */
244
399
  When(/^(I|we)* attach the file "([^"]*)?" to "([^"]*)?"$/, function (pronoundCase, fileUrl, element) {
245
- browser.fileUpload("../../../tests/assets/" + fileUrl, element);
400
+ // browser.setValue(element, require('path').resolve(__dirname + fileUrl));
401
+ });
402
+
403
+ /**
404
+ * Assert, that field contain a specific text
405
+ * Example: Then the "#username" field should contain "John Smith"
406
+ *
407
+ */
408
+ Then(/^the "([^"]*)?" field should contain "([^"]*)?"$/, function (field, expectedText) {
409
+
410
+ return this.shouldSee = function (browser) {
411
+ browser.assert.textContains(field, expectedText);
412
+ };
246
413
  });
247
414
 
248
415
  /**
249
- * Assert, that form field with specified id|class|name|label has specified value
250
- * Example: Then the "username" field should contain "John Smith"
416
+ * Assert, that field does not contain a specific text
417
+ * Example: Then the "#username" field should not contain "John Smith"
251
418
  *
252
419
  */
253
- Then(/^the "([^"]*)?" field should( not)* contain "([^"]*)?"$/, function (field, negativeCase, expectedText) {
254
- return browser.assert.elementContainsText(negativeCase, expectedText, field);
420
+ Then(/^the "([^"]*)?" field should not contain "([^"]*)?"$/, function (field, expectedText) {
421
+
422
+ return this.shouldSee = function (browser) {
423
+ browser.assert.not.textContains(field, expectedText);
424
+ };
255
425
  });
256
426
 
257
427
  /**
258
- * Assert, that checkbox with specified id|class|name|label is should be checked
259
- * Example: Then the "PrivacyPolicy" checkbox should be checked
428
+ * Assert, that checkbox with specified element is should be checked
429
+ * Example: Then the "#PrivacyPolicy" checkbox should be checked
260
430
  *
261
431
  */
262
- Then(/^the "([^"]*)?" checkbox should( not)* be checked$/, function (checkbox, negativeCase) {
263
- return browser.assert.checkboxChecked(checkbox, negativeCase);
432
+ Then(/^the "([^"]*)?" checkbox should be checked$/, function (checkbox) {
433
+ return browser.expect.element(checkbox).to.be.selected;
264
434
  });
265
435
 
266
436
  /**
267
- * Check, whether the checkbox specified by id|class|name|label is checked or not.
268
- * Example: Then the "Remember Me" checkbox is checked
269
- *
437
+ * Assert, that checkbox with specified element is should not be checked
438
+ * Example: Then the "#PrivacyPolicy" checkbox should not be checked
270
439
  *
271
440
  */
272
- Then(/^the "([^"]*)?" checkbox is( not)* checked$/, function (checkbox, negativeCase) {
273
- return browser.assert.checkboxChecked(checkbox, negativeCase);
441
+ Then(/^the "([^"]*)?" checkbox should not be checked$/, function (checkbox) {
442
+ return browser.expect.element(checkbox).to.not.be.selected;
443
+ });
444
+
445
+ /**
446
+ * Check, whether the checkbox specified is checked.
447
+ * Example: Then the "#rememberMe" checkbox is checked
448
+ *
449
+ */
450
+ Then(/^the "([^"]*)?" checkbox is checked$/, function (checkbox) {
451
+ return browser.expect.element(checkbox).to.be.selected;
452
+ });
453
+
454
+ /**
455
+ * Check, whether the checkbox specified is not checked.
456
+ * Example: Then the "#rememberMe" checkbox is not checked
457
+ *
458
+ */
459
+ Then(/^the "([^"]*)?" checkbox is not checked$/, function (checkbox) {
460
+ return browser.expect.element(checkbox).to.not.be.selected;
461
+ });
462
+
463
+ /**
464
+ * Assert, that checkbox with specified element should be checked
465
+ * Example: Then the checkbox "#PrivacyPolicy" should be checked
466
+ *
467
+ */
468
+ Then(/^the checkbox "([^"]*)?" should be checked$/, function (checkbox) {
469
+ return browser.expect.element(checkbox).to.be.selected;
470
+ });
471
+
472
+ /**
473
+ * Assert, that checkbox with specified element should not be checked
474
+ * Example: Then the checkbox "#PrivacyPolicy" should not be checked
475
+ *
476
+ */
477
+ Then(/^the checkbox "([^"]*)?" should not be checked$/, function (checkbox) {
478
+ return browser.expect.element(checkbox).to.not.be.selected;
274
479
  });
275
480
 
276
481
  /**
277
- * Assert, that checkbox with specified id|name|label|value is checked
278
- * Example: Then the checkbox "PrivacyPolicy" should be checked
279
- * Example: Then the checkbox "PrivacyPolicy" should not be checked
482
+ * Assert, that checkbox with specified element is checked
483
+ * Example: Then the checkbox "#rememberMe" is checked
280
484
  *
281
485
  */
282
- Then(/^the checkbox "([^"]*)?" should( not)* be checked$/, function (checkbox, negativeCase) {
283
- return browser.assert.checkboxChecked(checkbox, negativeCase);
486
+ Then(/^the checkbox "([^"]*)?" is checked$/, function (checkbox) {
487
+ return browser.expect.element(checkbox).to.be.selected;
284
488
  });
285
489
 
286
490
  /**
287
- * Assert, that checkbox with specified id|name|label|value is checked
288
- * Example: Then the checkbox "Remember Me" is checked
289
- * Example: And the checkbox "Remember Me" is not checked
491
+ * Assert, that checkbox with specified element is not checked
492
+ * Example: Then the checkbox "#rememberMe" is not checked
290
493
  *
291
494
  */
292
- Then(/^the checkbox "([^"]*)?" is( not)* checked$/, function (checkbox, negativeCase) {
293
- return browser.assert.checkboxChecked(checkbox, negativeCase);
495
+ Then(/^the checkbox "([^"]*)?" is not checked$/, function (checkbox) {
496
+ return browser.expect.element(checkbox).to.not.be.selected;
294
497
  });
295
498
 
296
499
  /**
297
- * Wait a specific number of seconds, or a max number of seconds until the element present.
500
+ * Wait a specific number of seconds.
298
501
  * Example: When I wait 1 second
299
502
  * Example: When I wait 5 seconds
503
+ *
504
+ */
505
+ When(/^(I|we)* wait (\d*) second(s)*$/, function (pronoundCase, number, withS) {
506
+ var waitTime = number * 1000;
507
+ return browser.pause(waitTime);
508
+ });
509
+
510
+ /**
511
+ * Wait a max number of seconds until the element present.
300
512
  * Example: When I wait max of 6 seconds
301
513
  *
302
514
  */
303
- When(/^(I|we)* wait( max of)* (\d*) second(s)*$/, function (pronoundCase, maxof, number, withS) {
304
- return browser.wait(maxof, number, "s");
515
+ When(/^(I|we)* wait max of (\d*) second(s)*$/, function (pronoundCase, number, withS) {
516
+ var waitTime = number * 1000;
517
+ return browser.waitForElementPresent('body', waitTime);
305
518
  });
306
519
 
307
520
  /**
308
- * Wait a specific number of minutes, or a max number of minutes until the element present.
521
+ * Wait a specific number of minutes.
309
522
  * Example: When I wait 1 minute
310
523
  * Example: When I wait 5 minutes
524
+ *
525
+ */
526
+ When(/^(I|we)* wait (\d*) minute(s)*$/, function (pronoundCase, number, withS) {
527
+ var waitTime = number * 1000 * 60;
528
+ return browser.pause(waitTime);
529
+ });
530
+
531
+ /**
532
+ * Wait a max number of minutes until the element present.
311
533
  * Example: When I wait max of 6 minutes
312
534
  *
313
535
  */
314
- When(/^(I|we)* wait( max of)* (\d*) minute(s)*$/, function (pronoundCase, maxof, number, withS) {
315
- return browser.wait(maxof, number, "m");
536
+ When(/^(I|we)* wait max of (\d*) minute(s)*$/, function (pronoundCase, number, withS) {
537
+ var waitTime = number * 1000 * 60;
538
+ return browser.waitForElementPresent('body', waitTime);
316
539
  });
317
540
 
318
541
  /**
319
- * Checks, that the current page response status is equal or not equal to the specified code
542
+ * Checks, that the current page response status is equal the specified code
320
543
  * Example: Then the response status code should be 200
544
+ *
545
+ */
546
+ Then(/^the response status code should be (\d+)$/, function (expectedStatusCode) {
547
+ return browser.url(function (currentURL) {
548
+ request(currentURL.value, (error, response, body) => {
549
+ browser.assert.equal(response.statusCode, expectedStatusCode);
550
+ });
551
+ });
552
+ });
553
+
554
+ /**
555
+ * Checks, that the current page response status is not equal the specified code
321
556
  * Example: And the response status code should not be 404
322
557
  *
323
558
  */
324
- Then(/^the response status code should( not)* be (\d+)$/, function (negativeCase, expectedStatusCode) {
325
- return browser.assert.responseStatus(negativeCase, expectedStatusCode);
559
+ Then(/^the response status code should not be (\d+)$/, function ( expectedStatusCode) {
560
+ return browser.url(function (currentURL) {
561
+ request(currentURL.value, (error, response, body) => {
562
+ browser.assert.not.equal(response.statusCode, expectedStatusCode);
563
+ });
564
+ });
326
565
  });
327
566
 
328
567
  /**
@@ -330,45 +569,75 @@ Then(/^the response status code should( not)* be (\d+)$/, function (negativeCase
330
569
  * Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
331
570
  *
332
571
  */
333
- Then(/^(I|we)* should( not)* see text matching "([^"]*)?"$/, function (pronoundCase, negativeCase, textPattern) {
334
- // return browser.assert.textMatching(negativeCase, textPattern);
572
+ Then(/^(I|we)* should see text matching "([^"]*)?"$/, function (pronoundCase, textPattern) {
335
573
  browser.elements('css selector', 'body', function (elements) {
336
574
  elements.value.forEach(function (elementsObj) {
337
- if (negativeCase) {
338
- return browser.assert.not.textMatches(elementsObj, textPattern);
339
- }
340
575
  return browser.assert.textMatches(elementsObj, textPattern);
341
576
  });
342
577
  });
343
578
  });
344
579
 
345
580
  /**
346
- * Checks, that page contains text matching specified pattern
347
- * 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 //pattern of DD/MM/YYYY or DD-MM-YYYY
581
+ * Checks, that page not contains text matching specified pattern
582
+ * Example: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
348
583
  *
349
584
  */
350
- Then(/^(I|we)* should( not)* see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, negativeCase, textPattern, element) {
351
- browser.elements('css selector', element, function (elements) {
585
+ Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase, textPattern) {
586
+ browser.elements('css selector', 'body', function (elements) {
352
587
  elements.value.forEach(function (elementsObj) {
353
- if (negativeCase) {
354
- return browser.assert.not.textMatches(elementsObj, textPattern);
355
- }
356
- return browser.assert.textMatches(elementsObj, textPattern);
588
+ return browser.assert.not.textMatches(elementsObj, textPattern);
357
589
  });
358
590
  });
359
591
  });
360
592
 
593
+ /**
594
+ * Checks, that page contains text matching specified pattern
595
+ * 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
596
+ * //pattern of DD/MM/YYYY or DD-MM-YYYY
597
+ *
598
+ */
599
+ Then(/^(I|we)* should see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, textPattern, element) {
600
+ // return browser.elements('css selector', element, function (elements) {
601
+ // elements.value.forEach(function (elementsObj) {
602
+ return this.shouldSeePattern = function (browser) {
603
+ browser.assert.textMatches(element, textPattern);
604
+ };
605
+ // });
606
+ // });
607
+ });
608
+
609
+ /**
610
+ * Checks, that page contains text matching specified pattern
611
+ * 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
612
+ * //pattern of DD/MM/YYYY or DD-MM-YYYY
613
+ *
614
+ */
615
+ Then(/^(I|we)* should not see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, textPattern, element) {
616
+
617
+ // return browser.elements('css selector', element, function (elements) {
618
+ // elements.value.forEach(function (elementsObj) {
619
+ return this.shouldSeePattern = function (browser) {
620
+ browser.assert.not.textMatches(element, textPattern);
621
+ };
622
+ // browser.assert.not.textMatches(elementsObj, textPattern);
623
+ // });
624
+ // });
625
+ });
361
626
 
362
627
  /**
363
628
  * Checks, that current URL Path matches regular expression
364
629
  * Example: Then the url should match "/contact-us.html"
365
630
  *
366
631
  */
367
- Then(/^the url should( not)* match "([^"]*)?"$/, function (negativeCase, pattern) {
368
-
369
- if (negativeCase) {
370
- return browser.assert.not.urlMatches(pattern);
371
- }
632
+ Then(/^the url should match "([^"]*)?"$/, function (pattern) {
372
633
  return browser.assert.urlMatches(pattern);
634
+ });
373
635
 
636
+ /**
637
+ * Checks, that current URL Path matches regular expression
638
+ * Example: Then the url should not match "/contact-us.html"
639
+ *
640
+ */
641
+ Then(/^the url should not match "([^"]*)?"$/, function (pattern) {
642
+ return browser.assert.not.urlMatches(pattern);
374
643
  });