Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Support custom devtools server commands #21

Merged
merged 7 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions lib/command_definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ export let rotationGesture = new CommandDefinition(
});
export let shakeDevice =
new CommandDefinition<void>('shakeDevice', [], 'POST', 'appium/device/shake');
export let sendChromiumCommand = new CommandDefinition<void>(
'sendChromiumCommand', ['cmd', 'params'], 'POST', '/chromium/send_command');
export let sendChromiumCommandAndGetResult = new CommandDefinition<Object>(
'sendChromiumCommandAndGetResult', ['cmd', 'params'], 'POST',
'/chromium/send_command_and_get_result');
4 changes: 4 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export interface ExtendedWebDriver extends WebDriver {

// See https://github.com/webdriverio/webdriverio/blob/v4.6.1/lib/protocol/shake
shakeDevice: () => wdpromise.Promise<void>;

sendChromiumCommand: (cmd: string, params: Object) => wdpromise.Promise<void>;

sendChromiumCommandAndGetResult: (cmd: string, params: Object) => wdpromise.Promise<Object>;
}

export function extend(baseDriver: WebDriver, fallbackGracefully = false): ExtendedWebDriver {
Expand Down
4 changes: 3 additions & 1 deletion spec/command_tests/table_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ describe('table tests', () => {
openDeviceNotifications: {},
rotationGesture: [{params: {x: 0, y: 0, duration: 1, rotation: 180, touchCount: 2}},
{args: [1,2,3,90,5], params: {x: 1, y: 2, duration: 3, rotation: 90, touchCount: 5}}],
shakeDevice: {}
shakeDevice: {},
sendChromiumCommand: {args: ['DOM.enable', {}]},
sendChromiumCommandAndGetResult: {args: ['DOM.enable', {}]}
}
function runTestcase(commandName: string) {
let itName = 'should correctly call "' + commandName + '"';
Expand Down
16 changes: 16 additions & 0 deletions spec/mock-server/commands/chromium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Custom chromium commands
*
* In this file we define all the custom commands which are part of the chromium API but will probably
* never be part of the webdriver spec or JsonWireProtocol.
*/

import {Command} from 'selenium-mock';
import {ChromiumCommandList} from '../interfaces';
import {noopFactory as noop} from './helpers';

export let chromium = {
sendChromiumCommand: noop('chromium/send_command'),
sendChromiumCommandAndGetResult: noop('chromium/send_command_and_get_result')
} as ChromiumCommandList;

2 changes: 2 additions & 0 deletions spec/mock-server/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {Command} from 'selenium-mock';
import {SessionCommandList, ElementCommandList, Session} from '../interfaces';
import {noopFactory as noop, getterFactory as getter, setterFactory as setter, constFactory} from './helpers';
import {appium} from './appium';
import {chromium} from './chromium';
import {storageFactory} from './storage';

export let session = {
element: {} as ElementCommandList,
sessionStorage: storageFactory('session'),
localStorage: storageFactory('local'),
appium: appium,
chromium: chromium,
} as SessionCommandList;

session.currentContext = getter('context', 'currentContext');
Expand Down
6 changes: 6 additions & 0 deletions spec/mock-server/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export interface AppiumCommandList extends CommandList {
device: AppiumDeviceCommandList;
}

export interface ChromiumCommandList extends CommandList {
sendChromiumCommand: Command<Session>;
sendChromiumCommandAndGetResult: Command<Session>;
}

// Commands which run against a particular webdriver session (as opposed to the whole server).
export interface SessionCommandList extends CommandList {
currentContext: Command<Session>;
Expand Down Expand Up @@ -124,4 +129,5 @@ export interface SessionCommandList extends CommandList {
sessionStorage: StorageCommandList;
localStorage: StorageCommandList;
appium: AppiumCommandList;
chromium: ChromiumCommandList;
}