webship-js 2.0.1 → 2.0.2

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 (41) hide show
  1. package/bin/generate-reports.js +191 -0
  2. package/bin/init-webship.js +343 -0
  3. package/bin/postinstall.js +8 -74
  4. package/cucumber.js +59 -1
  5. package/examples/diffy/baseline.html +54 -0
  6. package/examples/diffy/changed.html +63 -0
  7. package/examples/diffy/index.html +52 -0
  8. package/examples/index.html +6 -0
  9. package/examples/test--when--i-additionally-select.html +27 -0
  10. package/package.json +10 -4
  11. package/tests/features/diffy/test--diffy-01-example-demo.feature +22 -0
  12. package/tests/features/diffy/test--diffy-02-all-steps.feature +52 -0
  13. package/tests/features/diffy/test--diffy-03-real-api.feature +21 -0
  14. package/tests/features/test--then--i-save-screenshot.feature +33 -0
  15. package/tests/features/test--then--i-see-locator.feature +320 -0
  16. package/tests/features/test--then--i-should-see-n-elements.feature +24 -0
  17. package/tests/features/test--then--print-current-url-and-response.feature +21 -0
  18. package/tests/features/test--when--i-additionally-select.feature +30 -0
  19. package/tests/features/test--when--i-follow.feature +22 -0
  20. package/tests/selectors/back-end-selectors.json +13 -0
  21. package/tests/selectors/front-end-selectors.json +16 -0
  22. package/tests/selectors/homepage-selectors.json +13 -0
  23. package/tests/step-definitions/webship-api.js +234 -41
  24. package/tests/step-definitions/webship-screenshot.js +427 -0
  25. package/tests/step-definitions/webship-selectors.js +961 -0
  26. package/tests/step-definitions/webship.js +829 -230
  27. package/tests/step-definitions-diffy/README.md +329 -0
  28. package/tests/step-definitions-diffy/mock-diffy-api/server.js +84 -0
  29. package/tests/step-definitions-diffy/webship-diffy-mock.js +31 -0
  30. package/tests/step-definitions-diffy/webship-diffy.js +472 -0
  31. package/generate-reports.js +0 -22
  32. package/required/cucumber.js +0 -37
  33. package/required/generate-reports.js +0 -22
  34. package/required/package.json +0 -18
  35. package/required/playwright.config.ts +0 -37
  36. package/required/tests/features/README.md +0 -1
  37. package/required/tests/features/check-homepage.feature +0 -8
  38. package/required/tests/reports/README.md +0 -1
  39. package/required/tests/step-definitions/README.md +0 -1
  40. package/required/tests/step-definitions/custom.js +0 -4
  41. package/required/tsconfig.json +0 -12
@@ -46,10 +46,13 @@ function getNestedProperty(obj, path) {
46
46
  }
47
47
 
48
48
  /**
49
- * Adds Basic Authentication header to next request.
49
+ * Adds Basic Authentication header to the next request.
50
50
  *
51
51
  * Example #1: Given I am authenticating as "admin" with "password123" password
52
52
  * Example #2: Given We are authenticating as "user@example.com" with "secret" password
53
+ * Example #3: Given I am authenticating as "api-user" with "pass!word" password
54
+ * Example #4: Given we are authenticating as "reader" with "readonly" password
55
+ *
53
56
  */
54
57
  Given(/^(?:I am|we are) authenticating as "([^"]*)" with "([^"]*)" password$/, function (username, password) {
55
58
  delete apiHeaders['Authorization'];
@@ -58,22 +61,33 @@ Given(/^(?:I am|we are) authenticating as "([^"]*)" with "([^"]*)" password$/, f
58
61
  });
59
62
 
60
63
  /**
61
- * Sets a HTTP Header with value.
64
+ * Sets a single HTTP request header.
62
65
  *
63
66
  * Example #1: Given I set header "Content-Type" with value "application/json"
64
67
  * Example #2: Given I set header "Authorization" with value "Bearer token123"
65
68
  * Example #3: Given I set header "Accept" with value "application/xml"
69
+ * Example #4: Given I set header "Accept" with value "application/json"
70
+ * Example #5: Given we set header "X-Api-Key" with value "abcd-1234"
71
+ * Example #6: Given I set header "User-Agent" with value "webship-js"
72
+ * Example #7: Given we set header "Accept-Language" with value "en-US"
73
+ * Example #8: Given I set header "If-None-Match" with value "etag-xyz"
74
+ *
66
75
  */
67
76
  Given(/^(?:I |we )?set header "([^"]*)" with value "([^"]*)"$/, function (name, value) {
68
77
  apiHeaders[name] = replacePlaceHolder(value);
69
78
  });
70
79
 
71
80
  /**
72
- * Set the base URL for API calls (alternative syntax).
81
+ * Set the base URL for API calls. Accepts full URLs or paths relative to LAUNCH_URL.
73
82
  *
74
83
  * Example #1: Given the API base URL is "https://jsonplaceholder.typicode.com"
75
84
  * Example #2: Given I set the API base URL to "https://api.example.com/v1"
76
85
  * Example #3: Given the base URL is "http://localhost:3000/api"
86
+ * Example #4: Given the API base URL is "https://un.org/api"
87
+ * Example #5: Given I set the API base URL to "/api/v2"
88
+ * Example #6: Given the base URL is "/webship.co/api"
89
+ * Example #7: Given the API base URL is "http://127.0.0.1:8080"
90
+ *
77
91
  */
78
92
  Given(/^(?:the API base URL is|I set the API base URL to|the base URL is) "([^"]*)"$/, function (url) {
79
93
  // Check if the input is a full URL (contains protocol)
@@ -88,11 +102,17 @@ Given(/^(?:the API base URL is|I set the API base URL to|the base URL is) "([^"]
88
102
  });
89
103
 
90
104
  /**
91
- * Set request headers for API calls (alternative syntax).
105
+ * Set a request header. Alternative syntax.
92
106
  *
93
107
  * Example #1: Given I set the header "Content-Type" to "application/json"
94
108
  * Example #2: Given I set the header "Authorization" to "Bearer token123"
95
109
  * Example #3: Given the header "Accept" is "application/json"
110
+ * Example #4: Given we set the header "X-Api-Key" to "abcd-1234"
111
+ * Example #5: Given I set the header "If-Match" to "etag-123"
112
+ * Example #6: Given the header "User-Agent" is "webship-js"
113
+ * Example #7: Given we set the header "Accept-Language" to "en-US"
114
+ * Example #8: Given I set the header "Cache-Control" to "no-cache"
115
+ *
96
116
  */
97
117
  Given(/^(?:I set the header|we set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, function (headerName, headerValue) {
98
118
  apiHeaders[headerName] = replacePlaceHolder(headerValue);
@@ -101,10 +121,25 @@ Given(/^(?:I set the header|we set the header|the header) "([^"]*)" (?:to|is) "(
101
121
  /**
102
122
  * Set multiple headers using a table.
103
123
  *
104
- * Example: Given I set the following headers:
105
- * | Content-Type | application/json |
106
- * | Authorization | Bearer token123 |
107
- * | Accept | application/json |
124
+ * Example #1: Given I set the following headers:
125
+ * | Content-Type | application/json |
126
+ * | Authorization | Bearer token123 |
127
+ * | Accept | application/json |
128
+ *
129
+ * Example #2: Given we set the following headers:
130
+ * | Content-Type | application/json |
131
+ * | X-Api-Key | abcd-1234 |
132
+ * | Accept-Language | en-US |
133
+ *
134
+ * Example #3: Given I set the following headers:
135
+ * | User-Agent | webship-js |
136
+ * | Cache-Control | no-cache |
137
+ * | If-None-Match | etag-xyz |
138
+ *
139
+ * Example #4: Given we set the following headers:
140
+ * | Authorization | Bearer {{token}} |
141
+ * | Accept | application/json |
142
+ * | X-Request-ID | req-001 |
108
143
  */
109
144
  Given(/^(?:I|we) set the following headers:$/, function (table) {
110
145
  table.rows().forEach(row => {
@@ -117,6 +152,11 @@ Given(/^(?:I|we) set the following headers:$/, function (table) {
117
152
  *
118
153
  * Example #1: Given I set the request body to '{"name": "John", "email": "john@example.com"}'
119
154
  * Example #2: Given the request body is '{"title": "Test Post", "body": "This is a test"}'
155
+ * Example #3: Given we set the request body to '{"org": "Webship.co", "active": true}'
156
+ * Example #4: Given I set the request body to '{"id": 1, "tags": ["qa","api"]}'
157
+ * Example #5: Given the request body is '{"username": "admin", "password": "secret"}'
158
+ * Example #6: Given we set the request body to '{"email": "hello@un.org"}'
159
+ * Example #7: Given I set the request body to '{"status": "published"}'
120
160
  */
121
161
  Given(/^(?:I set the request body to|we set the request body to|the request body is) '([^']*)'$/, function (jsonData) {
122
162
  try {
@@ -130,10 +170,25 @@ Given(/^(?:I set the request body to|we set the request body to|the request body
130
170
  /**
131
171
  * Set request body using a table.
132
172
  *
133
- * Example: Given I set the request body with:
134
- * | name | John Doe |
135
- * | email | john@example.com |
136
- * | age | 30 |
173
+ * Example #1: Given I set the request body with:
174
+ * | name | John Doe |
175
+ * | email | john@example.com |
176
+ * | age | 30 |
177
+ *
178
+ * Example #2: Given we set the request body with:
179
+ * | org | Webship.co |
180
+ * | country | UN |
181
+ * | active | true |
182
+ *
183
+ * Example #3: Given I set the request body with:
184
+ * | title | Hello World |
185
+ * | body | First post |
186
+ * | userId | 1 |
187
+ *
188
+ * Example #4: Given we set the request body with:
189
+ * | status | published |
190
+ * | priority | 5 |
191
+ * | featured | false |
137
192
  */
138
193
  Given(/^(?:I|we) set the request body with:$/, function (table) {
139
194
  apiRequestData = {};
@@ -156,6 +211,12 @@ Given(/^(?:I|we) set the request body with:$/, function (table) {
156
211
  * Example #2: When we send a POST request to "/posts"
157
212
  * Example #3: When I send a PUT request to "/users/1"
158
213
  * Example #4: When we send a DELETE request to "/posts/1"
214
+ * Example #5: When I send a GET request to "/posts?userId=1"
215
+ * Example #6: When we send a PATCH request to "/users/42"
216
+ * Example #7: When I send a GET request to "/health"
217
+ * Example #8: When we send a HEAD request to "/users"
218
+ * Example #9: When I send a OPTIONS request to "/api"
219
+ * Example #10: When we send a GET request to "/posts/{{postId}}"
159
220
  */
160
221
  When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, endpoint) {
161
222
  const url = baseURL + '/' + prepareUrl(endpoint);
@@ -178,11 +239,24 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method
178
239
  /**
179
240
  * Sends HTTP request to specific URL with field values from Table.
180
241
  *
181
- * Example: When I send a POST request to "/users" with values:
182
- * When we send a POST request to "/users" with values:
183
- * | name | John Doe |
184
- * | email | john@example.com |
185
- * | age | 30 |
242
+ * Example #1: When I send a POST request to "/users" with values:
243
+ * | name | John Doe |
244
+ * | email | john@example.com |
245
+ * | age | 30 |
246
+ *
247
+ * Example #2: When we send a POST request to "/users" with values:
248
+ * | name | Alice |
249
+ * | email | alice@un.org |
250
+ * | role | editor |
251
+ *
252
+ * Example #3: When I send a PUT request to "/users/1" with values:
253
+ * | name | Updated Name |
254
+ * | active | true |
255
+ *
256
+ * Example #4: When we send a POST request to "/posts" with values:
257
+ * | title | Welcome |
258
+ * | body | Hello Webship.co|
259
+ * | userId | 1 |
186
260
  */
187
261
  When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async function (method, endpoint, table) {
188
262
  const url = baseURL + '/' + prepareUrl(endpoint);
@@ -211,14 +285,38 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async fun
211
285
  /**
212
286
  * Sends HTTP request to specific URL with raw body from PyString.
213
287
  *
214
- * Example: When I send a POST request to "/users" with body:
215
- * When we send a POST request to "/users" with body:
216
- * """
217
- * {
218
- * "name": "John Doe",
219
- * "email": "john@example.com"
220
- * }
221
- * """
288
+ * Example #1: When I send a POST request to "/users" with body:
289
+ * """
290
+ * {
291
+ * "name": "John Doe",
292
+ * "email": "john@example.com"
293
+ * }
294
+ * """
295
+ *
296
+ * Example #2: When we send a POST request to "/posts" with body:
297
+ * """
298
+ * {
299
+ * "title": "Hello",
300
+ * "body": "World",
301
+ * "userId": 1
302
+ * }
303
+ * """
304
+ *
305
+ * Example #3: When I send a PUT request to "/users/1" with body:
306
+ * """
307
+ * {
308
+ * "name": "Updated",
309
+ * "org": "Webship.co"
310
+ * }
311
+ * """
312
+ *
313
+ * Example #4: When we send a POST request to "/contacts" with body:
314
+ * """
315
+ * {
316
+ * "email": "info@un.org",
317
+ * "subscribe": true
318
+ * }
319
+ * """
222
320
  */
223
321
  When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function (method, endpoint, docString) {
224
322
  const url = baseURL + '/' + prepareUrl(endpoint);
@@ -260,13 +358,31 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async funct
260
358
  /**
261
359
  * Sends HTTP request to specific URL with form data.
262
360
  *
263
- * Example: When I send a POST request to "/login" with form data:
264
- * When we send a POST request to "/login" with form data:
265
- * """
266
- * username=admin
267
- * password=secret
268
- * remember=true
269
- * """
361
+ * Example #1: When I send a POST request to "/login" with form data:
362
+ * """
363
+ * username=admin
364
+ * password=secret
365
+ * remember=true
366
+ * """
367
+ *
368
+ * Example #2: When we send a POST request to "/subscribe" with form data:
369
+ * """
370
+ * email=hello@un.org
371
+ * list=newsletter
372
+ * """
373
+ *
374
+ * Example #3: When I send a POST request to "/contact" with form data:
375
+ * """
376
+ * name=Alice
377
+ * org=Webship.co
378
+ * message=Hello
379
+ * """
380
+ *
381
+ * Example #4: When we send a PUT request to "/profile" with form data:
382
+ * """
383
+ * name=Updated
384
+ * country=UN
385
+ * """
270
386
  */
271
387
  When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async function (method, endpoint, docString) {
272
388
  const url = baseURL + '/' + prepareUrl(endpoint);
@@ -309,6 +425,14 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async
309
425
  *
310
426
  * Example #1: Then the API response code should be 200
311
427
  * Example #2: Then API response code should be 404
428
+ * Example #3: Then the API response code should be 201
429
+ * Example #4: Then API response code should be 204
430
+ * Example #5: Then the API response code should be 400
431
+ * Example #6: Then API response code should be 401
432
+ * Example #7: Then the API response code should be 403
433
+ * Example #8: Then API response code should be 500
434
+ * Example #9: Then the API response code should be 301
435
+ * Example #10: Then API response code should be 302
312
436
  */
313
437
  Then(/^(?:the )?API response code should be (\d+)$/, function (expectedCode) {
314
438
  if (!apiResponse) {
@@ -326,6 +450,12 @@ Then(/^(?:the )?API response code should be (\d+)$/, function (expectedCode) {
326
450
  *
327
451
  * Example #1: Then the API response should contain "success"
328
452
  * Example #2: Then API response should contain "John Doe"
453
+ * Example #3: Then the API response should contain "Webship.co"
454
+ * Example #4: Then API response should contain "UN"
455
+ * Example #5: Then the API response should contain "published"
456
+ * Example #6: Then API response should contain "id"
457
+ * Example #7: Then the API response should contain "email"
458
+ * Example #8: Then API response should contain "hello@un.org"
329
459
  */
330
460
  Then(/^(?:the )?API response should contain "([^"]*)"$/, function (expectedText) {
331
461
  if (!apiResponse) {
@@ -345,6 +475,12 @@ Then(/^(?:the )?API response should contain "([^"]*)"$/, function (expectedText)
345
475
  *
346
476
  * Example #1: Then the API response should not contain "error"
347
477
  * Example #2: Then API response should not contain "failed"
478
+ * Example #3: Then the API response should not contain "forbidden"
479
+ * Example #4: Then API response should not contain "unauthorized"
480
+ * Example #5: Then the API response should not contain "password"
481
+ * Example #6: Then API response should not contain "secret"
482
+ * Example #7: Then the API response should not contain "exception"
483
+ * Example #8: Then API response should not contain "stack trace"
348
484
  */
349
485
  Then(/^(?:the )?API response should not contain "([^"]*)"$/, function (unexpectedText) {
350
486
  if (!apiResponse) {
@@ -362,13 +498,36 @@ Then(/^(?:the )?API response should not contain "([^"]*)"$/, function (unexpecte
362
498
  /**
363
499
  * Checks that API response body contains JSON from PyString.
364
500
  *
365
- * Example: Then the API response should contain json:
366
- * """
367
- * {
368
- * "name": "John Doe",
369
- * "email": "john@example.com"
370
- * }
371
- * """
501
+ * Example #1: Then the API response should contain json:
502
+ * """
503
+ * {
504
+ * "name": "John Doe",
505
+ * "email": "john@example.com"
506
+ * }
507
+ * """
508
+ *
509
+ * Example #2: Then API response should contain json:
510
+ * """
511
+ * {
512
+ * "org": "Webship.co",
513
+ * "active": true
514
+ * }
515
+ * """
516
+ *
517
+ * Example #3: Then the API response should contain json:
518
+ * """
519
+ * {
520
+ * "id": 1,
521
+ * "title": "Hello"
522
+ * }
523
+ * """
524
+ *
525
+ * Example #4: Then API response should contain json:
526
+ * """
527
+ * {
528
+ * "email": "hello@un.org"
529
+ * }
530
+ * """
372
531
  */
373
532
  Then(/^(?:the )?API response should contain json:$/, function (docString) {
374
533
  if (!apiResponse) {
@@ -401,7 +560,16 @@ Then(/^(?:the )?API response should contain json:$/, function (docString) {
401
560
  });
402
561
 
403
562
  /**
404
- * Alternative syntax for JSON property verification
563
+ * Alternative syntax for JSON property verification.
564
+ *
565
+ * Example #1: Then the JSON response should have "name" equal to "John Doe"
566
+ * Example #2: Then the API response should have "id" equal to 1
567
+ * Example #3: Then the JSON property "active" should be true
568
+ * Example #4: Then the JSON response should have "org" equal to "Webship.co"
569
+ * Example #5: Then the API response should have "email" equal to "hello@un.org"
570
+ * Example #6: Then the JSON property "count" should be 42
571
+ * Example #7: Then the JSON response should have "user.role" equal to "admin"
572
+ * Example #8: Then the JSON property "published" should be false
405
573
  */
406
574
  Then(/^(?:the JSON response should have|the API response should have|the JSON property) "([^"]*)" (?:equal to|should be) (.+)$/, function (propertyPath, expectedValue) {
407
575
  if (!apiResponse) {
@@ -435,6 +603,12 @@ Then(/^(?:the JSON response should have|the API response should have|the JSON pr
435
603
  *
436
604
  * Example #1: Then the JSON response should have property "id"
437
605
  * Example #2: Then the API response should contain property "user.email"
606
+ * Example #3: Then the JSON response should have property "title"
607
+ * Example #4: Then the API response should contain property "data"
608
+ * Example #5: Then the JSON response should have property "user.org"
609
+ * Example #6: Then the API response should contain property "meta.total"
610
+ * Example #7: Then the JSON response should have property "createdAt"
611
+ * Example #8: Then the API response should contain property "links.self"
438
612
  */
439
613
  Then(/^(?:the JSON response should have property|the API response should contain property) "([^"]*)"$/, function (propertyPath) {
440
614
  if (!apiResponse) {
@@ -452,6 +626,12 @@ Then(/^(?:the JSON response should have property|the API response should contain
452
626
  *
453
627
  * Example #1: Then the JSON response should not have property "password"
454
628
  * Example #2: Then the API response should not contain property "secret"
629
+ * Example #3: Then the JSON response should not have property "token"
630
+ * Example #4: Then the API response should not contain property "apiKey"
631
+ * Example #5: Then the JSON response should not have property "user.password"
632
+ * Example #6: Then the API response should not contain property "internal"
633
+ * Example #7: Then the JSON response should not have property "debug"
634
+ * Example #8: Then the API response should not contain property "stack"
455
635
  */
456
636
  Then(/^(?:the JSON response should not have property|the API response should not contain property) "([^"]*)"$/, function (propertyPath) {
457
637
  if (!apiResponse) {
@@ -484,6 +664,12 @@ Then(/^(?:the response should be valid JSON|the API response should be valid JSO
484
664
  *
485
665
  * Example #1: Then the response header "Content-Type" should be "application/json"
486
666
  * Example #2: Then the header "Cache-Control" should contain "no-cache"
667
+ * Example #3: Then the response header "Content-Type" should contain "charset=utf-8"
668
+ * Example #4: Then the header "X-Powered-By" should be "Webship.co"
669
+ * Example #5: Then the response header "ETag" should contain "etag"
670
+ * Example #6: Then the header "Location" should contain "/users/1"
671
+ * Example #7: Then the response header "Access-Control-Allow-Origin" should be "*"
672
+ * Example #8: Then the header "Content-Length" should contain "0"
487
673
  */
488
674
  Then(/^(?:the response header|the header) "([^"]*)" should (?:be|contain) "([^"]*)"$/, function (headerName, expectedValue) {
489
675
  if (!apiResponse) {
@@ -514,7 +700,14 @@ Then(/^print API response$/, function () {
514
700
  /**
515
701
  * Sets placeholder for replacement in URLs, requests, and responses.
516
702
  *
517
- * Example: Given I set placeholder "{{userId}}" to "123"
703
+ * Example #1: Given I set placeholder "{{userId}}" to "123"
704
+ * Example #2: Given we set placeholder "{{token}}" to "abcd-1234"
705
+ * Example #3: Given I set placeholder "{{postId}}" to "42"
706
+ * Example #4: Given we set placeholder "{{org}}" to "Webship.co"
707
+ * Example #5: Given I set placeholder "{{email}}" to "hello@un.org"
708
+ * Example #6: Given we set placeholder "{{apiKey}}" to "secret-xyz"
709
+ * Example #7: Given I set placeholder "{{version}}" to "v2"
710
+ * Example #8: Given we set placeholder "{{locale}}" to "en-US"
518
711
  */
519
712
  Given(/^(?:I|we) set placeholder "([^"]*)" to "([^"]*)"$/, function (placeholder, value) {
520
713
  placeHolders[placeholder] = value;