Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/commands/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { errors } from 'appium/driver';

const WINDOWS_CONTEXT = 'NATIVE_APP';

export async function getContexts (): Promise<string[]> {
return [WINDOWS_CONTEXT];
}

export async function getCurrentContext (): Promise<string> {
return WINDOWS_CONTEXT;
}

export async function setContext (context: string) {
Comment thread
mykola-mokhnach marked this conversation as resolved.
Outdated
if (context !== WINDOWS_CONTEXT) {
throw new errors.NoSuchContextError();
Comment thread
mykola-mokhnach marked this conversation as resolved.
Outdated
}
}
7 changes: 7 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as gestureCommands from './commands/gestures';
import * as powershellCommands from './commands/powershell';
import * as recordScreenCommands from './commands/record-screen';
import * as touchCommands from './commands/touch';
import * as contextCommands from './commands/context';
import { POWER_SHELL_FEATURE } from './constants';
import { newMethodMap } from './method-map';
import { executeMethodMap } from './execute-method-map';
Expand All @@ -29,6 +30,8 @@ const NO_PROXY = [
['POST', new RegExp('^/session/[^/]+/appium/device/pull_file')],
['POST', new RegExp('^/session/[^/]+/appium/device/pull_folder')],
['GET', new RegExp('^/session/[^/]+/screenshot')],
['GET', new RegExp('^/session/[^/]+/contexts?')],
['POST', new RegExp('^/session/[^/]+/context')],
// Workarounds for
// - https://github.com/appium/appium/issues/15923
// - https://github.com/appium/appium/issues/16316
Expand Down Expand Up @@ -205,6 +208,10 @@ export class WindowsDriver extends BaseDriver {
stopRecordingScreen = recordScreenCommands.stopRecordingScreen;

performActions = touchCommands.performActions;

getContexts = contextCommands.getContexts;
getCurrentContext = contextCommands.getCurrentContext;
setContext = contextCommands.setContext;
}

export default WindowsDriver;
Expand Down
39 changes: 39 additions & 0 deletions test/e2e/commands/context-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { buildWdIoOptions } from '../helpers';
import { remote as wdio } from 'webdriverio';

describe('context', function () {
let chai;
/** @type {import('webdriverio').Browser} */
let driver;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);

driver = await wdio(buildWdIoOptions('Root'));
});

after(async function () {
try {
if (driver) {
await driver.deleteSession();
}
} finally {
driver = null;
}
});

it('should support context api', async function () {
(await driver.getAppiumContext()).should.equal('NATIVE_APP');
(await driver.getAppiumContexts()).should.eql(['NATIVE_APP']);
await driver.switchAppiumContext('NATIVE_APP');
});

it('should throw an error if invalid context', async function () {
await driver.switchAppiumContext('INVALID_CONTEXT').should.rejectedWith(/no such context/i);
});

});
13 changes: 13 additions & 0 deletions test/unit/driver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ describe('driver.js', function () {
driver.caps.cap.should.equal('foo');
});

describe('context simulation', function () {
it('should support context commands', async function () {
let driver = new WindowsDriver({ app: 'myapp'}, false);
(await driver.getCurrentContext()).should.equal('NATIVE_APP');
(await driver.getContexts()).should.eql(['NATIVE_APP']);
await driver.setContext('NATIVE_APP');
});
it('should throw an error if invalid context', async function () {
let driver = new WindowsDriver({ app: 'myapp'}, false);
await driver.setContext('INVALID_CONTEXT').should.rejected;
});
});

// TODO: Implement or delete
//it('should set the default context', async function () {
// let driver = new SelendroidDriver({}, false);
Expand Down