webship-js 2.0.10 → 2.0.11

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 (110) hide show
  1. package/.github/ISSUE_TEMPLATE/issue.md +37 -0
  2. package/.github/PULL_REQUEST_TEMPLATE.md +24 -0
  3. package/.github/workflows/github-actions.yml +56 -4
  4. package/CLAUDE.md +5 -2
  5. package/README.md +13 -1
  6. package/bin/generate-reports.js +51 -7
  7. package/bin/init-webship.js +85 -17
  8. package/cucumber.js +29 -1
  9. package/docs/00-quick-start.md +30 -7
  10. package/docs/02-bbr-smart-waits.md +6 -0
  11. package/docs/04-step-reference.md +2 -2
  12. package/docs/11-debugging.md +21 -0
  13. package/docs/12-ai-agent-guide.md +3 -1
  14. package/docs/13-faq.md +3 -0
  15. package/docs/15-tag-conventions.md +4 -1
  16. package/docs/16-ci-cd.md +29 -13
  17. package/docs/global-settings.md +2 -2
  18. package/docs/install-webship-js/ddev-webship-js.md +3 -0
  19. package/docs/install-webship-js.md +14 -2
  20. package/examples/a11y-legacy-widget.html +34 -0
  21. package/examples/auth-state.html +42 -0
  22. package/examples/clock.html +33 -0
  23. package/examples/downloads/webship-archive.zip +0 -0
  24. package/examples/downloads/webship-notes.txt +4 -0
  25. package/examples/downloads/webship-report.csv +4 -0
  26. package/examples/downloads.html +16 -0
  27. package/examples/element-viewport.html +42 -0
  28. package/examples/field-types.html +98 -0
  29. package/examples/iframe-newsletter.html +29 -0
  30. package/examples/iframe-order.html +26 -0
  31. package/examples/iframe.html +21 -0
  32. package/examples/javascript-errors.html +35 -0
  33. package/examples/links.html +1 -0
  34. package/examples/metatags.html +18 -0
  35. package/examples/mouse-and-pointer.html +83 -0
  36. package/examples/native-dialogs.html +8 -0
  37. package/examples/network.html +83 -0
  38. package/examples/scroll-horizontal.html +50 -0
  39. package/examples/selectors-position.html +29 -0
  40. package/examples/storage.html +57 -0
  41. package/examples/viewport-size.html +24 -0
  42. package/examples/wait-conditions.html +69 -0
  43. package/examples/web-first.html +99 -0
  44. package/package.json +9 -2
  45. package/tests/assets/catalog.xml +19 -0
  46. package/tests/assets/feed-namespaced.xml +13 -0
  47. package/tests/assets/sitemap.xml +14 -0
  48. package/tests/assets/webship-site-expected.yaml +21 -0
  49. package/tests/assets/webship-site.schema.json +46 -0
  50. package/tests/assets/webship-site.yaml +21 -0
  51. package/tests/check-examples.js +235 -0
  52. package/tests/check-must-fail.js +84 -0
  53. package/tests/check-paths.js +82 -0
  54. package/tests/check-report.js +119 -0
  55. package/tests/check-scaffold.js +211 -0
  56. package/tests/features/a11y.feature +18 -0
  57. package/tests/features/auth-state.feature +32 -0
  58. package/tests/features/clock.feature +27 -0
  59. package/tests/features/cookie.feature +9 -0
  60. package/tests/features/dialog.feature +27 -0
  61. package/tests/features/element.feature +47 -0
  62. package/tests/features/field.feature +104 -0
  63. package/tests/features/file-download.feature +64 -0
  64. package/tests/features/iframe.feature +83 -0
  65. package/tests/features/javascript.feature +47 -0
  66. package/tests/features/link.feature +11 -0
  67. package/tests/features/metatag.feature +38 -0
  68. package/tests/features/mouse-and-pointer.feature +86 -0
  69. package/tests/features/network-mocking.feature +80 -0
  70. package/tests/features/responsive.feature +27 -0
  71. package/tests/features/scroll-horizontal.feature +55 -0
  72. package/tests/features/selectors-position.feature +41 -0
  73. package/tests/features/storage.feature +98 -0
  74. package/tests/features/test--then--i-see-locator.feature +13 -0
  75. package/tests/features/test--then--i-should--see-text-in-element.feature +9 -1
  76. package/tests/features/test--then--the-field-should-contain-value.feature +8 -0
  77. package/tests/features/video.feature +1 -0
  78. package/tests/features/wait.feature +89 -0
  79. package/tests/features/web-first.feature +100 -0
  80. package/tests/features/xml.feature +96 -0
  81. package/tests/features/yaml.feature +75 -0
  82. package/tests/must-fail/assertions.feature +96 -0
  83. package/tests/must-fail/waits.feature +51 -0
  84. package/tests/reports/README.md +2 -2
  85. package/tests/step-definitions/a11y.steps.js +12 -8
  86. package/tests/step-definitions/assertion.steps.js +235 -61
  87. package/tests/step-definitions/dialog.steps.js +2 -2
  88. package/tests/step-definitions/element.steps.js +3 -1
  89. package/tests/step-definitions/field.steps.js +152 -22
  90. package/tests/step-definitions/file-download.steps.js +74 -10
  91. package/tests/step-definitions/screenshot.steps.js +1 -1
  92. package/tests/step-definitions/selectors.steps.js +9 -3
  93. package/tests/step-definitions/storage.steps.js +3 -3
  94. package/tests/step-definitions/wait.steps.js +129 -39
  95. package/tests/step-definitions/webship.js +144 -3
  96. package/tests/step-definitions/xml.steps.js +76 -14
  97. package/tests/step-definitions/yaml.steps.js +46 -27
  98. package/.scratch/commit.txt +0 -14
  99. package/.scratch/docs.py +0 -42
  100. package/.scratch/echo-server.js +0 -8
  101. package/.scratch/echo.js +0 -35
  102. package/.scratch/echo.pid +0 -1
  103. package/.scratch/features/cookies.feature +0 -22
  104. package/.scratch/http.pid +0 -1
  105. package/.scratch/https.pid +0 -1
  106. package/.scratch/issue.md +0 -49
  107. package/.scratch/one.js +0 -2
  108. package/.scratch/one.json +0 -280
  109. package/.scratch/patch.py +0 -163
  110. package/.scratch/pr.md +0 -30
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)