webship-js 2.0.11 → 2.0.13
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.
- package/.circleci/config.yml +10 -1
- package/.drone.yml +7 -7
- package/.github/workflows/github-actions.yml +48 -0
- package/.gitlab-ci.yml +9 -4
- package/.harness/webship-js-pipeline.yml +5 -6
- package/.semaphore/semaphore.yml +6 -9
- package/.teamcity/settings.kts +7 -6
- package/.travis.yml +6 -1
- package/AGENTS.md +1 -1
- package/CLAUDE.md +65 -23
- package/Jenkinsfile +5 -3
- package/azure-pipelines.yml +17 -8
- package/bamboo-specs/bamboo.yml +9 -15
- package/bin/init-webship.js +53 -10
- package/bitbucket-pipelines.yml +5 -1
- package/buildspec.yml +6 -7
- package/cloudbuild.yaml +28 -12
- package/codefresh.yml +6 -6
- package/cucumber.js +17 -10
- package/docs/00-quick-start.md +8 -0
- package/docs/02-bbr-smart-waits.md +15 -10
- package/docs/03-selector-registry.md +24 -0
- package/docs/04-step-reference.md +51 -25
- package/docs/05-web-first-assertions.md +6 -0
- package/docs/07-auth-state.md +1 -1
- package/docs/08-clock-mocking.md +21 -2
- package/docs/09-api-testing.md +40 -2
- package/docs/10-accessibility.md +2 -0
- package/docs/11-debugging.md +3 -1
- package/docs/12-ai-agent-guide.md +5 -0
- package/docs/13-faq.md +72 -1
- package/docs/14-recipes-cookbook.md +2 -0
- package/docs/15-tag-conventions.md +2 -1
- package/docs/16-ci-cd.md +140 -119
- package/docs/README.md +5 -5
- package/docs/advanced-screenshots.md +3 -1
- package/docs/api-step-definitions.md +16 -2
- package/docs/global-settings.md +69 -17
- package/docs/install-webship-js.md +2 -0
- package/docs/step-definitions/then-i-should-see.md +14 -1
- package/docs/step-definitions/then-item-checkbox.md +2 -0
- package/docs/step-definitions/when-i-fill.md +4 -0
- package/docs/step-definitions/when-i-select-option-select-list.md +2 -0
- package/examples/check-switch.html +37 -0
- package/examples/choice-controls.html +29 -0
- package/examples/click-whitespace.html +37 -0
- package/examples/datetime-fields.html +52 -0
- package/examples/element-selector-hint.html +16 -0
- package/examples/field-states.html +27 -0
- package/examples/fill-in-empty.html +26 -0
- package/examples/fill-unreachable.html +27 -0
- package/examples/follow-hidden-first.html +29 -0
- package/examples/iframe-inner.html +20 -0
- package/examples/iframe-nested.html +16 -0
- package/examples/iframe-outer.html +15 -0
- package/examples/multi-value-fields.html +54 -0
- package/examples/registered-names.html +15 -0
- package/examples/select-by-label.html +33 -0
- package/examples/settle-budget.html +21 -0
- package/examples/sorted-tables.html +38 -0
- package/examples/text-matching.html +48 -0
- package/examples/text-order.html +25 -0
- package/examples/touch.html +22 -0
- package/examples/viewport-top.html +36 -0
- package/package.json +17 -1
- package/playwright.config.ts +3 -1
- package/tests/check-api-launch-url.js +106 -0
- package/tests/check-assets.js +103 -0
- package/tests/check-attachments.js +105 -0
- package/tests/check-breakpoints.js +117 -0
- package/tests/check-clock.js +143 -0
- package/tests/check-config.js +90 -0
- package/tests/check-context.js +215 -0
- package/tests/check-dry-run.js +104 -0
- package/tests/check-examples.js +10 -4
- package/tests/check-exit-report.js +141 -0
- package/tests/check-javascript-errors.js +105 -0
- package/tests/check-must-fail.js +5 -4
- package/tests/check-network-changed.js +137 -0
- package/tests/check-scaffold.js +54 -2
- package/tests/check-screenshots.js +117 -0
- package/tests/check-settle-verbs.js +137 -0
- package/tests/check-time-limit.js +104 -0
- package/tests/check-video.js +156 -0
- package/tests/check-world.js +167 -0
- package/tests/features/api-base-url.feature +25 -0
- package/tests/features/api-form-data.feature +18 -0
- package/tests/features/api-json-paths.feature +24 -0
- package/tests/features/api-response-contains.feature +21 -0
- package/tests/features/api-response-header-presence.feature +17 -0
- package/tests/features/api-response-header.feature +17 -0
- package/tests/features/api-saved-placeholders.feature +37 -0
- package/tests/features/api-step-definitions-individual.feature +1 -1
- package/tests/features/api-tables.feature +40 -0
- package/tests/features/breakpoints.feature +25 -0
- package/tests/features/check-switch.feature +28 -0
- package/tests/features/choice-controls.feature +35 -0
- package/tests/features/click-whitespace.feature +29 -0
- package/tests/features/complete-api-testing-examples.feature +1 -1
- package/tests/features/datetime-field-lookup.feature +29 -0
- package/tests/features/element-selector-hint.feature +14 -0
- package/tests/features/field-state.feature +21 -0
- package/tests/features/fill-in-empty-value.feature +41 -0
- package/tests/features/fill-reachable.feature +13 -0
- package/tests/features/follow-hidden-first.feature +9 -0
- package/tests/features/iframe-nested.feature +43 -0
- package/tests/features/javascript-tolerated-errors.feature +20 -0
- package/tests/features/modal-open.feature +13 -0
- package/tests/features/multi-value-field-lookup.feature +30 -0
- package/tests/features/registered-names.feature +14 -0
- package/tests/features/select-by-label.feature +31 -0
- package/tests/features/selector-files.feature +14 -0
- package/tests/features/selectors-table-header.feature +35 -0
- package/tests/features/settle-budget.feature +11 -0
- package/tests/features/sorted-tables.feature +19 -0
- package/tests/features/storage-quoted-values.feature +26 -0
- package/tests/features/text-matching.feature +38 -0
- package/tests/features/text-order.feature +14 -0
- package/tests/features/touch.feature +21 -0
- package/tests/features/viewport-top.feature +13 -0
- package/tests/features/xml-namespaces.feature +34 -0
- package/tests/must-fail/api-json-paths.feature +21 -0
- package/tests/must-fail/api-response-contains.feature +23 -0
- package/tests/must-fail/api-response-header-presence.feature +17 -0
- package/tests/must-fail/api-response-header.feature +21 -0
- package/tests/must-fail/api-without-base-url.feature +11 -0
- package/tests/must-fail/breakpoints.feature +15 -0
- package/tests/must-fail/choice-controls.feature +25 -0
- package/tests/must-fail/clock.feature +11 -0
- package/tests/must-fail/datetime-field.feature +10 -0
- package/tests/must-fail/element-selector-hint.feature +17 -0
- package/tests/must-fail/field-state.feature +20 -0
- package/tests/must-fail/fill-field.feature +30 -0
- package/tests/must-fail/iframe-text.feature +17 -0
- package/tests/must-fail/modal-open.feature +26 -0
- package/tests/must-fail/multi-value-field.feature +18 -0
- package/tests/must-fail/registered-names.feature +25 -0
- package/tests/must-fail/select-list.feature +15 -0
- package/tests/must-fail/selector-files.feature +10 -0
- package/tests/must-fail/sorted-tables.feature +20 -0
- package/tests/must-fail/storage-before-a-page.feature +13 -0
- package/tests/must-fail/text-matching.feature +16 -0
- package/tests/must-fail/text-order.feature +15 -0
- package/tests/must-fail/viewport-top.feature +20 -0
- package/tests/must-fail/yaml-numbers.feature +48 -0
- package/tests/step-definitions/a11y.steps.js +24 -15
- package/tests/step-definitions/action.steps.js +53 -20
- package/tests/step-definitions/api.steps.js +349 -67
- package/tests/step-definitions/assertion.steps.js +100 -10
- package/tests/step-definitions/auth.steps.js +15 -18
- package/tests/step-definitions/clock.steps.js +22 -0
- package/tests/step-definitions/debug.steps.js +8 -0
- package/tests/step-definitions/dialog.steps.js +7 -0
- package/tests/step-definitions/element.steps.js +132 -17
- package/tests/step-definitions/field.steps.js +412 -96
- package/tests/step-definitions/form.steps.js +88 -37
- package/tests/step-definitions/iframe.steps.js +89 -29
- package/tests/step-definitions/input.steps.js +26 -7
- package/tests/step-definitions/javascript.steps.js +64 -22
- package/tests/step-definitions/modal.steps.js +79 -13
- package/tests/step-definitions/navigation.steps.js +14 -0
- package/tests/step-definitions/network.steps.js +15 -5
- package/tests/step-definitions/response.steps.js +6 -4
- package/tests/step-definitions/responsive.steps.js +26 -33
- package/tests/step-definitions/screenshot.steps.js +25 -8
- package/tests/step-definitions/scroll.steps.js +20 -0
- package/tests/step-definitions/selectors.steps.js +95 -48
- package/tests/step-definitions/storage.steps.js +38 -13
- package/tests/step-definitions/table.steps.js +81 -6
- package/tests/step-definitions/video.steps.js +52 -55
- package/tests/step-definitions/wait.steps.js +88 -23
- package/tests/step-definitions/web-first.steps.js +69 -35
- package/tests/step-definitions/webship.js +741 -145
- package/tests/step-definitions/xml.steps.js +49 -15
- package/tests/step-definitions/yaml.steps.js +45 -20
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Runs a project World that extends the PlaywrightWorld webship-js exports,
|
|
5
|
+
// with a project step that calls this.smartSettle(), and checks that the
|
|
6
|
+
// extended World keeps what webship-js puts on a page (the @mobile viewport,
|
|
7
|
+
// the settle of the smart waits); then runs a World that replaces it
|
|
8
|
+
// without extending it and checks that the run says so.
|
|
9
|
+
//
|
|
10
|
+
// The check serves its own page on a free local port, so no other server is
|
|
11
|
+
// needed.
|
|
12
|
+
//
|
|
13
|
+
// Usage: node tests/check-world.js (npm run test:world)
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const http = require('http');
|
|
19
|
+
const { spawn } = require('child_process');
|
|
20
|
+
|
|
21
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
22
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-world-'));
|
|
23
|
+
const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
|
|
24
|
+
const webship = path.join(ROOT, 'tests', 'step-definitions', 'webship.js');
|
|
25
|
+
const defaults = require(path.join(ROOT, 'cucumber.js')).default;
|
|
26
|
+
|
|
27
|
+
const PAGE = `<!doctype html><html><head><title>World</title></head><body>
|
|
28
|
+
<h1>World</h1>
|
|
29
|
+
<button id="add" type="button">Add</button>
|
|
30
|
+
<p id="cart">Empty</p>
|
|
31
|
+
<script>
|
|
32
|
+
document.getElementById('add').addEventListener('click', function () {
|
|
33
|
+
setTimeout(function () { document.getElementById('cart').textContent = '1 item'; }, 600);
|
|
34
|
+
});
|
|
35
|
+
</script></body></html>`;
|
|
36
|
+
|
|
37
|
+
const extending = [
|
|
38
|
+
`const { setWorldConstructor, When, Then } = require(${JSON.stringify(cucumber)});`,
|
|
39
|
+
`const { PlaywrightWorld } = require(${JSON.stringify(webship)});`,
|
|
40
|
+
'class ProjectWorld extends PlaywrightWorld {',
|
|
41
|
+
" greeting() { return 'hello from the project World'; }",
|
|
42
|
+
'}',
|
|
43
|
+
'setWorldConstructor(ProjectWorld);',
|
|
44
|
+
"When('I put one item in the cart', async function () {",
|
|
45
|
+
" await this.page.click('#add');",
|
|
46
|
+
' await this.smartSettle();',
|
|
47
|
+
'});',
|
|
48
|
+
"Then('the World should be the project one', function () {",
|
|
49
|
+
" if (this.greeting() !== 'hello from the project World') throw new Error('Not the project World.');",
|
|
50
|
+
'});',
|
|
51
|
+
"Then('the window should be {int} by {int}', async function (width, height) {",
|
|
52
|
+
' const size = await this.page.evaluate(() => `${window.innerWidth} by ${window.innerHeight}`);',
|
|
53
|
+
' if (size !== `${width} by ${height}`) throw new Error(`The window is ${size}.`);',
|
|
54
|
+
'});',
|
|
55
|
+
'',
|
|
56
|
+
].join('\n');
|
|
57
|
+
|
|
58
|
+
const replacing = [
|
|
59
|
+
`const { setWorldConstructor, World, Then } = require(${JSON.stringify(cucumber)});`,
|
|
60
|
+
`const playwright = require(${JSON.stringify(path.join(ROOT, 'node_modules', 'playwright'))});`,
|
|
61
|
+
'class OwnWorld extends World {',
|
|
62
|
+
' async openBrowser() {',
|
|
63
|
+
' this.playwrightBrowser = await playwright.chromium.launch();',
|
|
64
|
+
' this.context = await this.playwrightBrowser.newContext();',
|
|
65
|
+
' this.page = await this.context.newPage();',
|
|
66
|
+
' }',
|
|
67
|
+
'}',
|
|
68
|
+
'setWorldConstructor(OwnWorld);',
|
|
69
|
+
'',
|
|
70
|
+
].join('\n');
|
|
71
|
+
|
|
72
|
+
function run(name, support, lines, base) {
|
|
73
|
+
const dir = path.join(tmp, name);
|
|
74
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
75
|
+
const steps = path.join(dir, 'world.steps.js');
|
|
76
|
+
const feature = path.join(dir, `${name}.feature`);
|
|
77
|
+
const report = path.join(dir, 'report.json');
|
|
78
|
+
const config = path.join(dir, 'cucumber.js');
|
|
79
|
+
fs.writeFileSync(steps, support);
|
|
80
|
+
fs.writeFileSync(feature, lines.join('\n') + '\n');
|
|
81
|
+
const world = JSON.parse(JSON.stringify(defaults.worldParameters));
|
|
82
|
+
world.launchUrl = base;
|
|
83
|
+
fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
|
|
84
|
+
requireModule: defaults.requireModule,
|
|
85
|
+
require: defaults.require.concat([steps]),
|
|
86
|
+
paths: [feature],
|
|
87
|
+
format: [`json:${report}`],
|
|
88
|
+
worldParameters: world,
|
|
89
|
+
}) + ' };');
|
|
90
|
+
const env = Object.assign({ SLOW_MO: '0' }, process.env, {
|
|
91
|
+
LAUNCH_URL: base,
|
|
92
|
+
WEBSHIP_REPORT_DISABLE: '1',
|
|
93
|
+
WEBSHIP_VIDEO: 'off',
|
|
94
|
+
WEBSHIP_JS_ERROR_MODE: 'off',
|
|
95
|
+
WEBSHIP_SCREENSHOT_ON_FAILED: 'false',
|
|
96
|
+
WEBSHIP_AUTO_SETTLE: 'off',
|
|
97
|
+
});
|
|
98
|
+
return new Promise((resolve) => {
|
|
99
|
+
const child = spawn(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
|
|
100
|
+
cwd: ROOT,
|
|
101
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
102
|
+
env,
|
|
103
|
+
});
|
|
104
|
+
let output = '';
|
|
105
|
+
child.stdout.on('data', (chunk) => { output += chunk; });
|
|
106
|
+
child.stderr.on('data', (chunk) => { output += chunk; });
|
|
107
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), 120000);
|
|
108
|
+
child.on('exit', () => {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
const results = [];
|
|
111
|
+
if (fs.existsSync(report) && fs.readFileSync(report, 'utf8').trim()) {
|
|
112
|
+
for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
|
|
113
|
+
for (const scenario of f.elements || []) {
|
|
114
|
+
const failed = (scenario.steps || []).find((step) => step.result && step.result.status !== 'passed');
|
|
115
|
+
results.push({ name: scenario.name, failed });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
resolve({ output: output.replace(/\u001b\[[0-9;]*m/g, ''), results });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const server = http.createServer((req, res) => {
|
|
125
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
126
|
+
res.end(PAGE);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
server.listen(0, '127.0.0.1', async () => {
|
|
130
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
131
|
+
const problems = [];
|
|
132
|
+
// The auto-settle is off in both runs: only this.smartSettle() waits.
|
|
133
|
+
const extended = await run('extending', extending, [
|
|
134
|
+
'Feature: A project World that extends PlaywrightWorld',
|
|
135
|
+
'',
|
|
136
|
+
' @mobile',
|
|
137
|
+
' Scenario: The extended World keeps the viewport and settles a project step',
|
|
138
|
+
' Given I am on "/"',
|
|
139
|
+
' Then the World should be the project one',
|
|
140
|
+
' And the window should be 375 by 667',
|
|
141
|
+
' When I put one item in the cart',
|
|
142
|
+
' Then I should see "1 item" in the "#cart" element',
|
|
143
|
+
], base);
|
|
144
|
+
if (extended.results.length !== 1) {
|
|
145
|
+
problems.push(`The extended World ran ${extended.results.length} scenarios, not 1:\n${extended.output.slice(-1200)}`);
|
|
146
|
+
} else if (extended.results[0].failed) {
|
|
147
|
+
const f = extended.results[0].failed;
|
|
148
|
+
problems.push(`The extended World: ${f.hidden ? 'a hook' : `"${f.keyword}${f.name}"`} ${f.result.status}: ${String(f.result.error_message || '').replace(/\u001b\[[0-9;]*m/g, '').split('\n')[0]}`);
|
|
149
|
+
}
|
|
150
|
+
const replaced = await run('replacing', replacing, [
|
|
151
|
+
'Feature: A World of its own',
|
|
152
|
+
'',
|
|
153
|
+
' Scenario: A World set by the project alone',
|
|
154
|
+
' Given I am on "/"',
|
|
155
|
+
' Then I should see "World"',
|
|
156
|
+
], base);
|
|
157
|
+
if (!/\[webship-js\] The World of this run does not extend PlaywrightWorld/.test(replaced.output)) {
|
|
158
|
+
problems.push('A World that replaces PlaywrightWorld ran without a word about what it loses.');
|
|
159
|
+
}
|
|
160
|
+
server.close();
|
|
161
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
162
|
+
if (problems.length) {
|
|
163
|
+
console.error('Extending the World:\n - ' + problems.join('\n - '));
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
console.log('Extending the World: an extended PlaywrightWorld keeps the viewport tag and this.smartSettle(); a replacing World is reported.');
|
|
167
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Feature: The API base URL belongs to its scenario
|
|
2
|
+
As a tester,
|
|
3
|
+
I want each scenario to send its API requests where it says
|
|
4
|
+
So that a scenario gives the same result alone and among others
|
|
5
|
+
|
|
6
|
+
Scenario: A path is joined to the base URL the scenario set
|
|
7
|
+
Given the API base URL is "/"
|
|
8
|
+
When I send a GET request to "/example-api.json"
|
|
9
|
+
Then the API response code should be 200
|
|
10
|
+
And the JSON response should have "data.0.type" equal to "articles"
|
|
11
|
+
|
|
12
|
+
Scenario: A base URL with a path of its own
|
|
13
|
+
Given the API base URL is "/examples-that-do-not-exist"
|
|
14
|
+
When I send a GET request to "/example-api.json"
|
|
15
|
+
Then the API response code should be 404
|
|
16
|
+
|
|
17
|
+
Scenario: A whole URL is sent as written, with no base URL
|
|
18
|
+
When I send a GET request to "http://localhost:8080/example-api.json"
|
|
19
|
+
Then the API response code should be 200
|
|
20
|
+
And the JSON response should have "included.0.attributes.name" equal to "John"
|
|
21
|
+
|
|
22
|
+
Scenario: A whole URL is sent as written, past the base URL
|
|
23
|
+
Given the API base URL is "https://api.example.invalid"
|
|
24
|
+
When I send a GET request to "http://localhost:8080/example-api.json"
|
|
25
|
+
Then the API response code should be 200
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Feature: The API form data step sends each field whole
|
|
2
|
+
As a tester,
|
|
3
|
+
I want a form field whose value contains "=" to reach the server as written
|
|
4
|
+
So that a redirect, a query string or a base64 token is not cut
|
|
5
|
+
|
|
6
|
+
Scenario: A value that contains "=" is sent whole
|
|
7
|
+
Given the API base URL is "https://jsonplaceholder.typicode.com"
|
|
8
|
+
When I send a POST request to "/posts" with form data:
|
|
9
|
+
"""
|
|
10
|
+
redirect=/search?q=shoes
|
|
11
|
+
token=YWJj==
|
|
12
|
+
|
|
13
|
+
title=Form data
|
|
14
|
+
"""
|
|
15
|
+
Then the API response code should be 201
|
|
16
|
+
And the JSON response should have "redirect" equal to "/search?q=shoes"
|
|
17
|
+
And the JSON response should have "token" equal to "YWJj=="
|
|
18
|
+
And the JSON response should have "title" equal to "Form data"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Feature: The API JSON property steps take a dot path or a JSON Pointer
|
|
2
|
+
As a tester,
|
|
3
|
+
I want to name a property of the response the way the YAML steps do too
|
|
4
|
+
So that a path written either way reads the same property
|
|
5
|
+
|
|
6
|
+
Background:
|
|
7
|
+
Given the API base URL is "/"
|
|
8
|
+
When I send a GET request to "/example-api.json"
|
|
9
|
+
|
|
10
|
+
Scenario: A dot path, with an index written either way
|
|
11
|
+
Then the JSON response should have "data.0.type" equal to "articles"
|
|
12
|
+
And the JSON response should have "data[0].attributes.title" equal to "JSON:API paints my bikeshed!"
|
|
13
|
+
And the JSON property "included.0.attributes.age" should be 80
|
|
14
|
+
|
|
15
|
+
Scenario: A JSON Pointer
|
|
16
|
+
Then the JSON response should have "/data/0/type" equal to "articles"
|
|
17
|
+
And the API response should have "/included/0/attributes/name" equal to "John"
|
|
18
|
+
And the JSON property "/included/0/attributes/age" should be 80
|
|
19
|
+
And the JSON response should have property "/data/0/relationships/author"
|
|
20
|
+
And the JSON response should not have property "/data/0/password"
|
|
21
|
+
|
|
22
|
+
Scenario: A JSON Pointer to a property that is there is not taken for a missing key
|
|
23
|
+
Then the API response should contain property "/data/0/type"
|
|
24
|
+
And the JSON response should not have property "/data/0/discount"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Feature: The API response text checks read the response the same way in both polarities
|
|
2
|
+
As a tester,
|
|
3
|
+
I want "should contain" and "should not contain" to agree on letter case and placeholders
|
|
4
|
+
So that a negative check fails on the text a positive check finds
|
|
5
|
+
|
|
6
|
+
Background:
|
|
7
|
+
Given the API base URL is "/"
|
|
8
|
+
When I send a GET request to "/example-api.json"
|
|
9
|
+
|
|
10
|
+
Scenario: Letter case does not matter to either polarity
|
|
11
|
+
Then the API response code should be 200
|
|
12
|
+
And the API response should contain "JSON:API paints my bikeshed!"
|
|
13
|
+
And the API response should contain "json:api paints my bikeshed!"
|
|
14
|
+
And the API response should not contain "Jane"
|
|
15
|
+
And the API response should not contain "jane"
|
|
16
|
+
|
|
17
|
+
Scenario: A placeholder in the expected text is replaced
|
|
18
|
+
Given I set placeholder "{{author}}" to "John"
|
|
19
|
+
And I set placeholder "{{nobody}}" to "Jane"
|
|
20
|
+
Then the API response should contain "{{author}}"
|
|
21
|
+
And the API response should not contain "{{nobody}}"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Feature: The API steps tell whether a response header is there
|
|
2
|
+
As a tester,
|
|
3
|
+
I want to check that an API response has a header, or has not, whatever its value
|
|
4
|
+
So that a missing ETag or a leaking server header is caught
|
|
5
|
+
|
|
6
|
+
Background:
|
|
7
|
+
Given the API base URL is "/"
|
|
8
|
+
When I send a GET request to "/example-api.json"
|
|
9
|
+
|
|
10
|
+
Scenario: Headers the response has
|
|
11
|
+
Then the API response should contain the header "ETag"
|
|
12
|
+
And the API response should contain the header "content-type"
|
|
13
|
+
And API response should contain the header "Accept-Ranges"
|
|
14
|
+
|
|
15
|
+
Scenario: Headers the response has not
|
|
16
|
+
Then the API response should not contain the header "X-Powered-By"
|
|
17
|
+
And the API response should not contain the header "Set-Cookie"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Feature: The API response header steps tell "should be" from "should contain"
|
|
2
|
+
As a tester,
|
|
3
|
+
I want "should be" to compare the whole value of a header
|
|
4
|
+
So that a wrong value that contains the right text does not pass
|
|
5
|
+
|
|
6
|
+
Background:
|
|
7
|
+
Given the API base URL is "/"
|
|
8
|
+
When I send a GET request to "/example-api.json"
|
|
9
|
+
|
|
10
|
+
Scenario: The whole value of a header
|
|
11
|
+
Then the response header "Content-Type" should be "application/json; charset=UTF-8"
|
|
12
|
+
And the header "content-type" should be "application/json; charset=UTF-8"
|
|
13
|
+
And the response header "Accept-Ranges" should be "bytes"
|
|
14
|
+
|
|
15
|
+
Scenario: A part of the value of a header
|
|
16
|
+
Then the response header "Content-Type" should contain "application/json"
|
|
17
|
+
And the header "CONTENT-TYPE" should contain "charset"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Feature: A value of an API response carried into later requests
|
|
2
|
+
As a tester,
|
|
3
|
+
I want to save a property of a response as a placeholder
|
|
4
|
+
So that a token or an id the API returned goes into the next requests
|
|
5
|
+
|
|
6
|
+
Scenario: A property saved as a placeholder, in a URL and a body
|
|
7
|
+
Given the API base URL is "https://jsonplaceholder.typicode.com"
|
|
8
|
+
When I send a GET request to "/posts/1"
|
|
9
|
+
Then the API response code should be 200
|
|
10
|
+
When I save the JSON property "userId" as placeholder "{{author}}"
|
|
11
|
+
And we save the JSON property "title" as placeholder "{{title}}"
|
|
12
|
+
And I send a GET request to "/users/{{author}}"
|
|
13
|
+
Then the API response code should be 200
|
|
14
|
+
And the JSON response should have "id" equal to 1
|
|
15
|
+
When I send a POST request to "/posts" with body:
|
|
16
|
+
"""
|
|
17
|
+
{"title": "{{title}}", "userId": {{author}}}
|
|
18
|
+
"""
|
|
19
|
+
Then the API response code should be 201
|
|
20
|
+
And the JSON response should have "userId" equal to 1
|
|
21
|
+
And the API response should contain "{{title}}"
|
|
22
|
+
|
|
23
|
+
Scenario: A header set before its placeholder has a value gets it when the request is sent
|
|
24
|
+
Given the API base URL is "/"
|
|
25
|
+
And I set the header "Range" to "bytes=0-{{last}}"
|
|
26
|
+
And I set placeholder "{{last}}" to "9"
|
|
27
|
+
When I send a GET request to "/example-api.json"
|
|
28
|
+
Then the API response code should be 206
|
|
29
|
+
|
|
30
|
+
Scenario: A value with characters that mean something in a pattern
|
|
31
|
+
Given I set placeholder "{{price}}" to "$1.50 (incl. $&)"
|
|
32
|
+
And the API base URL is "https://jsonplaceholder.typicode.com"
|
|
33
|
+
When I send a POST request to "/posts" with body:
|
|
34
|
+
"""
|
|
35
|
+
{"title": "{{price}}", "userId": 1}
|
|
36
|
+
"""
|
|
37
|
+
Then the JSON response should have "title" equal to "$1.50 (incl. $&)"
|
|
@@ -139,7 +139,7 @@ Feature: API Step Definitions Individual
|
|
|
139
139
|
Scenario: Header Assertions
|
|
140
140
|
Given the API base URL is "https://jsonplaceholder.typicode.com"
|
|
141
141
|
When I send a GET request to "/posts/1"
|
|
142
|
-
Then the response header "Content-Type" should be "application/json"
|
|
142
|
+
Then the response header "Content-Type" should be "application/json; charset=utf-8"
|
|
143
143
|
# Alternative syntax:
|
|
144
144
|
# Then the header "Cache-Control" should contain "no-cache"
|
|
145
145
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Feature: The API headers and body tables send every row
|
|
2
|
+
As a tester,
|
|
3
|
+
I want the first row of a headers or body table to be sent like the others
|
|
4
|
+
So that no header and no field is silently left out
|
|
5
|
+
|
|
6
|
+
Scenario: The first row of the headers table is sent
|
|
7
|
+
Given the API base URL is "/"
|
|
8
|
+
And I set the following headers:
|
|
9
|
+
| Range | bytes=0-9 |
|
|
10
|
+
| Accept | application/json |
|
|
11
|
+
When I send a GET request to "/example-api.json"
|
|
12
|
+
Then the API response code should be 206
|
|
13
|
+
|
|
14
|
+
Scenario: A headers table that starts with a row naming its columns
|
|
15
|
+
Given the API base URL is "/"
|
|
16
|
+
And I set the following headers:
|
|
17
|
+
| header | value |
|
|
18
|
+
| Range | bytes=0-9 |
|
|
19
|
+
When I send a GET request to "/example-api.json"
|
|
20
|
+
Then the API response code should be 206
|
|
21
|
+
|
|
22
|
+
Scenario: The first row of the request body table is sent
|
|
23
|
+
Given the API base URL is "https://jsonplaceholder.typicode.com"
|
|
24
|
+
And I set the request body with:
|
|
25
|
+
| title | First row |
|
|
26
|
+
| userId | 1 |
|
|
27
|
+
When I send a POST request to "/posts"
|
|
28
|
+
Then the API response code should be 201
|
|
29
|
+
And the JSON response should have "title" equal to "First row"
|
|
30
|
+
And the JSON response should have "userId" equal to 1
|
|
31
|
+
|
|
32
|
+
Scenario: A request body table that starts with a row naming its columns
|
|
33
|
+
Given the API base URL is "https://jsonplaceholder.typicode.com"
|
|
34
|
+
And I set the request body with:
|
|
35
|
+
| field | value |
|
|
36
|
+
| title | Second row |
|
|
37
|
+
When I send a POST request to "/posts"
|
|
38
|
+
Then the API response code should be 201
|
|
39
|
+
And the JSON response should have "title" equal to "Second row"
|
|
40
|
+
And the JSON response should not have property "field"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Feature: One breakpoint registry for every step and tag
|
|
2
|
+
The viewing-the-site step, the set-the-viewport step and the tags for
|
|
3
|
+
mobile and desktop read the same named sizes: the built-in names, the
|
|
4
|
+
project's worldParameters.selectors.breakpoints,
|
|
5
|
+
WEBSHIP_SELECTORS_BREAKPOINTS and the names a scenario adds.
|
|
6
|
+
tests/check-breakpoints.js covers the environment variable and the
|
|
7
|
+
breakpoint marked default.
|
|
8
|
+
|
|
9
|
+
Scenario: The viewing-the-site step knows the built-in mobile, tablet and desktop
|
|
10
|
+
Given I am on "/viewport-size.html"
|
|
11
|
+
When I am viewing the site on a "mobile" screen
|
|
12
|
+
Then "#viewport-size" should have text "Viewport is 375 by 667"
|
|
13
|
+
When I am viewing the site on a tablet device
|
|
14
|
+
Then "#viewport-size" should have text "Viewport is 768 by 1024"
|
|
15
|
+
When I am viewing the site on a "desktop" screen
|
|
16
|
+
Then "#viewport-size" should have text "Viewport is 1200 by 900"
|
|
17
|
+
|
|
18
|
+
Scenario: A breakpoint a scenario adds reaches the viewing-the-site step
|
|
19
|
+
Given I am on "/viewport-size.html"
|
|
20
|
+
And the following responsive breakpoints:
|
|
21
|
+
| pocket | 320 | 480 |
|
|
22
|
+
When I am viewing the site on a "pocket" screen
|
|
23
|
+
Then "#viewport-size" should have text "Viewport is 320 by 480"
|
|
24
|
+
When I set the viewport to the "xxl" breakpoint
|
|
25
|
+
Then "#viewport-size" should have text "Viewport is 1400 by 900"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Feature: Toggle switches and custom checkboxes
|
|
2
|
+
As a tester
|
|
3
|
+
I want to check and uncheck a box the way a person does
|
|
4
|
+
So that a slider drawn over the checkbox, or a box drawn by its label, does not stop the step
|
|
5
|
+
|
|
6
|
+
Scenario: Check a switch whose slider covers its checkbox
|
|
7
|
+
Given I am on "/check-switch.html"
|
|
8
|
+
When I check "Analytics cookies"
|
|
9
|
+
Then the checkbox "Analytics cookies" should be checked
|
|
10
|
+
|
|
11
|
+
Scenario: Uncheck a switch that is on
|
|
12
|
+
Given I am on "/check-switch.html"
|
|
13
|
+
When I uncheck "Marketing cookies"
|
|
14
|
+
Then the checkbox "Marketing cookies" should not be checked
|
|
15
|
+
|
|
16
|
+
Scenario: Check and uncheck a switch named by its checkbox
|
|
17
|
+
Given I am on "/check-switch.html"
|
|
18
|
+
When I check the checkbox "#analytics"
|
|
19
|
+
Then the checkbox "#analytics" should be checked
|
|
20
|
+
When I uncheck the checkbox "#analytics"
|
|
21
|
+
Then the checkbox "#analytics" should not be checked
|
|
22
|
+
|
|
23
|
+
Scenario: Check a checkbox whose input is hidden and whose label draws the box
|
|
24
|
+
Given I am on "/check-switch.html"
|
|
25
|
+
When I check "Remember this device"
|
|
26
|
+
Then the checkbox "Remember this device" should be checked
|
|
27
|
+
When I uncheck "Remember this device"
|
|
28
|
+
Then the checkbox "Remember this device" should not be checked
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Feature: Checkboxes, radio buttons and fields named by their label, name or id
|
|
2
|
+
As a tester,
|
|
3
|
+
I want the checkbox, radio button and field steps to find a control the way the check steps do,
|
|
4
|
+
so that a scenario names a control by what the form shows.
|
|
5
|
+
|
|
6
|
+
Scenario: The state of a checkbox named by its label, its name or its id
|
|
7
|
+
Given I am on "/choice-controls.html"
|
|
8
|
+
Then the "Newsletter" checkbox should be checked
|
|
9
|
+
And the "#opt-news" checkbox should be checked
|
|
10
|
+
And the checkbox "terms" should not be checked
|
|
11
|
+
And the "opt-terms" checkbox is not checked
|
|
12
|
+
And the checkbox "Accept the terms" is not checked
|
|
13
|
+
|
|
14
|
+
Scenario: Check and uncheck a checkbox named by its label or its name
|
|
15
|
+
Given I am on "/choice-controls.html"
|
|
16
|
+
When I check the checkbox "Accept the terms"
|
|
17
|
+
And I uncheck the checkbox "newsletter"
|
|
18
|
+
Then the checkbox "terms" is checked
|
|
19
|
+
And the "Newsletter" checkbox should not be checked
|
|
20
|
+
|
|
21
|
+
Scenario: The state of a radio button named by its label, its id or its value
|
|
22
|
+
Given I am on "/choice-controls.html"
|
|
23
|
+
Then the radio button "Premium" should be selected
|
|
24
|
+
And the "plan-basic" radio button is not selected
|
|
25
|
+
And the radio button "basic" should not be selected
|
|
26
|
+
When I choose the radio button "Basic"
|
|
27
|
+
Then the radio button "basic" should be selected
|
|
28
|
+
And the "Premium" radio button is not selected
|
|
29
|
+
|
|
30
|
+
Scenario: Fill a field named by its label or its name
|
|
31
|
+
Given I am on "/choice-controls.html"
|
|
32
|
+
When I fill in the field "City" with "Amman"
|
|
33
|
+
And I fill in the field "nickname" with "Ali"
|
|
34
|
+
Then "#city" should have value "Amman"
|
|
35
|
+
And "#nick" should have value "Ali"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Feature: Links and buttons whose markup puts white space around their text
|
|
2
|
+
As a tester
|
|
3
|
+
I want to click a link and press a button by the text a person reads
|
|
4
|
+
So that the indentation of a template does not hide them from the steps
|
|
5
|
+
|
|
6
|
+
Scenario: Click a link whose text sits on a line of its own
|
|
7
|
+
Given I am on "/click-whitespace.html"
|
|
8
|
+
When I click "Products"
|
|
9
|
+
Then the url should match "#products$"
|
|
10
|
+
|
|
11
|
+
Scenario: Click a link whose text breaks across lines
|
|
12
|
+
Given I am on "/click-whitespace.html"
|
|
13
|
+
When I click "About us"
|
|
14
|
+
Then the url should match "#about-us$"
|
|
15
|
+
|
|
16
|
+
Scenario: Press a button whose label is indented
|
|
17
|
+
Given I am on "/click-whitespace.html"
|
|
18
|
+
When I press "Save draft"
|
|
19
|
+
Then I should see "The draft was saved."
|
|
20
|
+
|
|
21
|
+
Scenario: Click a link of a table row whose text is indented
|
|
22
|
+
Given I am on "/click-whitespace.html"
|
|
23
|
+
When I click "Edit" in the "Order 1042" row
|
|
24
|
+
Then the url should match "#order-1042$"
|
|
25
|
+
|
|
26
|
+
Scenario: Follow a link whose text sits on a line of its own
|
|
27
|
+
Given I am on "/click-whitespace.html"
|
|
28
|
+
When I follow "Products"
|
|
29
|
+
Then the url should match "#products$"
|
|
@@ -130,7 +130,7 @@ Feature: Complete API Testing Examples - All Step Definitions
|
|
|
130
130
|
Scenario: Response Header Validation
|
|
131
131
|
When I send a GET request to "/posts/1"
|
|
132
132
|
Then the API response code should be 200
|
|
133
|
-
And the response header "Content-Type" should be "application/json"
|
|
133
|
+
And the response header "Content-Type" should be "application/json; charset=utf-8"
|
|
134
134
|
|
|
135
135
|
Scenario: Placeholder Usage
|
|
136
136
|
Given I set placeholder "{{postId}}" to "1"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Feature: Find the inputs of a datetime field by its own label
|
|
2
|
+
As a tester,
|
|
3
|
+
I want a datetime step to fill the inputs of the field it names and no other,
|
|
4
|
+
so that a form with several date fields is filled in the right places.
|
|
5
|
+
|
|
6
|
+
Scenario: A label that contains the text of another one is not taken for it
|
|
7
|
+
Given I am on "/datetime-fields.html"
|
|
8
|
+
When I fill in the date part of the datetime field "Start" with "2026-05-08"
|
|
9
|
+
Then "#start-date" should have value "2026-05-08"
|
|
10
|
+
And "#restart-date" should have value ""
|
|
11
|
+
|
|
12
|
+
Scenario: Two fields in one paragraph
|
|
13
|
+
Given I am on "/datetime-fields.html"
|
|
14
|
+
When I fill in the datetime field "Closing" with date "2026-06-30" and time "18:00"
|
|
15
|
+
And I fill in the date part of the datetime field "Opening" with "2026-06-01"
|
|
16
|
+
Then "#closing-date" should have value "2026-06-30"
|
|
17
|
+
And "#closing-time" should have value "18:00"
|
|
18
|
+
And "#opening-date" should have value "2026-06-01"
|
|
19
|
+
|
|
20
|
+
Scenario: A label alone in its wrapper
|
|
21
|
+
Given I am on "/datetime-fields.html"
|
|
22
|
+
When I fill in the datetime field "Arrival" with date "2026-07-04" and time "08:30"
|
|
23
|
+
Then "#arrival-date" should have value "2026-07-04"
|
|
24
|
+
And "#arrival-time" should have value "08:30"
|
|
25
|
+
And "#leaving-date" should have value ""
|
|
26
|
+
And "#leaving-time" should have value ""
|
|
27
|
+
When I fill in the time part of the datetime field "Leaving" with "20:15"
|
|
28
|
+
Then "#leaving-time" should have value "20:15"
|
|
29
|
+
And "#arrival-time" should have value "08:30"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Feature: An element named by its text, next to the same element named by a selector
|
|
2
|
+
`I should see a "…" element` reads its argument as the exact text of an
|
|
3
|
+
element or of a label; the web-first steps read a CSS selector.
|
|
4
|
+
|
|
5
|
+
Scenario: The text of an element and its selector
|
|
6
|
+
Given I am on "/element-selector-hint.html"
|
|
7
|
+
Then I should see a "First news item" element
|
|
8
|
+
And ".news-item" should be visible
|
|
9
|
+
And "header" should be visible
|
|
10
|
+
|
|
11
|
+
Scenario: A selector given to the negative is read as a text
|
|
12
|
+
Given I am on "/element-selector-hint.html"
|
|
13
|
+
Then I should not see a ".news-item" element
|
|
14
|
+
And I should not see a "Third news item" element
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Feature: The state of a field
|
|
2
|
+
As a tester,
|
|
3
|
+
I want to check that a field is enabled, disabled, editable or read-only,
|
|
4
|
+
so that a form shows the right fields as locked.
|
|
5
|
+
|
|
6
|
+
Scenario: An enabled field that can be edited
|
|
7
|
+
Given I am on "/field-states.html"
|
|
8
|
+
Then the field "Username" should have "enabled" state
|
|
9
|
+
And the field "Username" should have "editable" state
|
|
10
|
+
|
|
11
|
+
Scenario: A disabled field
|
|
12
|
+
Given I am on "/field-states.html"
|
|
13
|
+
Then the field "Account ID" should have "disabled" state
|
|
14
|
+
And the field "account_id" should have "disabled" state
|
|
15
|
+
|
|
16
|
+
Scenario: A read-only field is enabled but cannot be edited
|
|
17
|
+
Given I am on "/field-states.html"
|
|
18
|
+
Then the field "Reference" should have "read-only" state
|
|
19
|
+
And the field "Reference" should have "readonly" state
|
|
20
|
+
And the field "Reference" should have "enabled" state
|
|
21
|
+
And the field "Notes" should have "read-only" state
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Feature: Fill in a field with an empty value
|
|
2
|
+
As a tester,
|
|
3
|
+
I want to fill a field with "" in every form of the fill step,
|
|
4
|
+
so that a scenario can clear a field the way it fills one.
|
|
5
|
+
|
|
6
|
+
Scenario: Fill a field with an empty value by its label
|
|
7
|
+
Given I am on "/fill-in-empty.html"
|
|
8
|
+
Then the field "title" should not be empty
|
|
9
|
+
When I fill in "Title" with ""
|
|
10
|
+
Then the field "title" should be empty
|
|
11
|
+
|
|
12
|
+
Scenario: Fill in an empty value for a field by its label
|
|
13
|
+
Given I am on "/fill-in-empty.html"
|
|
14
|
+
Then the field "summary" should not be empty
|
|
15
|
+
When I fill in "" for "Summary"
|
|
16
|
+
Then the field "summary" should be empty
|
|
17
|
+
|
|
18
|
+
Scenario: Fill a field with an empty value by its placeholder
|
|
19
|
+
Given I am on "/fill-in-empty.html"
|
|
20
|
+
When I fill in "Comma separated" with ""
|
|
21
|
+
Then the field "keywords" should be empty
|
|
22
|
+
|
|
23
|
+
Scenario: Fill a field with an empty value by attribute
|
|
24
|
+
Given I am on "/fill-in-empty.html"
|
|
25
|
+
When I fill in "#title" with "" by attr
|
|
26
|
+
And I fill in "keywords-field" with "" by its "class" attribute
|
|
27
|
+
Then the field "title" should be empty
|
|
28
|
+
And the field "keywords" should be empty
|
|
29
|
+
|
|
30
|
+
Scenario: Fill in an empty value for a field by attribute
|
|
31
|
+
Given I am on "/fill-in-empty.html"
|
|
32
|
+
When I fill in "" for "summary" by its "name" attribute
|
|
33
|
+
Then the field "summary" should be empty
|
|
34
|
+
|
|
35
|
+
Scenario: An empty cell of the fill table empties its field
|
|
36
|
+
Given I am on "/fill-in-empty.html"
|
|
37
|
+
When I fill in the following:
|
|
38
|
+
| Title | |
|
|
39
|
+
| Summary | New words |
|
|
40
|
+
Then the field "title" should be empty
|
|
41
|
+
And the field "summary" should not be empty
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Feature: Fill a field that can be filled, next to fields that cannot
|
|
2
|
+
As a tester,
|
|
3
|
+
I want the fill steps to fill a visible, enabled field as before,
|
|
4
|
+
so that the plain messages for the other fields change nothing else.
|
|
5
|
+
|
|
6
|
+
Scenario: Fill a visible field by its label, its placeholder and by attribute
|
|
7
|
+
Given I am on "/fill-unreachable.html"
|
|
8
|
+
When I fill in "Your name" with "Alice"
|
|
9
|
+
Then "#visible-name" should have value "Alice"
|
|
10
|
+
When I fill in "Full name" with "Bob"
|
|
11
|
+
Then "#visible-name" should have value "Bob"
|
|
12
|
+
When I fill in "visible_name" with "Carol" by its "name" attribute
|
|
13
|
+
Then "#visible-name" should have value "Carol"
|