playwright-cucumber-ts-steps 1.3.0 → 1.3.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.
- package/dist/backend/actions/click.d.ts +84 -0
- package/dist/backend/actions/click.d.ts.map +1 -1
- package/dist/backend/actions/click.js +167 -17
- package/dist/backend/actions/form.d.ts +6 -0
- package/dist/backend/actions/form.d.ts.map +1 -1
- package/dist/backend/actions/form.js +17 -1
- package/dist/backend/actions/formTable.js +1 -1
- package/dist/backend/actions/frames.js +3 -3
- package/dist/backend/actions/index.d.ts +2 -0
- package/dist/backend/actions/index.d.ts.map +1 -1
- package/dist/backend/actions/index.js +2 -0
- package/dist/backend/actions/inputs.js +18 -18
- package/dist/backend/actions/interactions.d.ts +14 -5
- package/dist/backend/actions/interactions.d.ts.map +1 -1
- package/dist/backend/actions/interactions.js +69 -13
- package/dist/backend/actions/keyboard.js +6 -6
- package/dist/backend/actions/misc.d.ts +8 -2
- package/dist/backend/actions/misc.d.ts.map +1 -1
- package/dist/backend/actions/misc.js +64 -16
- package/dist/backend/actions/mobile.js +7 -7
- package/dist/backend/actions/mouse.js +9 -9
- package/dist/backend/actions/navigation.js +5 -5
- package/dist/backend/actions/visual.d.ts +47 -0
- package/dist/backend/actions/visual.d.ts.map +1 -0
- package/dist/backend/actions/visual.js +97 -0
- package/dist/backend/actions/waits.d.ts +6 -0
- package/dist/backend/actions/waits.d.ts.map +1 -1
- package/dist/backend/actions/waits.js +18 -5
- package/dist/backend/api/assertions.js +3 -3
- package/dist/backend/api/mock.js +3 -3
- package/dist/backend/api/network.js +6 -6
- package/dist/backend/api/requests.js +4 -4
- package/dist/backend/assertions/document.d.ts +61 -0
- package/dist/backend/assertions/document.d.ts.map +1 -0
- package/dist/backend/assertions/document.js +166 -0
- package/dist/backend/assertions/elements.d.ts +163 -0
- package/dist/backend/assertions/elements.d.ts.map +1 -0
- package/dist/backend/assertions/elements.js +441 -0
- package/dist/backend/assertions/expectVisible.js +1 -1
- package/dist/backend/assertions/forms.d.ts +43 -0
- package/dist/backend/assertions/forms.d.ts.map +1 -0
- package/dist/backend/assertions/forms.js +126 -0
- package/dist/backend/assertions/index.d.ts +10 -0
- package/dist/backend/assertions/index.d.ts.map +1 -1
- package/dist/backend/assertions/index.js +10 -0
- package/dist/backend/assertions/pageState.js +4 -4
- package/dist/backend/assertions/storage.d.ts +67 -0
- package/dist/backend/assertions/storage.d.ts.map +1 -0
- package/dist/backend/assertions/storage.js +220 -0
- package/dist/backend/assertions/text.d.ts +103 -12
- package/dist/backend/assertions/text.d.ts.map +1 -1
- package/dist/backend/assertions/text.js +207 -28
- package/dist/backend/assertions/visibility.d.ts +18 -0
- package/dist/backend/assertions/visibility.d.ts.map +1 -1
- package/dist/backend/assertions/visibility.js +58 -12
- package/dist/backend/auth/index.js +2 -2
- package/dist/backend/db/steps.d.ts +2 -2
- package/dist/backend/db/steps.d.ts.map +1 -1
- package/dist/backend/db/steps.js +11 -11
- package/dist/backend/elements/alerts.js +3 -3
- package/dist/backend/elements/find.js +26 -24
- package/dist/backend/elements/forms.js +4 -4
- package/dist/backend/elements/frames.js +3 -3
- package/dist/backend/utils/fixtures.js +1 -1
- package/dist/backend/utils/resolver.d.ts +6 -0
- package/dist/backend/utils/resolver.d.ts.map +1 -0
- package/dist/backend/utils/resolver.js +19 -0
- package/dist/component/index.d.ts +3 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component/index.js +6 -0
- package/dist/component/runner.d.ts +18 -0
- package/dist/component/runner.d.ts.map +1 -0
- package/dist/component/runner.js +91 -0
- package/dist/core/runner.d.ts +1 -0
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +179 -124
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/metadata.json +564 -172
- package/package.json +4 -3
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.countElements = countElements;
|
|
4
|
+
exports.expectButtonNotVisible = expectButtonNotVisible;
|
|
5
|
+
exports.expectHeadingNotVisible = expectHeadingNotVisible;
|
|
6
|
+
exports.expectLabelNotVisible = expectLabelNotVisible;
|
|
7
|
+
exports.expectLinkNotVisible = expectLinkNotVisible;
|
|
8
|
+
exports.expectTestIdNotVisible = expectTestIdNotVisible;
|
|
9
|
+
exports.expectRoleNotVisible = expectRoleNotVisible;
|
|
10
|
+
exports.expectOptionNotVisible = expectOptionNotVisible;
|
|
11
|
+
exports.expectElementWithAttributeNotVisible = expectElementWithAttributeNotVisible;
|
|
12
|
+
exports.expectElementAttributeContains = expectElementAttributeContains;
|
|
13
|
+
exports.expectElementAttributeEquals = expectElementAttributeEquals;
|
|
14
|
+
exports.expectElementHasAttribute = expectElementHasAttribute;
|
|
15
|
+
exports.expectButtonVisible = expectButtonVisible;
|
|
16
|
+
exports.expectElementToHaveClassContaining = expectElementToHaveClassContaining;
|
|
17
|
+
exports.expectElementToNotContainText = expectElementToNotContainText;
|
|
18
|
+
exports.expectElementToHaveText = expectElementToHaveText;
|
|
19
|
+
exports.expectElementToContainText = expectElementToContainText;
|
|
20
|
+
exports.expectElementToHaveValue = expectElementToHaveValue;
|
|
21
|
+
exports.expectElementAttributeValue = expectElementAttributeValue;
|
|
22
|
+
exports.getElementBySelectorToBeVisible = getElementBySelectorToBeVisible;
|
|
23
|
+
exports.expectHeadingVisible = expectHeadingVisible;
|
|
24
|
+
exports.expectLabelVisible = expectLabelVisible;
|
|
25
|
+
exports.expectLinkVisible = expectLinkVisible;
|
|
26
|
+
exports.expectTestIdVisible = expectTestIdVisible;
|
|
27
|
+
exports.expectRoleVisible = expectRoleVisible;
|
|
28
|
+
exports.expectOptionVisible = expectOptionVisible;
|
|
29
|
+
exports.expectElementToHaveCount = expectElementToHaveCount;
|
|
30
|
+
exports.expectElementToBeHidden = expectElementToBeHidden;
|
|
31
|
+
//src/backend/assertions/elements.ts
|
|
32
|
+
const test_1 = require("@playwright/test");
|
|
33
|
+
const registry_1 = require("../../core/registry");
|
|
34
|
+
const fixtures_1 = require("../utils/fixtures");
|
|
35
|
+
const resolver_1 = require("../utils/resolver");
|
|
36
|
+
// ==================================================
|
|
37
|
+
// CORE FUNCTIONS
|
|
38
|
+
// ==================================================
|
|
39
|
+
/**
|
|
40
|
+
* Counts the number of elements matching the selector.
|
|
41
|
+
* Supports fixtures for reusable selectors.
|
|
42
|
+
* @example Then I count elements "li.item"
|
|
43
|
+
*/
|
|
44
|
+
async function countElements(page, selectorKey) {
|
|
45
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
46
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
47
|
+
const count = await page.locator(selector).count();
|
|
48
|
+
console.log(`🔢 Found ${count} elements matching "${selector}"`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Asserts that a button element does not exist or is not visible.
|
|
52
|
+
* Supports fixtures for reusable selectors.
|
|
53
|
+
* @example Then I do not see button element "nav.logoutBtn"
|
|
54
|
+
*/
|
|
55
|
+
async function expectButtonNotVisible(page, selectorKey) {
|
|
56
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
57
|
+
await (0, test_1.expect)(page.locator(selector)).toBeHidden();
|
|
58
|
+
console.log(`✅ Button "${selector}" is not visible or does not exist`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Asserts that a heading element does not exist or is not visible.
|
|
62
|
+
* Supports fixtures for reusable selectors.
|
|
63
|
+
* @example Then I do not see heading element "h1.main-title"
|
|
64
|
+
*/
|
|
65
|
+
async function expectHeadingNotVisible(page, selectorKey) {
|
|
66
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
67
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
68
|
+
const element = page.locator(selector);
|
|
69
|
+
const count = await element.count();
|
|
70
|
+
if (count > 0) {
|
|
71
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
72
|
+
}
|
|
73
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
74
|
+
console.log(`✅ Heading "${selector}" is not visible or does not exist`);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Asserts that a label element does not exist or is not visible.
|
|
78
|
+
* Supports fixtures for reusable selectors.
|
|
79
|
+
* @example Then I do not see label element "label.username-label"
|
|
80
|
+
*/
|
|
81
|
+
async function expectLabelNotVisible(page, selectorKey) {
|
|
82
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
83
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
84
|
+
const element = page.locator(selector);
|
|
85
|
+
const count = await element.count();
|
|
86
|
+
if (count > 0) {
|
|
87
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
88
|
+
}
|
|
89
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
90
|
+
console.log(`✅ Label "${selector}" is not visible or does not exist`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Asserts that a link element does not exist or is not visible.
|
|
94
|
+
* Supports fixtures for reusable selectors.
|
|
95
|
+
* @example Then I do not see link element "a.privacy-link"
|
|
96
|
+
*/
|
|
97
|
+
async function expectLinkNotVisible(page, selectorKey) {
|
|
98
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
99
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
100
|
+
const element = page.locator(selector);
|
|
101
|
+
const count = await element.count();
|
|
102
|
+
if (count > 0) {
|
|
103
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
104
|
+
}
|
|
105
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
106
|
+
console.log(`✅ Link "${selector}" is not visible or does not exist`);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Asserts that an element with a specific test ID does not exist or is not visible.
|
|
110
|
+
* Supports fixtures for reusable test IDs.
|
|
111
|
+
* @example Then I do not see testid element "data-testid=my-component"
|
|
112
|
+
*/
|
|
113
|
+
async function expectTestIdNotVisible(page, selectorKey) {
|
|
114
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
115
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
116
|
+
const element = page.locator(selector);
|
|
117
|
+
const count = await element.count();
|
|
118
|
+
if (count > 0) {
|
|
119
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
120
|
+
}
|
|
121
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
122
|
+
console.log(`✅ Test ID "${selector}" is not visible or does not exist`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Asserts that an element with a specific role does not exist or is not visible.
|
|
126
|
+
* Supports fixtures for reusable roles.
|
|
127
|
+
* @example Then I do not see role element "button"
|
|
128
|
+
*/
|
|
129
|
+
async function expectRoleNotVisible(page, roleKey) {
|
|
130
|
+
const roles = (0, fixtures_1.loadFixture)("roles.json");
|
|
131
|
+
const role = (0, fixtures_1.getFixtureValue)(roles, roleKey);
|
|
132
|
+
const element = page.getByRole(role);
|
|
133
|
+
const count = await element.count();
|
|
134
|
+
if (count > 0) {
|
|
135
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
136
|
+
}
|
|
137
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
138
|
+
console.log(`✅ Role "${role}" is not visible or does not exist`);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Asserts that an option element does not exist or is not visible.
|
|
142
|
+
* Supports fixtures for reusable selectors.
|
|
143
|
+
* @example Then I do not see option element "option[value='disabled']"
|
|
144
|
+
*/
|
|
145
|
+
async function expectOptionNotVisible(page, selectorKey) {
|
|
146
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
147
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
148
|
+
const element = page.locator(selector);
|
|
149
|
+
const count = await element.count();
|
|
150
|
+
if (count > 0) {
|
|
151
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
152
|
+
}
|
|
153
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
154
|
+
console.log(`✅ Option "${selector}" is not visible or does not exist`);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Asserts that an element with a specific attribute does not exist or is not visible.
|
|
158
|
+
* Supports fixtures for reusable selectors and attribute values.
|
|
159
|
+
* @example Then I do not see element with attribute "aria-hidden" having value "false"
|
|
160
|
+
*/
|
|
161
|
+
async function expectElementWithAttributeNotVisible(page, attrKey, valueKey) {
|
|
162
|
+
const attributes = (0, fixtures_1.loadFixture)("attributes.json");
|
|
163
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
164
|
+
const attr = (0, fixtures_1.getFixtureValue)(attributes, attrKey);
|
|
165
|
+
const value = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
166
|
+
const selector = `[${attr}="${value}"]`;
|
|
167
|
+
const element = page.locator(selector);
|
|
168
|
+
const count = await element.count();
|
|
169
|
+
if (count > 0) {
|
|
170
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
171
|
+
}
|
|
172
|
+
// If count is 0, the element doesn't exist, which satisfies "not see"
|
|
173
|
+
console.log(`✅ Element with attribute "${attr}" and value "${value}" is not visible or does not exist`);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Asserts that an element has an attribute containing the specified value.
|
|
177
|
+
* Supports fixtures for reusable selectors, attributes and values.
|
|
178
|
+
* @example Then I see element attribute "class" contains "active"
|
|
179
|
+
*/
|
|
180
|
+
async function expectElementAttributeContains(page, selectorKey, attrKey, valueKey) {
|
|
181
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
182
|
+
const attributes = (0, fixtures_1.loadFixture)("attributes.json");
|
|
183
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
184
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
185
|
+
const attr = (0, fixtures_1.getFixtureValue)(attributes, attrKey);
|
|
186
|
+
const value = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
187
|
+
const element = page.locator(selector);
|
|
188
|
+
const actualValue = await element.getAttribute(attr);
|
|
189
|
+
if (!actualValue || !actualValue.includes(value)) {
|
|
190
|
+
throw new Error(`Element "${selector}" attribute "${attr}" value "${actualValue}" does not contain "${value}"`);
|
|
191
|
+
}
|
|
192
|
+
console.log(`✅ Element "${selector}" attribute "${attr}" contains "${value}"`);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Asserts that an element has an attribute equal to the specified value.
|
|
196
|
+
* Supports fixtures for reusable selectors, attributes and values.
|
|
197
|
+
* @example Then I see element attribute "class" equals "btn-primary"
|
|
198
|
+
*/
|
|
199
|
+
async function expectElementAttributeEquals(page, selectorKey, attrKey, valueKey) {
|
|
200
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
201
|
+
const attributes = (0, fixtures_1.loadFixture)("attributes.json");
|
|
202
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
203
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
204
|
+
const attr = (0, fixtures_1.getFixtureValue)(attributes, attrKey);
|
|
205
|
+
const value = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
206
|
+
const element = page.locator(selector);
|
|
207
|
+
const actualValue = await element.getAttribute(attr);
|
|
208
|
+
if (actualValue !== value) {
|
|
209
|
+
throw new Error(`Element "${selector}" attribute "${attr}" value "${actualValue}" does not equal "${value}"`);
|
|
210
|
+
}
|
|
211
|
+
console.log(`✅ Element "${selector}" attribute "${attr}" equals "${value}"`);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Asserts that an element has a specific attribute.
|
|
215
|
+
* Supports fixtures for reusable selectors and attributes.
|
|
216
|
+
* @example Then I see element has attribute "aria-label"
|
|
217
|
+
*/
|
|
218
|
+
async function expectElementHasAttribute(page, selectorKey, attrKey) {
|
|
219
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
220
|
+
const attributes = (0, fixtures_1.loadFixture)("attributes.json");
|
|
221
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
222
|
+
const attr = (0, fixtures_1.getFixtureValue)(attributes, attrKey);
|
|
223
|
+
const element = page.locator(selector);
|
|
224
|
+
const hasAttribute = await element.getAttribute(attr) !== null;
|
|
225
|
+
if (!hasAttribute) {
|
|
226
|
+
throw new Error(`Element "${selector}" does not have attribute "${attr}"`);
|
|
227
|
+
}
|
|
228
|
+
console.log(`✅ Element "${selector}" has attribute "${attr}"`);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Asserts that a button element exists and is visible.
|
|
232
|
+
* Supports fixtures for reusable selectors.
|
|
233
|
+
* @example Then I see button element "nav.loginBtn"
|
|
234
|
+
*/
|
|
235
|
+
async function expectButtonVisible(page, selectorKey) {
|
|
236
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
237
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
238
|
+
console.log(`✅ Button "${selector}" is visible`);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Gets an element by selector and asserts it has a class containing the specified text.
|
|
242
|
+
* @example Then I get element by selector "button.primary" to have class containing "active"
|
|
243
|
+
*/
|
|
244
|
+
async function expectElementToHaveClassContaining(page, selectorKey, classKey) {
|
|
245
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
246
|
+
const className = (0, resolver_1.resolveParam)(classKey, "classes.json");
|
|
247
|
+
const element = page.locator(selector);
|
|
248
|
+
const currentClass = await element.getAttribute('class');
|
|
249
|
+
if (!currentClass || !currentClass.includes(className)) {
|
|
250
|
+
throw new Error(`Element "${selector}" does not have class containing "${className}", current classes: "${currentClass}"`);
|
|
251
|
+
}
|
|
252
|
+
console.log(`✅ Element "${selector}" has class containing "${className}"`);
|
|
253
|
+
}
|
|
254
|
+
// Additional functions for more specific text assertions
|
|
255
|
+
/**
|
|
256
|
+
* Asserts that an element does NOT contain the specified text.
|
|
257
|
+
* Supports fixtures for reusable selectors and text values.
|
|
258
|
+
* @example Then I get element by selector "error.message" to not contain text "success"
|
|
259
|
+
*/
|
|
260
|
+
async function expectElementToNotContainText(page, selectorKey, textKey) {
|
|
261
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
262
|
+
const texts = (0, fixtures_1.loadFixture)("texts.json");
|
|
263
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
264
|
+
const text = (0, fixtures_1.getFixtureValue)(texts, textKey);
|
|
265
|
+
await (0, test_1.expect)(page.locator(selector)).not.toContainText(text);
|
|
266
|
+
console.log(`✅ Element "${selector}" does not contain text "${text}"`);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Gets an element by selector and asserts it has the exact text specified.
|
|
270
|
+
* @example Then I get element by selector "header.title" to have text "Welcome Home"
|
|
271
|
+
*/
|
|
272
|
+
async function expectElementToHaveText(page, selectorKey, textKey) {
|
|
273
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
274
|
+
const text = (0, resolver_1.resolveParam)(textKey, "texts.json");
|
|
275
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveText(text);
|
|
276
|
+
console.log(`✅ Element "${selector}" has exact text "${text}"`);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Gets an element by selector and asserts it contains the specified text.
|
|
280
|
+
* @example Then I get element by selector "error.message" to contain text "invalid credentials"
|
|
281
|
+
*/
|
|
282
|
+
async function expectElementToContainText(page, selectorKey, textKey) {
|
|
283
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
284
|
+
const text = (0, resolver_1.resolveParam)(textKey, "texts.json");
|
|
285
|
+
await (0, test_1.expect)(page.locator(selector)).toContainText(text);
|
|
286
|
+
console.log(`✅ Element "${selector}" contains text "${text}"`);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Gets an element by selector and asserts it has the specified value.
|
|
290
|
+
* @example Then I get element by selector "login.usernameField" to have value "john_doe"
|
|
291
|
+
*/
|
|
292
|
+
async function expectElementToHaveValue(page, selectorKey, valueKey) {
|
|
293
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
294
|
+
const value = (0, resolver_1.resolveParam)(valueKey, "values.json");
|
|
295
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveValue(value);
|
|
296
|
+
console.log(`✅ Input "${selector}" has value "${value}"`);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Gets an element by selector and asserts it has the specified attribute with value.
|
|
300
|
+
* @example Then I get element by selector "terms.link" to have attribute "href" with value "/terms-and-conditions"
|
|
301
|
+
*/
|
|
302
|
+
async function expectElementAttributeValue(page, selectorKey, attrKey, valueKey) {
|
|
303
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
304
|
+
const attr = (0, resolver_1.resolveParam)(attrKey, "attributes.json");
|
|
305
|
+
const value = (0, resolver_1.resolveParam)(valueKey, "values.json");
|
|
306
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveAttribute(attr, value);
|
|
307
|
+
console.log(`✅ Element "${selector}" attribute "${attr}" is "${value}"`);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Gets an element by selector and asserts it is visible.
|
|
311
|
+
* @example When I get element by selector "div.modal" to be visible
|
|
312
|
+
*/
|
|
313
|
+
async function getElementBySelectorToBeVisible(page, selectorKey) {
|
|
314
|
+
const selector = (0, resolver_1.resolveParam)(selectorKey, "selectors.json");
|
|
315
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
316
|
+
console.log(`✅ Element "${selector}" is visible`);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Asserts that a heading element exists and is visible.
|
|
320
|
+
* Supports fixtures for reusable selectors.
|
|
321
|
+
* @example Then I see heading element "h1.main-title"
|
|
322
|
+
*/
|
|
323
|
+
async function expectHeadingVisible(page, selectorKey) {
|
|
324
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
325
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
326
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
327
|
+
console.log(`✅ Heading "${selector}" is visible`);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Asserts that a label element exists and is visible.
|
|
331
|
+
* Supports fixtures for reusable selectors.
|
|
332
|
+
* @example Then I see label element "label.username-label"
|
|
333
|
+
*/
|
|
334
|
+
async function expectLabelVisible(page, selectorKey) {
|
|
335
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
336
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
337
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
338
|
+
console.log(`✅ Label "${selector}" is visible`);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Asserts that a link element exists and is visible.
|
|
342
|
+
* Supports fixtures for reusable selectors.
|
|
343
|
+
* @example Then I see link element "a.privacy-link"
|
|
344
|
+
*/
|
|
345
|
+
async function expectLinkVisible(page, selectorKey) {
|
|
346
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
347
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
348
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
349
|
+
console.log(`✅ Link "${selector}" is visible`);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Asserts that an element with a specific test ID exists and is visible.
|
|
353
|
+
* Supports fixtures for reusable test IDs.
|
|
354
|
+
* @example Then I see testid element "data-testid=my-component"
|
|
355
|
+
*/
|
|
356
|
+
async function expectTestIdVisible(page, selectorKey) {
|
|
357
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
358
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
359
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
360
|
+
console.log(`✅ Test ID "${selector}" is visible`);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Asserts that an element with a specific role exists and is visible.
|
|
364
|
+
* Supports fixtures for reusable roles.
|
|
365
|
+
* @example Then I see role element "button"
|
|
366
|
+
*/
|
|
367
|
+
async function expectRoleVisible(page, roleKey) {
|
|
368
|
+
const roles = (0, fixtures_1.loadFixture)("roles.json");
|
|
369
|
+
const role = (0, fixtures_1.getFixtureValue)(roles, roleKey);
|
|
370
|
+
await (0, test_1.expect)(page.getByRole(role)).toBeVisible();
|
|
371
|
+
console.log(`✅ Role "${role}" is visible`);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Asserts that an option element exists and is visible.
|
|
375
|
+
* Supports fixtures for reusable selectors.
|
|
376
|
+
* @example Then I see option element "option[value='enabled']"
|
|
377
|
+
*/
|
|
378
|
+
async function expectOptionVisible(page, selectorKey) {
|
|
379
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
380
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
381
|
+
await (0, test_1.expect)(page.locator(selector)).toBeVisible();
|
|
382
|
+
console.log(`✅ Option "${selector}" is visible`);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Asserts that an element has a specific count of occurrences.
|
|
386
|
+
* Supports fixtures for reusable selectors.
|
|
387
|
+
* @example Then I expect "li.item" to have count 5
|
|
388
|
+
*/
|
|
389
|
+
async function expectElementToHaveCount(page, selectorKey, count) {
|
|
390
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
391
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
392
|
+
const elements = page.locator(selector);
|
|
393
|
+
const actualCount = await elements.count();
|
|
394
|
+
if (actualCount !== count) {
|
|
395
|
+
throw new Error(`Expected ${count} elements matching "${selector}", but found ${actualCount}`);
|
|
396
|
+
}
|
|
397
|
+
console.log(`✅ Element "${selector}" has count ${count}`);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Asserts that an element is hidden (not visible).
|
|
401
|
+
* Supports fixtures for reusable selectors.
|
|
402
|
+
* @example Then I expect "modal.overlay" to be hidden
|
|
403
|
+
*/
|
|
404
|
+
async function expectElementToBeHidden(page, selectorKey) {
|
|
405
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
406
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
407
|
+
await (0, test_1.expect)(page.locator(selector)).not.toBeVisible();
|
|
408
|
+
console.log(`✅ Element "${selector}" is hidden`);
|
|
409
|
+
}
|
|
410
|
+
// ==================================================
|
|
411
|
+
// GLUE STEPS
|
|
412
|
+
// ==================================================
|
|
413
|
+
(0, registry_1.Step)("I pw count elements {string}", countElements, "Then");
|
|
414
|
+
(0, registry_1.Step)("I pw do not see button element {string}", expectButtonNotVisible, "Then");
|
|
415
|
+
(0, registry_1.Step)("I pw do not see heading element {string}", expectHeadingNotVisible, "Then");
|
|
416
|
+
(0, registry_1.Step)("I pw do not see label element {string}", expectLabelNotVisible, "Then");
|
|
417
|
+
(0, registry_1.Step)("I pw do not see link element {string}", expectLinkNotVisible, "Then");
|
|
418
|
+
(0, registry_1.Step)("I pw do not see testid element {string}", expectTestIdNotVisible, "Then");
|
|
419
|
+
(0, registry_1.Step)("I pw do not see role element {string}", expectRoleNotVisible, "Then");
|
|
420
|
+
(0, registry_1.Step)("I pw do not see option element {string}", expectOptionNotVisible, "Then");
|
|
421
|
+
(0, registry_1.Step)("I pw do not see element with attribute {string} having value {string}", expectElementWithAttributeNotVisible, "Then");
|
|
422
|
+
(0, registry_1.Step)("I pw see element attribute {string} contains {string}", expectElementAttributeContains, "Then");
|
|
423
|
+
(0, registry_1.Step)("I pw see element attribute {string} equals {string}", expectElementAttributeEquals, "Then");
|
|
424
|
+
(0, registry_1.Step)("I pw see element has attribute {string}", expectElementHasAttribute, "Then");
|
|
425
|
+
(0, registry_1.Step)("I pw see button element {string}", expectButtonVisible, "Then");
|
|
426
|
+
(0, registry_1.Step)("I pw see heading element {string}", expectHeadingVisible, "Then");
|
|
427
|
+
(0, registry_1.Step)("I pw see label element {string}", expectLabelVisible, "Then");
|
|
428
|
+
(0, registry_1.Step)("I pw see link element {string}", expectLinkVisible, "Then");
|
|
429
|
+
(0, registry_1.Step)("I pw see testid element {string}", expectTestIdVisible, "Then");
|
|
430
|
+
(0, registry_1.Step)("I pw see role element {string}", expectRoleVisible, "Then");
|
|
431
|
+
(0, registry_1.Step)("I pw see option element {string}", expectOptionVisible, "Then");
|
|
432
|
+
(0, registry_1.Step)("I pw expect {string} to have count {int}", expectElementToHaveCount, "Then");
|
|
433
|
+
(0, registry_1.Step)("I pw expect {string} to be hidden", expectElementToBeHidden, "Then");
|
|
434
|
+
// Combined element selection and assertion steps
|
|
435
|
+
(0, registry_1.Step)("I pw get element by selector {string} to have class containing {string}", expectElementToHaveClassContaining, "When");
|
|
436
|
+
(0, registry_1.Step)("I pw get element by selector {string} to have text {string}", expectElementToHaveText, "Then");
|
|
437
|
+
(0, registry_1.Step)("I pw get element by selector {string} to contain text {string}", expectElementToContainText, "Then");
|
|
438
|
+
(0, registry_1.Step)("I pw get element by selector {string} to have value {string}", expectElementToHaveValue, "Then");
|
|
439
|
+
(0, registry_1.Step)("I pw get element by selector {string} to have attribute {string} with value {string}", expectElementAttributeValue, "Then");
|
|
440
|
+
(0, registry_1.Step)("I pw get element by selector {string} to be visible", getElementBySelectorToBeVisible, "When");
|
|
441
|
+
(0, registry_1.Step)("I pw get element by selector {string} to not contain text {string}", expectElementToNotContainText, "Then");
|
|
@@ -29,4 +29,4 @@ async function expectVisible(page, selectorKey, timeout = 2000) {
|
|
|
29
29
|
// ==================================================
|
|
30
30
|
// GLUE STEPS
|
|
31
31
|
// ==================================================
|
|
32
|
-
(0, registry_1.Step)("I expect the element {string} to be visible", expectVisible, "Then");
|
|
32
|
+
(0, registry_1.Step)("I pw expect the element {string} to be visible", expectVisible, "Then");
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that an input element has the expected value.
|
|
3
|
+
* Supports fixtures for reusable selectors and values.
|
|
4
|
+
* @example Then I see input value "login.username" equals "testuser"
|
|
5
|
+
*/
|
|
6
|
+
export declare function expectInputValue(page: any, selectorKey: string, valueKey: string): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Asserts that an input element has a value containing the expected substring.
|
|
9
|
+
* Supports fixtures for reusable selectors and values.
|
|
10
|
+
* @example Then I see input value "login.username" contains "test"
|
|
11
|
+
*/
|
|
12
|
+
export declare function expectInputValueContains(page: any, selectorKey: string, valueKey: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Asserts that a textarea element has the expected value.
|
|
15
|
+
* Supports fixtures for reusable selectors and values.
|
|
16
|
+
* @example Then I see textarea value "comments.textarea" equals "This is my comment"
|
|
17
|
+
*/
|
|
18
|
+
export declare function expectTextareaValue(page: any, selectorKey: string, valueKey: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Asserts that a textarea element has a value containing the expected substring.
|
|
21
|
+
* Supports fixtures for reusable selectors and values.
|
|
22
|
+
* @example Then I see textarea value "comments.textarea" contains "comment"
|
|
23
|
+
*/
|
|
24
|
+
export declare function expectTextareaValueContains(page: any, selectorKey: string, valueKey: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Asserts that an element has the expected text content.
|
|
27
|
+
* Supports fixtures for reusable selectors and text values.
|
|
28
|
+
* @example Then I see text "header.title" equals "Welcome to our site"
|
|
29
|
+
*/
|
|
30
|
+
export declare function expectText(page: any, selectorKey: string, textKey: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Asserts that an element has text content containing the expected substring.
|
|
33
|
+
* Supports fixtures for reusable selectors and text values.
|
|
34
|
+
* @example Then I see text "header.title" contains "Welcome"
|
|
35
|
+
*/
|
|
36
|
+
export declare function expectTextContains(page: any, selectorKey: string, textKey: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Asserts that an element has the expected value (for form elements).
|
|
39
|
+
* Supports fixtures for reusable selectors and values.
|
|
40
|
+
* @example Then I see value "input.amount" equals "100"
|
|
41
|
+
*/
|
|
42
|
+
export declare function expectValue(page: any, selectorKey: string, valueKey: string): Promise<void>;
|
|
43
|
+
//# sourceMappingURL=forms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../../src/backend/assertions/forms.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectInputValue = expectInputValue;
|
|
4
|
+
exports.expectInputValueContains = expectInputValueContains;
|
|
5
|
+
exports.expectTextareaValue = expectTextareaValue;
|
|
6
|
+
exports.expectTextareaValueContains = expectTextareaValueContains;
|
|
7
|
+
exports.expectText = expectText;
|
|
8
|
+
exports.expectTextContains = expectTextContains;
|
|
9
|
+
exports.expectValue = expectValue;
|
|
10
|
+
//src/backend/assertions/forms.ts
|
|
11
|
+
const test_1 = require("@playwright/test");
|
|
12
|
+
const registry_1 = require("../../core/registry");
|
|
13
|
+
const fixtures_1 = require("../utils/fixtures");
|
|
14
|
+
// ==================================================
|
|
15
|
+
// CORE FUNCTIONS
|
|
16
|
+
// ==================================================
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that an input element has the expected value.
|
|
19
|
+
* Supports fixtures for reusable selectors and values.
|
|
20
|
+
* @example Then I see input value "login.username" equals "testuser"
|
|
21
|
+
*/
|
|
22
|
+
async function expectInputValue(page, selectorKey, valueKey) {
|
|
23
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
24
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
25
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
26
|
+
const expectedValue = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
27
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveValue(expectedValue);
|
|
28
|
+
console.log(`✅ Input "${selector}" has value "${expectedValue}"`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Asserts that an input element has a value containing the expected substring.
|
|
32
|
+
* Supports fixtures for reusable selectors and values.
|
|
33
|
+
* @example Then I see input value "login.username" contains "test"
|
|
34
|
+
*/
|
|
35
|
+
async function expectInputValueContains(page, selectorKey, valueKey) {
|
|
36
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
37
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
38
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
39
|
+
const expectedValue = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
40
|
+
const actualValue = await page.locator(selector).inputValue();
|
|
41
|
+
if (!actualValue.includes(expectedValue)) {
|
|
42
|
+
throw new Error(`Input "${selector}" value "${actualValue}" does not contain "${expectedValue}"`);
|
|
43
|
+
}
|
|
44
|
+
console.log(`✅ Input "${selector}" value contains "${expectedValue}"`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Asserts that a textarea element has the expected value.
|
|
48
|
+
* Supports fixtures for reusable selectors and values.
|
|
49
|
+
* @example Then I see textarea value "comments.textarea" equals "This is my comment"
|
|
50
|
+
*/
|
|
51
|
+
async function expectTextareaValue(page, selectorKey, valueKey) {
|
|
52
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
53
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
54
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
55
|
+
const expectedValue = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
56
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveValue(expectedValue);
|
|
57
|
+
console.log(`✅ Textarea "${selector}" has value "${expectedValue}"`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Asserts that a textarea element has a value containing the expected substring.
|
|
61
|
+
* Supports fixtures for reusable selectors and values.
|
|
62
|
+
* @example Then I see textarea value "comments.textarea" contains "comment"
|
|
63
|
+
*/
|
|
64
|
+
async function expectTextareaValueContains(page, selectorKey, valueKey) {
|
|
65
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
66
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
67
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
68
|
+
const expectedValue = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
69
|
+
const actualValue = await page.locator(selector).inputValue();
|
|
70
|
+
if (!actualValue.includes(expectedValue)) {
|
|
71
|
+
throw new Error(`Textarea "${selector}" value "${actualValue}" does not contain "${expectedValue}"`);
|
|
72
|
+
}
|
|
73
|
+
console.log(`✅ Textarea "${selector}" value contains "${expectedValue}"`);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Asserts that an element has the expected text content.
|
|
77
|
+
* Supports fixtures for reusable selectors and text values.
|
|
78
|
+
* @example Then I see text "header.title" equals "Welcome to our site"
|
|
79
|
+
*/
|
|
80
|
+
async function expectText(page, selectorKey, textKey) {
|
|
81
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
82
|
+
const texts = (0, fixtures_1.loadFixture)("texts.json");
|
|
83
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
84
|
+
const expectedText = (0, fixtures_1.getFixtureValue)(texts, textKey);
|
|
85
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveText(expectedText);
|
|
86
|
+
console.log(`✅ Element "${selector}" has text "${expectedText}"`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Asserts that an element has text content containing the expected substring.
|
|
90
|
+
* Supports fixtures for reusable selectors and text values.
|
|
91
|
+
* @example Then I see text "header.title" contains "Welcome"
|
|
92
|
+
*/
|
|
93
|
+
async function expectTextContains(page, selectorKey, textKey) {
|
|
94
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
95
|
+
const texts = (0, fixtures_1.loadFixture)("texts.json");
|
|
96
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
97
|
+
const expectedText = (0, fixtures_1.getFixtureValue)(texts, textKey);
|
|
98
|
+
const actualText = await page.locator(selector).textContent();
|
|
99
|
+
if (!actualText || !actualText.includes(expectedText)) {
|
|
100
|
+
throw new Error(`Element "${selector}" text "${actualText}" does not contain "${expectedText}"`);
|
|
101
|
+
}
|
|
102
|
+
console.log(`✅ Element "${selector}" text contains "${expectedText}"`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Asserts that an element has the expected value (for form elements).
|
|
106
|
+
* Supports fixtures for reusable selectors and values.
|
|
107
|
+
* @example Then I see value "input.amount" equals "100"
|
|
108
|
+
*/
|
|
109
|
+
async function expectValue(page, selectorKey, valueKey) {
|
|
110
|
+
const selectors = (0, fixtures_1.loadFixture)("selectors.json");
|
|
111
|
+
const values = (0, fixtures_1.loadFixture)("values.json");
|
|
112
|
+
const selector = (0, fixtures_1.getFixtureValue)(selectors, selectorKey);
|
|
113
|
+
const expectedValue = (0, fixtures_1.getFixtureValue)(values, valueKey);
|
|
114
|
+
await (0, test_1.expect)(page.locator(selector)).toHaveValue(expectedValue);
|
|
115
|
+
console.log(`✅ Element "${selector}" has value "${expectedValue}"`);
|
|
116
|
+
}
|
|
117
|
+
// ==================================================
|
|
118
|
+
// GLUE STEPS
|
|
119
|
+
// ==================================================
|
|
120
|
+
(0, registry_1.Step)("I pw see input value {string} equals {string}", expectInputValue, "Then");
|
|
121
|
+
(0, registry_1.Step)("I pw see input value {string} contains {string}", expectInputValueContains, "Then");
|
|
122
|
+
(0, registry_1.Step)("I pw see textarea value {string} equals {string}", expectTextareaValue, "Then");
|
|
123
|
+
(0, registry_1.Step)("I pw see textarea value {string} contains {string}", expectTextareaValueContains, "Then");
|
|
124
|
+
(0, registry_1.Step)("I pw see text {string} equals {string}", expectText, "Then");
|
|
125
|
+
(0, registry_1.Step)("I pw see text {string} contains {string}", expectTextContains, "Then");
|
|
126
|
+
(0, registry_1.Step)("I pw see value {string} equals {string}", expectValue, "Then");
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
export * from "./visibility";
|
|
2
|
+
export * from "./expectVisible";
|
|
2
3
|
export * from "./text";
|
|
3
4
|
export * from "./pageState";
|
|
5
|
+
export * from "./document";
|
|
6
|
+
export * from "./storage";
|
|
7
|
+
export * from "./elements";
|
|
8
|
+
export * from "./forms";
|
|
4
9
|
import "./visibility";
|
|
10
|
+
import "./expectVisible";
|
|
5
11
|
import "./text";
|
|
6
12
|
import "./pageState";
|
|
13
|
+
import "./document";
|
|
14
|
+
import "./storage";
|
|
15
|
+
import "./elements";
|
|
16
|
+
import "./forms";
|
|
7
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backend/assertions/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backend/assertions/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAIxB,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;AACzB,OAAO,QAAQ,CAAC;AAChB,OAAO,aAAa,CAAC;AACrB,OAAO,YAAY,CAAC;AACpB,OAAO,WAAW,CAAC;AACnB,OAAO,YAAY,CAAC;AACpB,OAAO,SAAS,CAAC"}
|