From 6ba4ce8b9e856a3f040bf28de0ed152b901a8d60 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Wed, 22 Nov 2023 11:11:22 +0100 Subject: [PATCH] fix(appium): expose switchToContext --- docs/helpers/Appium.md | 2 +- lib/helper/Appium.js | 12 ++++++------ test/helper/AppiumV2_test.js | 4 ++-- test/helper/Appium_test.js | 4 ++-- typings/tests/helpers/Appium.types.ts | 2 +- typings/tests/helpers/AppiumTs.types.ts | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/helpers/Appium.md b/docs/helpers/Appium.md index 20025b8c9..9b08f3bd6 100644 --- a/docs/helpers/Appium.md +++ b/docs/helpers/Appium.md @@ -440,7 +440,7 @@ let settings = await I.grabSettings(); Returns **[Promise][6]<[string][5]>** Appium: support Android and iOS -### \_switchToContext +### switchToContext Switch to the specified context. diff --git a/lib/helper/Appium.js b/lib/helper/Appium.js index d448c858b..c6e2b9f44 100644 --- a/lib/helper/Appium.js +++ b/lib/helper/Appium.js @@ -368,7 +368,7 @@ class Appium extends Webdriver { if (context.web) return this.switchToWeb(context.web); if (context.webview) return this.switchToWeb(context.webview); } - return this._switchToContext(context); + return this.switchToContext(context); } _withinEnd() { @@ -834,7 +834,7 @@ class Appium extends Webdriver { * * @param {*} context the context to switch to */ - async _switchToContext(context) { + async switchToContext(context) { return this.browser.switchContext(context); } @@ -858,11 +858,11 @@ class Appium extends Webdriver { this.isWeb = true; this.defaultContext = 'body'; - if (context) return this._switchToContext(context); + if (context) return this.switchToContext(context); const contexts = await this.grabAllContexts(); this.debugSection('Contexts', contexts.toString()); for (const idx in contexts) { - if (contexts[idx].match(/^WEBVIEW/)) return this._switchToContext(contexts[idx]); + if (contexts[idx].match(/^WEBVIEW/)) return this.switchToContext(contexts[idx]); } throw new Error('No WEBVIEW could be guessed, please specify one in params'); @@ -885,8 +885,8 @@ class Appium extends Webdriver { this.isWeb = false; this.defaultContext = '//*'; - if (context) return this._switchToContext(context); - return this._switchToContext('NATIVE_APP'); + if (context) return this.switchToContext(context); + return this.switchToContext('NATIVE_APP'); } /** diff --git a/test/helper/AppiumV2_test.js b/test/helper/AppiumV2_test.js index 22e00e826..540f1765d 100644 --- a/test/helper/AppiumV2_test.js +++ b/test/helper/AppiumV2_test.js @@ -171,12 +171,12 @@ describe('Appium', function () { }); }); - describe('app context and activity: #_switchToContext, #switchToWeb, #switchToNative', () => { + describe('app context and activity: #switchToContext, #switchToWeb, #switchToNative', () => { it('should switch context', async () => { await app.resetApp(); await app.waitForElement('~buttonStartWebviewCD', smallWait); await app.click('~buttonStartWebviewCD'); - await app._switchToContext('WEBVIEW_io.selendroid.testapp'); + await app.switchToContext('WEBVIEW_io.selendroid.testapp'); const val = await app.grabContext(); return assert.equal(val, 'WEBVIEW_io.selendroid.testapp'); }); diff --git a/test/helper/Appium_test.js b/test/helper/Appium_test.js index 0d6db3f96..cd3a18fe3 100644 --- a/test/helper/Appium_test.js +++ b/test/helper/Appium_test.js @@ -168,12 +168,12 @@ describe('Appium', function () { }); }); - describe('app context and activity: #_switchToContext, #switchToWeb, #switchToNative', () => { + describe('app context and activity: #switchToContext, #switchToWeb, #switchToNative', () => { it('should switch context', async () => { await app.resetApp(); await app.waitForElement('~buttonStartWebviewCD', smallWait); await app.click('~buttonStartWebviewCD'); - await app._switchToContext('WEBVIEW_io.selendroid.testapp'); + await app.switchToContext('WEBVIEW_io.selendroid.testapp'); const val = await app.grabContext(); return assert.equal(val, 'WEBVIEW_io.selendroid.testapp'); }); diff --git a/typings/tests/helpers/Appium.types.ts b/typings/tests/helpers/Appium.types.ts index 9d3323619..99467fa7f 100644 --- a/typings/tests/helpers/Appium.types.ts +++ b/typings/tests/helpers/Appium.types.ts @@ -39,7 +39,7 @@ appium.grabCurrentActivity(); // $ExpectType Promise appium.grabNetworkConnection(); // $ExpectType Promise<{}> appium.grabOrientation(); // $ExpectType Promise appium.grabSettings(); // $ExpectType Promise -appium._switchToContext(str); // $ExpectType void +appium.switchToContext(str); // $ExpectType void appium.switchToWeb(); // $ExpectType Promise appium.switchToNative(); // $ExpectType Promise appium.switchToNative(str); // $ExpectType Promise diff --git a/typings/tests/helpers/AppiumTs.types.ts b/typings/tests/helpers/AppiumTs.types.ts index e1c88b672..b41983925 100644 --- a/typings/tests/helpers/AppiumTs.types.ts +++ b/typings/tests/helpers/AppiumTs.types.ts @@ -39,7 +39,7 @@ appium.grabCurrentActivity(); // $ExpectType Promise appium.grabNetworkConnection(); // $ExpectType Promise<{}> appium.grabOrientation(); // $ExpectType Promise appium.grabSettings(); // $ExpectType Promise -appium._switchToContext(str); // $ExpectType Promise +appium.switchToContext(str); // $ExpectType Promise appium.switchToWeb(); // $ExpectType Promise appium.switchToNative(); // $ExpectType Promise appium.switchToNative(str); // $ExpectType Promise