test(appium): add e2e tests for plugin use of executeMethod(Map)
MODIFY
packages/appium/test/e2e/plugin.e2e.spec.js
packages/appium/test/e2e/plugin.e2e.spec.js
@@ -328,6 +328,50 @@ describe('FakePlugin w/ FakeDriver via HTTP', function () {
});
});
});
+
+ describe('Execute Methods', function () {
+ /** @type {AppiumServer} */
+ let server;
+
+ /** @type {import('webdriverio').Browser<'async'>} */
+ let driver;
+
+ before(async function () {
+ // then start server if we need to
+ const args = {
+ appiumHome,
+ port,
+ address: TEST_HOST,
+ usePlugins: ['fake'],
+ useDrivers: ['fake'],
+ };
+ server = /** @type {AppiumServer} */ (await appiumServer(args));
+ driver = await wdio(wdOpts);
+ });
+ after(async function () {
+ if (driver) {
+ await driver.deleteSession();
+ }
+ if (server) {
+ await server.close();
+ }
+ });
+
+ it('should handle execute methods using executeMethodMap', async function () {
+ const res = await driver.executeScript('fake: plugMeIn', [{socket: 'electrical'}]);
+ res.should.eql('Plugged in to electrical');
+ });
+
+ it('should handle execute methods overridden on the driver', async function () {
+ const res = await driver.executeScript('fake: getThing', []);
+ res.should.eql('PLUGIN_FAKE_THING');
+ });
+
+ it('should let driver handle unknown execute methods', async function () {
+ const sum = await driver.executeScript('fake: addition', [{num1: 2, num2: 3}]);
+ sum.should.eql(5);
+ });
+ });
});
/**

MODIFY
packages/fake-plugin/lib/plugin.js
packages/fake-plugin/lib/plugin.js
@@ -5,10 +5,7 @@ import {BasePlugin} from 'appium/plugin';
import B from 'bluebird';
class FakePlugin extends BasePlugin {
- async getFakePluginArgs() {
- await B.delay(1);
- return this.cliArgs;
- }
+ fakeThing = 'PLUGIN_FAKE_THING';
static newMethodMap = /** @type {const} */ ({
'/session/:sessionId/fake_data': {
@@ -27,6 +24,19 @@ class FakePlugin extends BasePlugin {
/** @type {string?} */
static _unexpectedData = null;
+ static executeMethodMap = /** @type {const} */ ({
+ // this execute method overrides fake-drivers fake: getThing, for testing
+ 'fake: getThing': {
+ command: 'getFakeThing',
+ },
+
+ // this is a totally new execute method
+ 'fake: plugMeIn': {
+ command: 'plugMeIn',
+ params: {required: ['socket']},
+ },
+ });
+
static fakeRoute(req, res) {
res.send(JSON.stringify({fake: 'fakeResponse'}));
}
@@ -45,6 +55,21 @@ class FakePlugin extends BasePlugin {
});
}
+ async getFakeThing() {
+ await B.delay(1);
+ return this.fakeThing;
+ }
+
+ async plugMeIn(next, driver, /** @type {string} */ socket) {
+ await B.delay(1);
+ return `Plugged in to ${socket}`;
+ }
+
+ async getFakePluginArgs() {
+ await B.delay(1);
+ return this.cliArgs;
+ }
+
async getPageSource(next, driver, ...args) {
await B.delay(10);
return `<Fake>${JSON.stringify(args)}</Fake>`;
@@ -78,6 +103,10 @@ class FakePlugin extends BasePlugin {
async onUnexpectedShutdown(driver, cause) {
FakePlugin._unexpectedData = `Session ended because ${cause}`;
}
+
+ async execute(next, driver, script, args) {
+ return await this.executeMethod(next, driver, script, args);
+ }
}
export {FakePlugin};

test(appium): add e2e tests for plugin use of executeMethod(Map)