webship-js 2.0.10 → 2.0.12

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 (248) hide show
  1. package/.circleci/config.yml +10 -1
  2. package/.drone.yml +7 -7
  3. package/.github/ISSUE_TEMPLATE/issue.md +37 -0
  4. package/.github/PULL_REQUEST_TEMPLATE.md +24 -0
  5. package/.github/workflows/github-actions.yml +101 -4
  6. package/.gitlab-ci.yml +9 -4
  7. package/.harness/webship-js-pipeline.yml +5 -6
  8. package/.semaphore/semaphore.yml +6 -9
  9. package/.teamcity/settings.kts +7 -6
  10. package/.travis.yml +6 -1
  11. package/AGENTS.md +1 -1
  12. package/CLAUDE.md +69 -24
  13. package/Jenkinsfile +5 -3
  14. package/README.md +13 -1
  15. package/azure-pipelines.yml +17 -8
  16. package/bamboo-specs/bamboo.yml +9 -15
  17. package/bin/generate-reports.js +51 -7
  18. package/bin/init-webship.js +127 -23
  19. package/bitbucket-pipelines.yml +5 -1
  20. package/buildspec.yml +6 -7
  21. package/cloudbuild.yaml +28 -12
  22. package/codefresh.yml +6 -6
  23. package/cucumber.js +46 -11
  24. package/docs/00-quick-start.md +38 -7
  25. package/docs/02-bbr-smart-waits.md +21 -10
  26. package/docs/03-selector-registry.md +24 -0
  27. package/docs/04-step-reference.md +53 -27
  28. package/docs/05-web-first-assertions.md +6 -0
  29. package/docs/07-auth-state.md +1 -1
  30. package/docs/08-clock-mocking.md +21 -2
  31. package/docs/09-api-testing.md +40 -2
  32. package/docs/10-accessibility.md +2 -0
  33. package/docs/11-debugging.md +24 -1
  34. package/docs/12-ai-agent-guide.md +8 -1
  35. package/docs/13-faq.md +75 -1
  36. package/docs/14-recipes-cookbook.md +2 -0
  37. package/docs/15-tag-conventions.md +5 -1
  38. package/docs/16-ci-cd.md +161 -124
  39. package/docs/README.md +5 -5
  40. package/docs/advanced-screenshots.md +3 -1
  41. package/docs/api-step-definitions.md +16 -2
  42. package/docs/global-settings.md +70 -18
  43. package/docs/install-webship-js/ddev-webship-js.md +3 -0
  44. package/docs/install-webship-js.md +16 -2
  45. package/docs/step-definitions/then-i-should-see.md +14 -1
  46. package/docs/step-definitions/then-item-checkbox.md +2 -0
  47. package/docs/step-definitions/when-i-fill.md +4 -0
  48. package/docs/step-definitions/when-i-select-option-select-list.md +2 -0
  49. package/examples/a11y-legacy-widget.html +34 -0
  50. package/examples/auth-state.html +42 -0
  51. package/examples/choice-controls.html +29 -0
  52. package/examples/clock.html +33 -0
  53. package/examples/datetime-fields.html +52 -0
  54. package/examples/downloads/webship-archive.zip +0 -0
  55. package/examples/downloads/webship-notes.txt +4 -0
  56. package/examples/downloads/webship-report.csv +4 -0
  57. package/examples/downloads.html +16 -0
  58. package/examples/element-selector-hint.html +16 -0
  59. package/examples/element-viewport.html +42 -0
  60. package/examples/field-states.html +27 -0
  61. package/examples/field-types.html +98 -0
  62. package/examples/fill-in-empty.html +26 -0
  63. package/examples/fill-unreachable.html +27 -0
  64. package/examples/iframe-inner.html +20 -0
  65. package/examples/iframe-nested.html +16 -0
  66. package/examples/iframe-newsletter.html +29 -0
  67. package/examples/iframe-order.html +26 -0
  68. package/examples/iframe-outer.html +15 -0
  69. package/examples/iframe.html +21 -0
  70. package/examples/javascript-errors.html +35 -0
  71. package/examples/links.html +1 -0
  72. package/examples/metatags.html +18 -0
  73. package/examples/mouse-and-pointer.html +83 -0
  74. package/examples/multi-value-fields.html +54 -0
  75. package/examples/native-dialogs.html +8 -0
  76. package/examples/network.html +83 -0
  77. package/examples/registered-names.html +15 -0
  78. package/examples/scroll-horizontal.html +50 -0
  79. package/examples/select-by-label.html +33 -0
  80. package/examples/selectors-position.html +29 -0
  81. package/examples/settle-budget.html +21 -0
  82. package/examples/sorted-tables.html +38 -0
  83. package/examples/storage.html +57 -0
  84. package/examples/text-matching.html +48 -0
  85. package/examples/text-order.html +25 -0
  86. package/examples/touch.html +22 -0
  87. package/examples/viewport-size.html +24 -0
  88. package/examples/viewport-top.html +36 -0
  89. package/examples/wait-conditions.html +69 -0
  90. package/examples/web-first.html +99 -0
  91. package/package.json +24 -2
  92. package/playwright.config.ts +3 -1
  93. package/tests/assets/catalog.xml +19 -0
  94. package/tests/assets/feed-namespaced.xml +13 -0
  95. package/tests/assets/sitemap.xml +14 -0
  96. package/tests/assets/webship-site-expected.yaml +21 -0
  97. package/tests/assets/webship-site.schema.json +46 -0
  98. package/tests/assets/webship-site.yaml +21 -0
  99. package/tests/check-api-launch-url.js +106 -0
  100. package/tests/check-assets.js +103 -0
  101. package/tests/check-attachments.js +105 -0
  102. package/tests/check-breakpoints.js +117 -0
  103. package/tests/check-clock.js +143 -0
  104. package/tests/check-config.js +90 -0
  105. package/tests/check-context.js +215 -0
  106. package/tests/check-dry-run.js +104 -0
  107. package/tests/check-examples.js +241 -0
  108. package/tests/check-exit-report.js +141 -0
  109. package/tests/check-javascript-errors.js +105 -0
  110. package/tests/check-must-fail.js +85 -0
  111. package/tests/check-paths.js +82 -0
  112. package/tests/check-report.js +119 -0
  113. package/tests/check-scaffold.js +246 -0
  114. package/tests/check-screenshots.js +117 -0
  115. package/tests/check-settle-verbs.js +137 -0
  116. package/tests/check-time-limit.js +104 -0
  117. package/tests/check-video.js +156 -0
  118. package/tests/check-world.js +167 -0
  119. package/tests/features/a11y.feature +18 -0
  120. package/tests/features/api-base-url.feature +25 -0
  121. package/tests/features/api-form-data.feature +18 -0
  122. package/tests/features/api-json-paths.feature +24 -0
  123. package/tests/features/api-response-contains.feature +21 -0
  124. package/tests/features/api-response-header-presence.feature +17 -0
  125. package/tests/features/api-response-header.feature +17 -0
  126. package/tests/features/api-saved-placeholders.feature +37 -0
  127. package/tests/features/api-step-definitions-individual.feature +1 -1
  128. package/tests/features/api-tables.feature +40 -0
  129. package/tests/features/auth-state.feature +32 -0
  130. package/tests/features/breakpoints.feature +25 -0
  131. package/tests/features/choice-controls.feature +35 -0
  132. package/tests/features/clock.feature +27 -0
  133. package/tests/features/complete-api-testing-examples.feature +1 -1
  134. package/tests/features/cookie.feature +9 -0
  135. package/tests/features/datetime-field-lookup.feature +29 -0
  136. package/tests/features/dialog.feature +27 -0
  137. package/tests/features/element-selector-hint.feature +14 -0
  138. package/tests/features/element.feature +47 -0
  139. package/tests/features/field-state.feature +21 -0
  140. package/tests/features/field.feature +104 -0
  141. package/tests/features/file-download.feature +64 -0
  142. package/tests/features/fill-in-empty-value.feature +41 -0
  143. package/tests/features/fill-reachable.feature +13 -0
  144. package/tests/features/iframe-nested.feature +43 -0
  145. package/tests/features/iframe.feature +83 -0
  146. package/tests/features/javascript-tolerated-errors.feature +20 -0
  147. package/tests/features/javascript.feature +47 -0
  148. package/tests/features/link.feature +11 -0
  149. package/tests/features/metatag.feature +38 -0
  150. package/tests/features/modal-open.feature +13 -0
  151. package/tests/features/mouse-and-pointer.feature +86 -0
  152. package/tests/features/multi-value-field-lookup.feature +30 -0
  153. package/tests/features/network-mocking.feature +80 -0
  154. package/tests/features/registered-names.feature +14 -0
  155. package/tests/features/responsive.feature +27 -0
  156. package/tests/features/scroll-horizontal.feature +55 -0
  157. package/tests/features/select-by-label.feature +31 -0
  158. package/tests/features/selector-files.feature +14 -0
  159. package/tests/features/selectors-position.feature +41 -0
  160. package/tests/features/selectors-table-header.feature +35 -0
  161. package/tests/features/settle-budget.feature +11 -0
  162. package/tests/features/sorted-tables.feature +19 -0
  163. package/tests/features/storage-quoted-values.feature +26 -0
  164. package/tests/features/storage.feature +98 -0
  165. package/tests/features/test--then--i-see-locator.feature +13 -0
  166. package/tests/features/test--then--i-should--see-text-in-element.feature +9 -1
  167. package/tests/features/test--then--the-field-should-contain-value.feature +8 -0
  168. package/tests/features/text-matching.feature +38 -0
  169. package/tests/features/text-order.feature +14 -0
  170. package/tests/features/touch.feature +21 -0
  171. package/tests/features/video.feature +1 -0
  172. package/tests/features/viewport-top.feature +13 -0
  173. package/tests/features/wait.feature +89 -0
  174. package/tests/features/web-first.feature +100 -0
  175. package/tests/features/xml-namespaces.feature +34 -0
  176. package/tests/features/xml.feature +96 -0
  177. package/tests/features/yaml.feature +75 -0
  178. package/tests/must-fail/api-json-paths.feature +21 -0
  179. package/tests/must-fail/api-response-contains.feature +23 -0
  180. package/tests/must-fail/api-response-header-presence.feature +17 -0
  181. package/tests/must-fail/api-response-header.feature +21 -0
  182. package/tests/must-fail/api-without-base-url.feature +11 -0
  183. package/tests/must-fail/assertions.feature +96 -0
  184. package/tests/must-fail/breakpoints.feature +15 -0
  185. package/tests/must-fail/choice-controls.feature +25 -0
  186. package/tests/must-fail/clock.feature +11 -0
  187. package/tests/must-fail/datetime-field.feature +10 -0
  188. package/tests/must-fail/element-selector-hint.feature +17 -0
  189. package/tests/must-fail/field-state.feature +20 -0
  190. package/tests/must-fail/fill-field.feature +30 -0
  191. package/tests/must-fail/iframe-text.feature +17 -0
  192. package/tests/must-fail/modal-open.feature +26 -0
  193. package/tests/must-fail/multi-value-field.feature +18 -0
  194. package/tests/must-fail/registered-names.feature +25 -0
  195. package/tests/must-fail/select-list.feature +15 -0
  196. package/tests/must-fail/selector-files.feature +10 -0
  197. package/tests/must-fail/sorted-tables.feature +20 -0
  198. package/tests/must-fail/storage-before-a-page.feature +13 -0
  199. package/tests/must-fail/text-matching.feature +16 -0
  200. package/tests/must-fail/text-order.feature +15 -0
  201. package/tests/must-fail/viewport-top.feature +20 -0
  202. package/tests/must-fail/waits.feature +51 -0
  203. package/tests/must-fail/yaml-numbers.feature +48 -0
  204. package/tests/reports/README.md +2 -2
  205. package/tests/step-definitions/a11y.steps.js +36 -23
  206. package/tests/step-definitions/action.steps.js +22 -8
  207. package/tests/step-definitions/api.steps.js +349 -67
  208. package/tests/step-definitions/assertion.steps.js +327 -63
  209. package/tests/step-definitions/auth.steps.js +15 -18
  210. package/tests/step-definitions/clock.steps.js +22 -0
  211. package/tests/step-definitions/debug.steps.js +8 -0
  212. package/tests/step-definitions/dialog.steps.js +9 -2
  213. package/tests/step-definitions/element.steps.js +135 -18
  214. package/tests/step-definitions/field.steps.js +523 -80
  215. package/tests/step-definitions/file-download.steps.js +74 -10
  216. package/tests/step-definitions/form.steps.js +76 -29
  217. package/tests/step-definitions/iframe.steps.js +89 -29
  218. package/tests/step-definitions/input.steps.js +26 -7
  219. package/tests/step-definitions/javascript.steps.js +64 -22
  220. package/tests/step-definitions/modal.steps.js +79 -13
  221. package/tests/step-definitions/navigation.steps.js +14 -0
  222. package/tests/step-definitions/network.steps.js +15 -5
  223. package/tests/step-definitions/response.steps.js +6 -4
  224. package/tests/step-definitions/responsive.steps.js +26 -33
  225. package/tests/step-definitions/screenshot.steps.js +26 -9
  226. package/tests/step-definitions/scroll.steps.js +20 -0
  227. package/tests/step-definitions/selectors.steps.js +104 -51
  228. package/tests/step-definitions/storage.steps.js +41 -16
  229. package/tests/step-definitions/table.steps.js +81 -6
  230. package/tests/step-definitions/video.steps.js +52 -55
  231. package/tests/step-definitions/wait.steps.js +209 -54
  232. package/tests/step-definitions/web-first.steps.js +69 -35
  233. package/tests/step-definitions/webship.js +807 -128
  234. package/tests/step-definitions/xml.steps.js +124 -28
  235. package/tests/step-definitions/yaml.steps.js +90 -46
  236. package/.scratch/commit.txt +0 -14
  237. package/.scratch/docs.py +0 -42
  238. package/.scratch/echo-server.js +0 -8
  239. package/.scratch/echo.js +0 -35
  240. package/.scratch/echo.pid +0 -1
  241. package/.scratch/features/cookies.feature +0 -22
  242. package/.scratch/http.pid +0 -1
  243. package/.scratch/https.pid +0 -1
  244. package/.scratch/issue.md +0 -49
  245. package/.scratch/one.js +0 -2
  246. package/.scratch/one.json +0 -280
  247. package/.scratch/patch.py +0 -163
  248. package/.scratch/pr.md +0 -30
package/.scratch/issue.md DELETED
@@ -1,49 +0,0 @@
1
- ### Problem/Motivation
2
-
3
- `When I send a REST "<method>" request to "<url>"` (`tests/step-definitions/rest.steps.js`) and the API request steps `When I send a <METHOD> request to "<endpoint>"` with their `with body:`, `with values:` and `with form data:` forms (`tests/step-definitions/api.steps.js`) send their request from Node with `axios`, outside the browser. Node does not trust a self-signed or locally issued certificate, so on a site served over HTTPS with one the REST step fails with:
4
-
5
- ```
6
- Error: self-signed certificate
7
- ```
8
-
9
- and the API steps fail with:
10
-
11
- ```
12
- GET request failed: self-signed certificate
13
- ```
14
-
15
- (`unable to verify the first certificate` when the certificate comes from a local authority.) The browser itself opens the same site, because the browser context sets `ignoreHTTPSErrors`. It is the same weakness as #330, in the remaining steps that still send a request from Node.
16
-
17
- #### Steps to reproduce
18
-
19
- 1. Serve `examples/` over HTTPS with a self-signed certificate: `npx http-server examples -p 8443 -S -C cert.pem -K key.pem`.
20
- 2. Run the suite with `LAUNCH_URL=https://localhost:8443`.
21
- 3. `When I send a REST "GET" request to "/example-api.json"` (`tests/features/absolute-url.feature:41`) fails with `Error: self-signed certificate`.
22
- 4. `Given the API base URL is "/"`, `When I send a GET request to "/example-api.json"` fails with `GET request failed: self-signed certificate`.
23
-
24
- ### Proposed resolution
25
-
26
- Send these requests with Playwright's request API so they follow the HTTPS setting of the browser context: the REST steps through the browser context itself, the API steps from a request context of their own that carries no cookie of the browser.
27
-
28
- AI-Generated: Yes
29
-
30
- ### Checkpoints:
31
- - [x] File an issue
32
- - [ ] Addition/Change/Update/Fix
33
- - [ ] Testing to ensure no regression
34
- - [ ] Automated unit testing coverage
35
- - [ ] Automated functional testing coverage
36
- - [ ] UX/UI designer responsibilities
37
- - [ ] Readability
38
- - [ ] Accessibility
39
- - [ ] Performance
40
- - [ ] Security
41
- - [ ] Developer Documentation
42
- - [ ] User Guide Documentation
43
- - [ ] Reviewed by human
44
- - [ ] Code review by maintainers
45
- - [ ] Full testing and approval
46
- - [ ] Credit contributors
47
- - [ ] Review with the product owner
48
- - [ ] Release notes snippet
49
- - [ ] Release
package/.scratch/one.js DELETED
@@ -1,2 +0,0 @@
1
- const base = require('../cucumber.js').default;
2
- module.exports = { default: { ...base, paths: process.env.ONE.split(','), format: ['progress', 'json:.scratch/one.json'] } };
package/.scratch/one.json DELETED
@@ -1,280 +0,0 @@
1
- [
2
- {
3
- "description": "",
4
- "elements": [
5
- {
6
- "description": "",
7
- "id": "cookie-check-(not-committed);rest-shares-the-browser-cookies,-api-does-not",
8
- "keyword": "Scenario",
9
- "line": 2,
10
- "name": "REST shares the browser cookies, API does not",
11
- "steps": [
12
- {
13
- "keyword": "Before",
14
- "hidden": true,
15
- "result": {
16
- "status": "passed",
17
- "duration": 59045699
18
- }
19
- },
20
- {
21
- "keyword": "Before",
22
- "hidden": true,
23
- "result": {
24
- "status": "passed",
25
- "duration": 146611
26
- }
27
- },
28
- {
29
- "keyword": "Before",
30
- "hidden": true,
31
- "result": {
32
- "status": "passed",
33
- "duration": 429690
34
- }
35
- },
36
- {
37
- "keyword": "Before",
38
- "hidden": true,
39
- "result": {
40
- "status": "passed",
41
- "duration": 358450
42
- }
43
- },
44
- {
45
- "keyword": "Before",
46
- "hidden": true,
47
- "result": {
48
- "status": "passed",
49
- "duration": 56777
50
- }
51
- },
52
- {
53
- "keyword": "Before",
54
- "hidden": true,
55
- "result": {
56
- "status": "passed",
57
- "duration": 106737
58
- }
59
- },
60
- {
61
- "arguments": [],
62
- "keyword": "Given ",
63
- "line": 3,
64
- "name": "I am on \"/about-us.html\"",
65
- "match": {
66
- "location": "tests/step-definitions/navigation.steps.js:64"
67
- },
68
- "result": {
69
- "status": "passed",
70
- "duration": 520204689
71
- }
72
- },
73
- {
74
- "arguments": [],
75
- "keyword": "And ",
76
- "line": 4,
77
- "name": "the cookie \"session_id\" is set to \"abc123\"",
78
- "match": {
79
- "location": "tests/step-definitions/storage.steps.js:31"
80
- },
81
- "result": {
82
- "status": "passed",
83
- "duration": 2178232
84
- }
85
- },
86
- {
87
- "arguments": [],
88
- "keyword": "Given ",
89
- "line": 5,
90
- "name": "the API base URL is \"http://localhost:8990\"",
91
- "match": {
92
- "location": "tests/step-definitions/api.steps.js:101"
93
- },
94
- "result": {
95
- "status": "passed",
96
- "duration": 449720
97
- }
98
- },
99
- {
100
- "arguments": [],
101
- "keyword": "And ",
102
- "line": 6,
103
- "name": "I am authenticating as \"tester\" with \"secret\" password",
104
- "match": {
105
- "location": "tests/step-definitions/api.steps.js:66"
106
- },
107
- "result": {
108
- "status": "passed",
109
- "duration": 356252
110
- }
111
- },
112
- {
113
- "arguments": [
114
- {
115
- "content": "{\"a\": 1}",
116
- "line": 8
117
- }
118
- ],
119
- "keyword": "When ",
120
- "line": 7,
121
- "name": "I send a POST request to \"/echo\" with body:",
122
- "match": {
123
- "location": "tests/step-definitions/api.steps.js:314"
124
- },
125
- "result": {
126
- "status": "passed",
127
- "duration": 15836827
128
- }
129
- },
130
- {
131
- "arguments": [],
132
- "keyword": "Then ",
133
- "line": 11,
134
- "name": "the JSON response should have \"cookie\" equal to \"none\"",
135
- "match": {
136
- "location": "tests/step-definitions/api.steps.js:548"
137
- },
138
- "result": {
139
- "status": "passed",
140
- "duration": 230198
141
- }
142
- },
143
- {
144
- "arguments": [],
145
- "keyword": "And ",
146
- "line": 12,
147
- "name": "the JSON response should have \"auth\" equal to \"Basic dGVzdGVyOnNlY3JldA==\"",
148
- "match": {
149
- "location": "tests/step-definitions/api.steps.js:548"
150
- },
151
- "result": {
152
- "status": "passed",
153
- "duration": 134050
154
- }
155
- },
156
- {
157
- "arguments": [],
158
- "keyword": "And ",
159
- "line": 13,
160
- "name": "the JSON response should have \"type\" equal to \"application/json\"",
161
- "match": {
162
- "location": "tests/step-definitions/api.steps.js:548"
163
- },
164
- "result": {
165
- "status": "passed",
166
- "duration": 146486
167
- }
168
- },
169
- {
170
- "arguments": [],
171
- "keyword": "And ",
172
- "line": 14,
173
- "name": "a cookie with the name \"from_api\" should not exist",
174
- "match": {
175
- "location": "tests/step-definitions/cookie.steps.js:132"
176
- },
177
- "result": {
178
- "status": "passed",
179
- "duration": 1479906
180
- }
181
- },
182
- {
183
- "arguments": [
184
- {
185
- "content": "a=1&b=2",
186
- "line": 16
187
- }
188
- ],
189
- "keyword": "When ",
190
- "line": 15,
191
- "name": "I send a REST \"POST\" request to \"http://localhost:8990/echo\" with body:",
192
- "match": {
193
- "location": "tests/step-definitions/rest.steps.js:88"
194
- },
195
- "result": {
196
- "status": "passed",
197
- "duration": 7299009
198
- }
199
- },
200
- {
201
- "arguments": [],
202
- "keyword": "Then ",
203
- "line": 19,
204
- "name": "the REST response should contain \"session_id=abc123\"",
205
- "match": {
206
- "location": "tests/step-definitions/rest.steps.js:118"
207
- },
208
- "result": {
209
- "status": "passed",
210
- "duration": 308369
211
- }
212
- },
213
- {
214
- "arguments": [],
215
- "keyword": "And ",
216
- "line": 20,
217
- "name": "the REST response should contain \"application/x-www-form-urlencoded\"",
218
- "match": {
219
- "location": "tests/step-definitions/rest.steps.js:118"
220
- },
221
- "result": {
222
- "status": "passed",
223
- "duration": 187290
224
- }
225
- },
226
- {
227
- "arguments": [],
228
- "keyword": "And ",
229
- "line": 21,
230
- "name": "the REST response should contain \"a=1&b=2\"",
231
- "match": {
232
- "location": "tests/step-definitions/rest.steps.js:118"
233
- },
234
- "result": {
235
- "status": "passed",
236
- "duration": 100281
237
- }
238
- },
239
- {
240
- "arguments": [],
241
- "keyword": "And ",
242
- "line": 22,
243
- "name": "a cookie with the name \"from_api\" should exist",
244
- "match": {
245
- "location": "tests/step-definitions/cookie.steps.js:32"
246
- },
247
- "result": {
248
- "status": "passed",
249
- "duration": 1266994
250
- }
251
- },
252
- {
253
- "keyword": "After",
254
- "hidden": true,
255
- "result": {
256
- "status": "passed",
257
- "duration": 97005
258
- }
259
- },
260
- {
261
- "keyword": "After",
262
- "hidden": true,
263
- "result": {
264
- "status": "passed",
265
- "duration": 18792075
266
- }
267
- }
268
- ],
269
- "tags": [],
270
- "type": "scenario"
271
- }
272
- ],
273
- "id": "cookie-check-(not-committed)",
274
- "line": 1,
275
- "keyword": "Feature",
276
- "name": "cookie check (not committed)",
277
- "tags": [],
278
- "uri": ".scratch/features/cookies.feature"
279
- }
280
- ]
package/.scratch/patch.py DELETED
@@ -1,163 +0,0 @@
1
- import re,io
2
- p='tests/step-definitions/webship.js'
3
- s=open(p).read()
4
- helper = r'''
5
- // Transport settings of the browser context that a request sent outside the
6
- // browser session still has to follow: the HTTPS setting, the proxy and the
7
- // client certificates. Nothing of the session itself (cookies, storage,
8
- // credentials, extra headers) is in this list.
9
- function transportOptions() {
10
- const from = playwrightConfig.contextOptions || {};
11
- const options = {};
12
- for (const key of ['ignoreHTTPSErrors', 'proxy', 'clientCertificates']) {
13
- if (from[key] !== undefined) options[key] = from[key];
14
- }
15
- return options;
16
- }
17
-
18
- function hasHeader(headers, name) {
19
- const wanted = name.toLowerCase();
20
- return Object.keys(headers).some((key) => key.toLowerCase() === wanted);
21
- }
22
-
23
- /**
24
- * Send an HTTP request with Playwright's request API and return the answer
25
- * as `{ status, statusText, headers, data, config }`: header names are in
26
- * lower case and `data` is the parsed JSON when the body is JSON, the body
27
- * text otherwise. No status code throws.
28
- *
29
- * `session: true` sends the request through the browser context, so it
30
- * shares the cookies, the credentials and the extra headers of the page.
31
- * `session: false` sends it from a request context of its own: no cookie of
32
- * the browser goes with it and none comes back into the browser. Both follow
33
- * the HTTPS setting of the browser context, so a self-signed or locally
34
- * issued certificate is accepted whenever the browser accepts it.
35
- *
36
- * @param {Object} world
37
- * @param {{method: string, url: string, headers?: Object, data?: *, session?: boolean}} request
38
- * @returns {Promise<{status: number, statusText: string, headers: Object, data: *, config: Object}>}
39
- */
40
- async function sendRequest(world, { method, url, headers, data, session }) {
41
- const verb = String(method || 'GET').toUpperCase();
42
- const sent = Object.assign({}, headers || {});
43
- if (!hasHeader(sent, 'accept')) sent.Accept = 'application/json, text/plain, */*';
44
- const options = { method: verb, headers: sent, failOnStatusCode: false };
45
- if (data !== undefined && data !== null) {
46
- options.data = data;
47
- // A raw text body with no declared type goes out as a form body.
48
- if (typeof data === 'string' && !hasHeader(sent, 'content-type') && /^(POST|PUT|PATCH)$/.test(verb)) {
49
- sent['Content-Type'] = 'application/x-www-form-urlencoded';
50
- }
51
- }
52
- const shared = session && world && world.context ? world.context.request : null;
53
- const own = shared ? null : await playwright.request.newContext(transportOptions());
54
- try {
55
- const response = await (shared || own).fetch(url, options);
56
- const text = await response.text();
57
- let body = text;
58
- try { body = JSON.parse(text); } catch (e) { /* not JSON: keep the text */ }
59
- return {
60
- status: response.status(),
61
- statusText: response.statusText(),
62
- headers: response.headers(),
63
- data: body,
64
- config: { method: verb.toLowerCase(), url },
65
- };
66
- } finally {
67
- if (own) await own.dispose();
68
- }
69
- }
70
-
71
- /**
72
- * Navigate to a URL with friendly error messages for common failures'''
73
- marker = '''
74
- /**
75
- * Navigate to a URL with friendly error messages for common failures'''
76
- assert s.count(marker)==1
77
- s=s.replace(marker,helper)
78
- s=s.replace(" resolveUrl,\n fillField,"," resolveUrl,\n sendRequest,\n fillField,")
79
- open(p,'w').write(s)
80
-
81
- p='tests/step-definitions/rest.steps.js'
82
- s=open(p).read()
83
- s=s.replace("""// Lightweight REST testing — distinct from the existing api.steps.js steps
84
- // Preserves exact step phrasing for compatibility.
85
- ""","""// Lightweight REST testing — distinct from the existing api.steps.js steps
86
- // Preserves exact step phrasing for compatibility.
87
- //
88
- // A REST request is sent through the browser context, so it follows the
89
- // browser session: its cookies, its credentials and its HTTPS setting (a
90
- // self-signed or locally issued certificate is accepted like in the page).
91
- """)
92
- s=s.replace("const axios = require('axios');\nconst { resolveUrl } = require('./webship');","const { resolveUrl, sendRequest, friendly } = require('./webship');")
93
- s=s.replace("""function ensureState(world) {
94
- if (!world._rest) world._rest = { headers: {}, response: null };
95
- return world._rest;
96
- }
97
- ""","""function ensureState(world) {
98
- if (!world._rest) world._rest = { headers: {}, response: null };
99
- return world._rest;
100
- }
101
-
102
- async function sendRest(world, method, url, body) {
103
- const s = ensureState(world);
104
- const target = resolveUrl(world.launchUrl, url);
105
- try {
106
- s.response = await sendRequest(world, {
107
- method, url: target, headers: s.headers, data: body, session: true,
108
- });
109
- } catch (e) {
110
- throw friendly({
111
- action: `send the REST ${method} request to "${target}"`,
112
- cause: e,
113
- hint: 'check the URL is reachable from the machine that runs the tests.',
114
- });
115
- }
116
- }
117
- """)
118
- old1=""" const s = ensureState(this);
119
- const target = resolveUrl(this.launchUrl, url);
120
- s.response = await axios.request({
121
- method, url: target, headers: s.headers, validateStatus: () => true,
122
- });
123
- """
124
- old2=""" const s = ensureState(this);
125
- const target = resolveUrl(this.launchUrl, url);
126
- s.response = await axios.request({
127
- method, url: target, headers: s.headers, data: body, validateStatus: () => true,
128
- });
129
- """
130
- assert old1 in s and old2 in s
131
- s=s.replace(old1," await sendRest(this, method, url);\n").replace(old2," await sendRest(this, method, url, body);\n")
132
- open(p,'w').write(s)
133
-
134
- p='tests/step-definitions/api.steps.js'
135
- s=open(p).read()
136
- s=s.replace("const axios = require('axios');\nconst assert = require('assert');\nconst { friendly } = require('./webship');","const assert = require('assert');\nconst { friendly, sendRequest } = require('./webship');")
137
- s=s.replace("""// Global variables to store API response and request data""","""// The API steps talk to an API on its own terms: its own base URL, its own
138
- // authentication and headers. A request is sent outside the browser session
139
- // (no cookie of the browser goes with it), and it follows the HTTPS setting
140
- // of the browser context, so a self-signed or locally issued certificate is
141
- // accepted whenever the browser accepts it.
142
- function sendApiRequest(world, method, url, headers, data) {
143
- return sendRequest(world, { method, url, headers, data, session: false });
144
- }
145
-
146
- // Global variables to store API response and request data""")
147
- pat=re.compile(r"""apiResponse = await axios\(\{
148
- method: method,
149
- url: url,
150
- headers: (.*?),
151
- data: (\w+(?:\.stringify\(fields\))?),
152
- validateStatus: function \(status\) \{
153
- return true; // Don't throw on any status code
154
- \}
155
- \}\);""",re.S)
156
- def rep(m):
157
- h=re.sub(r"\s+"," ",m.group(1)).replace("{ ...apiHeaders, 'Content-Type': 'application/x-www-form-urlencoded' }","{ ...apiHeaders, 'Content-Type': 'application/x-www-form-urlencoded' }")
158
- return "apiResponse = await sendApiRequest(this, method, url, %s, %s);"%(h,m.group(2))
159
- s,n=pat.subn(rep,s)
160
- assert n==4,n
161
- s,n=re.subn(r"throw friendly\(`\$\{method\} request( with \w+(?: data)?)? failed: \$\{error\.message\}`\);", lambda m:"throw friendly(`${method} request%s to \"${url}\" failed.`, error);"%(m.group(1) or ''), s)
162
- assert n==4,n
163
- open(p,'w').write(s)
package/.scratch/pr.md DELETED
@@ -1,30 +0,0 @@
1
- The REST request steps (`I send a REST "<method>" request to "<url>"`, with and without a body) and the API request steps (`I send a <METHOD> request to "<endpoint>"`, plain and with a body, values or form data) now send their request with Playwright's request API instead of `axios` from Node, so they follow the HTTPS setting of the browser context and reach a site served with a self-signed or locally issued certificate. The REST steps go through the browser context and share its cookies; the API steps keep their own base URL, authentication and headers and carry no cookie of the browser. Step phrases and the status, header, body and JSON assertions that follow them are unchanged.
2
-
3
- Closes #333
4
-
5
- Proof: the new `tests/features/rest-and-api-requests.feature` (14 scenarios: GET and POST with a JSON body, 404 and 405 answers, a response header and JSON assertions, a path and an absolute URL) fails 7 of 14 before the change over HTTPS with a self-signed certificate (`self-signed certificate`) and passes after it. Full suite locally, over HTTP and over HTTPS with a self-signed certificate: 345 scenarios, 1652 steps, all passed in both.
6
-
7
- AI-Generated: Yes
8
-
9
- ### Checkpoints:
10
- - [x] File an issue
11
- - [x] Addition/Change/Update/Fix
12
- - [x] Testing to ensure no regression
13
- - [ ] Automated unit testing coverage
14
- - [x] Automated functional testing coverage
15
- - [ ] UX/UI designer responsibilities
16
- - [ ] Readability
17
- - [ ] Accessibility
18
- - [ ] Performance
19
- - [ ] Security
20
- - [ ] Developer Documentation
21
- - [x] User Guide Documentation
22
- - [ ] Reviewed by human
23
- - [ ] Code review by maintainers
24
- - [ ] Full testing and approval
25
- - [ ] Credit contributors
26
- - [ ] Review with the product owner
27
- - [ ] Release notes snippet
28
- - [ ] Release
29
-
30
- 🤖 Generated with [Claude Code](https://claude.com/claude-code)