Skip to content

Commit 1650c36

Browse files
added _I switch to 'window name or title' window_ (#49)
* added _I switch to 'window name or title' window_
1 parent 278d13e commit 1650c36

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
77
## [0.0.23]
88
- :rocket: added types to global members
99
- :rocket: added _I switch to 'IFrame' frame_
10+
- :rocket: added _I switch to 'window name or title' window_
1011

1112
## [0.0.22]
1213
- :beetle: fixed exports of mock and poDefine

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/qavajs/steps-playwright#readme",
2525
"devDependencies": {
2626
"@cucumber/cucumber": "^9.1.2",
27-
"@qavajs/cli": "^0.0.22",
27+
"@qavajs/cli": "^0.0.23",
2828
"@qavajs/console-formatter": "^0.2.1",
2929
"@qavajs/memory": "^1.4.1",
3030
"@qavajs/po-playwright": "^0.0.9",

src/actions.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@ When('I switch to {int} window', async function (index: number) {
127127
po.driver = page;
128128
});
129129

130+
/**
131+
* Switch to window by title or url
132+
* @param {string} matcher - url or title of window to switch
133+
* @example I switch to 'google' window
134+
*/
135+
When('I switch to {string} window', async function (matcher: string) {
136+
const urlOrTitle = await getValue(matcher);
137+
const pages = context.pages();
138+
for (const p of pages) {
139+
if (p.url().includes(urlOrTitle) || (await p.title()).includes(urlOrTitle)) {
140+
global.page = p;
141+
//@ts-ignore
142+
po.driver = p;
143+
return;
144+
}
145+
}
146+
throw new Error(`Page matching '${matcher}' is not found`);
147+
});
148+
130149
/**
131150
* Refresh current page
132151
* @example I refresh page

test-e2e/features/actions.feature

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,19 @@ Feature: actions
9191
When I expect 'Frame Element' not to be visible
9292
When I expect 'Inner Frame Element' not to be visible
9393

94-
Scenario: switch to tab by index
94+
Scenario Outline: switch to tab by <test>
9595
When I click 'New Tab Link'
9696
When I wait 1000 ms
97-
When I switch to 2 window
97+
When I switch to <param> window
9898
Then I expect current url to be equal '$framePage'
9999
When I expect 'Frame Element' to be visible
100100

101+
Examples:
102+
| test | param |
103+
| index | 2 |
104+
| title | 'Frame' |
105+
| url | 'frame.html' |
106+
101107
Scenario: refresh page
102108
When I type 'test value' to 'Input'
103109
Then I expect text of 'Action' to be equal 'test value'

test-e2e/features/waits.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Feature: waits
7979
Then I wait until text of 'Loading' to be equal '100%' (timeout: 3000)
8080

8181
Scenario: wait for property with timeout
82-
Then I wait until 'value' property of 'Loading Input' to be equal '100%' (timeout: 3000)
82+
Then I wait until 'value' property of 'Loading Input' to be equal '100%' (timeout: 5000)
8383

8484
Scenario: wait for attribute with timeout
8585
Then I wait until 'style' attribute of 'Hidden Element' to contain 'hidden' (timeout: 3000)

0 commit comments

Comments
 (0)