Skip to content

Commit 55c6266

Browse files
added value wait and expect steps (#108)
1 parent df91020 commit 55c6266

File tree

9 files changed

+69
-7
lines changed

9 files changed

+69
-7
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
publish-npm:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
1616
with:
1717
node-version: 18
1818
registry-url: https://registry.npmjs.org/

.github/workflows/pull-request.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
version: [ 18, 20 ]
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
16-
- uses: actions/setup-node@v3
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
1717
with:
1818
node-version: ${{ matrix.version }}
1919
- run: npm ci
@@ -22,7 +22,7 @@ jobs:
2222
- run: npm run install:browsers
2323
- run: npm run test:e2e
2424
- name: junit report
25-
uses: mikepenz/action-junit-report@v3
25+
uses: mikepenz/action-junit-report@v4
2626
if: always()
2727
with:
2828
report_paths: './test-e2e/report.xml'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1111

1212
## [Unreleased]
1313
- :pencil: cleaned up dependencies
14+
- :rocket: added value wait and validation
1415

1516
## [0.44.0]
1617
- :rocket: added option to take full page screenshot (_config.browser.screenshot.fullPage_)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/steps-playwright",
3-
"version": "0.44.0",
3+
"version": "0.45.0",
44
"description": "steps to interact with playwright",
55
"main": "./index.js",
66
"scripts": {

src/validations.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ Then(
4141
}
4242
);
4343

44+
/**
45+
* Verify value of element
46+
* @param {string} alias - element to verify
47+
* @param {string} validationType - validation
48+
* @param {string} value - expected value
49+
* @example I expect value of 'Search Input' to be equal 'text'
50+
*/
51+
Then(
52+
'I expect value of {string} {playwrightValidation} {string}',
53+
async function (alias: string, validationType: string, value: string) {
54+
const expectedValue = await getValue(value);
55+
const element = await getElement(alias);
56+
const timeout = config.browser.timeout.value;
57+
await element.waitFor({ state: 'attached', timeout });
58+
const validation = getPollValidation(validationType);
59+
const actualValue = () => element.evaluate(
60+
(node: any) => node.value
61+
);
62+
await validation(actualValue, expectedValue, {
63+
timeout,
64+
interval: config.browser.timeout.valueInterval
65+
});
66+
}
67+
);
68+
4469
/**
4570
* Verify that property of element satisfies condition
4671
* @param {string} property - element to verify

src/waits.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,33 @@ When(
7272
}
7373
);
7474

75+
/**
76+
* Wait for element value condition
77+
* @param {string} alias - element to wait condition
78+
* @param {string} wait - wait condition
79+
* @param {string} value - expected value to wait
80+
* @param {number|null} [timeout] - custom timeout in ms
81+
* @example I wait until value of 'Search Input' to be equal 'Javascript'
82+
* @example I wait until value of 'Search Input' to be equal 'Javascript' (timeout: 3000)
83+
*/
84+
When(
85+
'I wait until value of {string} {playwrightValidation} {string}( ){playwrightTimeout}',
86+
async function (alias: string, waitType: string, value: string, timeoutValue: number | null) {
87+
const wait = getPollValidation(waitType);
88+
const element = await getElement(alias);
89+
const timeout = timeoutValue ?? config.browser.timeout.value;
90+
await element.waitFor({ state: 'attached', timeout });
91+
const expectedValue = await getValue(value);
92+
const getValueFn = () => element.evaluate(
93+
(node: any) => node.value
94+
);
95+
await wait(getValueFn, expectedValue, {
96+
timeout,
97+
interval: config.browser.timeout.valueInterval
98+
});
99+
}
100+
);
101+
75102
/**
76103
* Wait for element property condition
77104
* @param {string} property - property

test-e2e/features/validations.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Feature: validations
1818
Then I expect number of elements in 'Simple Text List Items' collection to be greater than '2'
1919
Then I expect number of elements in 'Simple Text List Items' collection to be less than '4'
2020

21+
Scenario: element value
22+
Then I expect value of 'Simple Text Input' to be equal '123'
23+
Then I expect value of 'Simple Text Input' not to be equal '1234'
24+
Then I expect value of 'Simple Text Input' to contain '12'
25+
2126
Scenario: element property
2227
Then I expect 'value' property of 'Simple Text Input' to be equal '123'
2328
Then I expect 'value' property of 'Simple Text Input' not to be equal '1234'

test-e2e/features/waits.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Feature: waits
2222
| not to contain | 10 |
2323
| not to match | ^.0%$ |
2424

25+
Scenario: wait for value
26+
Then I wait until value of 'Loading Input' to equal '100%'
27+
2528
Scenario Outline: wait for property (<condition>)
2629
Then I wait until 'value' property of 'Loading Input' <condition> '<expectation>'
2730

test-e2e/webui.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const common = {
3737
],
3838
formatOptions: {
3939
console: {
40-
showLogs: true
40+
showLogs: true,
41+
showProgress: false
4142
}
4243
},
4344
memory: new Memory(),

0 commit comments

Comments
 (0)