@@ -3,6 +3,7 @@ import log from '../logger';
33import Chromedriver from 'appium-chromedriver' ;
44import PortFinder from 'portfinder' ;
55import B from 'bluebird' ;
6+ import { util } from 'appium-support' ;
67import { errors } from 'appium-base-driver' ;
78import { default as webviewHelpers ,
89 NATIVE_WIN , WEBVIEW_BASE , WEBVIEW_WIN , CHROMIUM_WIN } from '../webview-helpers' ;
@@ -37,21 +38,22 @@ commands.getContexts = async function () {
3738} ;
3839
3940commands . setContext = async function ( name ) {
40- if ( name === null ) {
41+ if ( ! util . hasValue ( name ) ) {
4142 name = this . defaultContextName ( ) ;
4243 } else if ( name === WEBVIEW_WIN ) {
4344 // handle setContext "WEBVIEW"
4445 name = this . defaultWebviewName ( ) ;
4546 }
47+ // if we're already in the context we want, do nothing
48+ if ( name === this . curContext ) {
49+ return ;
50+ }
51+
4652 let contexts = await this . getContexts ( ) ;
4753 // if the context we want doesn't exist, fail
4854 if ( ! _ . includes ( contexts , name ) ) {
4955 throw new errors . NoSuchContextError ( ) ;
5056 }
51- // if we're already in the context we want, do nothing
52- if ( name === this . curContext ) {
53- return ;
54- }
5557
5658 await this . switchContext ( name ) ;
5759 this . curContext = name ;
0 commit comments