@@ -28,6 +28,8 @@ export class WebdriverBrowserProvider implements BrowserProvider {
2828 private options ?: Capabilities . WebdriverIOConfig
2929
3030 private closing = false
31+ private iframeSwitched = false
32+ private topLevelContext : string | undefined
3133
3234 getSupportedBrowsers ( ) : readonly string [ ] {
3335 return webdriverBrowsers
@@ -43,6 +45,10 @@ export class WebdriverBrowserProvider implements BrowserProvider {
4345 this . options = options as Capabilities . WebdriverIOConfig
4446 }
4547
48+ isIframeSwitched ( ) : boolean {
49+ return this . iframeSwitched
50+ }
51+
4652 async switchToTestFrame ( ) : Promise < void > {
4753 const page = this . browser !
4854 // support wdio@9
@@ -56,6 +62,7 @@ export class WebdriverBrowserProvider implements BrowserProvider {
5662 )
5763 await page . switchToFrame ( iframe )
5864 }
65+ this . iframeSwitched = true
5966 }
6067
6168 async switchToMainFrame ( ) : Promise < void > {
@@ -66,6 +73,21 @@ export class WebdriverBrowserProvider implements BrowserProvider {
6673 else {
6774 await page . switchToParentFrame ( )
6875 }
76+ this . iframeSwitched = false
77+ }
78+
79+ async setViewport ( options : { width : number ; height : number } ) : Promise < void > {
80+ if ( this . topLevelContext == null || ! this . browser ) {
81+ throw new Error ( `The browser has no open pages.` )
82+ }
83+ await this . browser . send ( {
84+ method : 'browsingContext.setViewport' ,
85+ params : {
86+ context : this . topLevelContext ,
87+ devicePixelRatio : 1 ,
88+ viewport : options ,
89+ } ,
90+ } )
6991 }
7092
7193 getCommandsContext ( ) : {
@@ -153,6 +175,7 @@ export class WebdriverBrowserProvider implements BrowserProvider {
153175 const browserInstance = await this . openBrowser ( )
154176 debug ?.( '[%s][%s] browser page is created, opening %s' , sessionId , this . browserName , url )
155177 await browserInstance . url ( url )
178+ this . topLevelContext = await browserInstance . getWindowHandle ( )
156179 await this . _throwIfClosing ( 'opening the url' )
157180 }
158181
0 commit comments