@@ -36,25 +36,22 @@ import { iosPortForward, iosRemovePortForward } from './iOS';
36
36
import type { PortForwardCallback , PortReleaseCallback } from './types' ;
37
37
import _ from 'lodash' ;
38
38
39
- import type {
40
- RouteMatcher
41
- } from '@appium/types' ;
39
+ import type { RouteMatcher } from '@appium/types' ;
42
40
43
41
const WEBVIEW_NO_PROXY = [
44
- [ `GET` , new RegExp ( `^/session/[^/]+/appium` ) ] ,
45
- [ `GET` , new RegExp ( `^/session/[^/]+/context` ) ] ,
46
- [ `GET` , new RegExp ( `^/session/[^/]+/element/[^/]+/rect` ) ] ,
47
- [ `GET` , new RegExp ( `^/session/[^/]+/log/types$` ) ] ,
48
- [ `GET` , new RegExp ( `^/session/[^/]+/orientation` ) ] ,
49
- [ `POST` , new RegExp ( `^/session/[^/]+/appium` ) ] ,
50
- [ `POST` , new RegExp ( `^/session/[^/]+/context` ) ] ,
51
- [ `POST` , new RegExp ( `^/session/[^/]+/log$` ) ] ,
52
- [ `POST` , new RegExp ( `^/session/[^/]+/orientation` ) ] ,
53
- [ `POST` , new RegExp ( `^/session/[^/]+/touch/multi/perform` ) ] ,
54
- [ `POST` , new RegExp ( `^/session/[^/]+/touch/perform` ) ] ,
42
+ [ `GET` , new RegExp ( `^/session/[^/]+/appium` ) ] ,
43
+ [ `GET` , new RegExp ( `^/session/[^/]+/context` ) ] ,
44
+ [ `GET` , new RegExp ( `^/session/[^/]+/element/[^/]+/rect` ) ] ,
45
+ [ `GET` , new RegExp ( `^/session/[^/]+/log/types$` ) ] ,
46
+ [ `GET` , new RegExp ( `^/session/[^/]+/orientation` ) ] ,
47
+ [ `POST` , new RegExp ( `^/session/[^/]+/appium` ) ] ,
48
+ [ `POST` , new RegExp ( `^/session/[^/]+/context` ) ] ,
49
+ [ `POST` , new RegExp ( `^/session/[^/]+/log$` ) ] ,
50
+ [ `POST` , new RegExp ( `^/session/[^/]+/orientation` ) ] ,
51
+ [ `POST` , new RegExp ( `^/session/[^/]+/touch/multi/perform` ) ] ,
52
+ [ `POST` , new RegExp ( `^/session/[^/]+/touch/perform` ) ] ,
55
53
] as import ( '@appium/types' ) . RouteMatcher [ ] ;
56
54
57
-
58
55
export class AppiumFlutterDriver extends BaseDriver < FlutterDriverConstraints > {
59
56
// @ts -ignore
60
57
public proxydriver : XCUITestDriver | AndroidUiautomator2Driver ;
@@ -215,19 +212,32 @@ export class AppiumFlutterDriver extends BaseDriver<FlutterDriverConstraints> {
215
212
}
216
213
217
214
async executeCommand ( command : any , ...args : any ) {
218
- if ( this . currentContext === this . NATIVE_CONTEXT_NAME && isFlutterDriverCommand ( command ) ) {
215
+ if (
216
+ this . currentContext === this . NATIVE_CONTEXT_NAME &&
217
+ isFlutterDriverCommand ( command )
218
+ ) {
219
219
return await super . executeCommand ( command , ...args ) ;
220
220
}
221
221
222
222
this . handleContextSwitch ( command , args ) ;
223
- logger . default . info ( `Executing the proxy command: ${ command } with args: ${ args } ` ) ;
223
+ logger . default . info (
224
+ `Executing the proxy command: ${ command } with args: ${ args } ` ,
225
+ ) ;
224
226
return await this . proxydriver . executeCommand ( command as string , ...args ) ;
225
227
}
226
228
227
229
private handleContextSwitch ( command : string , args : any [ ] ) : void {
228
230
if ( command === 'setContext' ) {
229
- const isWebviewContext = args . find ( ( arg ) => typeof arg === 'string' && arg . includes ( 'WEBVIEW' ) ) ;
230
- this . currentContext = args [ 0 ] ;
231
+ const isWebviewContext =
232
+ typeof args [ 0 ] === 'string' && args [ 0 ] . includes ( 'WEBVIEW' ) ;
233
+ if ( typeof args [ 0 ] === 'string' && args [ 0 ] . length > 0 ) {
234
+ this . currentContext = args [ 0 ] ;
235
+ } else {
236
+ logger . default . warn (
237
+ `Attempted to set context to invalid value: ${ args [ 0 ] } . Keeping current context: ${ this . currentContext } ` ,
238
+ ) ;
239
+ }
240
+
231
241
if ( isWebviewContext ) {
232
242
this . proxyWebViewActive = true ;
233
243
} else {
@@ -237,8 +247,8 @@ export class AppiumFlutterDriver extends BaseDriver<FlutterDriverConstraints> {
237
247
}
238
248
239
249
public getProxyAvoidList ( ) : RouteMatcher [ ] {
240
- return WEBVIEW_NO_PROXY ;
241
- }
250
+ return WEBVIEW_NO_PROXY ;
251
+ }
242
252
243
253
public async createSession (
244
254
...args : any [ ]
@@ -424,14 +434,14 @@ export class AppiumFlutterDriver extends BaseDriver<FlutterDriverConstraints> {
424
434
}
425
435
426
436
public proxyActive ( ) : boolean {
427
- // In WebView context, all request should got to each driver
437
+ // In WebView context, all request should go to each driver
428
438
// so that they can handle http request properly.
429
439
// On iOS, WebView context is handled by XCUITest driver while Android is by chromedriver.
430
440
// It means XCUITest driver should keep the XCUITest driver as a proxy,
431
441
// while UIAutomator2 driver should proxy to chromedriver instead of UIA2 proxy.
432
442
return (
433
443
this . proxyWebViewActive &&
434
- this . proxydriver . constructor . name !== XCUITestDriver . name
444
+ ! ( this . proxydriver instanceof XCUITestDriver )
435
445
) ;
436
446
}
437
447
0 commit comments