11import { When } from '@cucumber/cucumber' ;
22import { getValue , getElement } from './transformers' ;
33import { po } from '@qavajs/po-playwright' ;
4+ import { expect } from '@playwright/test' ;
45
56/**
67 * Opens provided url
@@ -79,6 +80,10 @@ When('I switch to parent frame', async function () {
7980 * @example I switch to 2 frame
8081 */
8182When ( 'I switch to {int} frame' , async function ( index : number ) {
83+ await expect . poll (
84+ ( ) => page . frames ( ) ?. length ,
85+ { timeout : config . browser . timeout . page }
86+ ) . toBeGreaterThan ( index ) ;
8287 // @ts -ignore
8388 po . driver = page . frames ( ) [ index ] ;
8489} ) ;
@@ -89,7 +94,15 @@ When('I switch to {int} frame', async function (index: number) {
8994 * @example I switch to 2 window
9095 */
9196When ( 'I switch to {int} window' , async function ( index : number ) {
97+ await expect . poll (
98+ ( ) => browser . contexts ( ) ?. length ,
99+ { timeout : config . browser . timeout . page }
100+ ) . toBeGreaterThan ( index - 1 ) ;
92101 global . context = browser . contexts ( ) [ index - 1 ] ;
102+ await expect . poll (
103+ ( ) => context . pages ( ) ?. length ,
104+ { timeout : config . browser . timeout . page }
105+ ) . toBeGreaterThan ( index - 1 ) ;
93106 global . page = context . pages ( ) [ index - 1 ] ;
94107 //@ts -ignore
95108 po . driver = page ;
0 commit comments