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

Commit 603b3f3

Browse files
authored
Merge pull request #21 from ventuno/ftr-support-custom-devtools-cmds-2
Support custom devtools server commands
2 parents 60b0f78 + ed25619 commit 603b3f3

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

lib/command_definitions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,8 @@ export let rotationGesture = new CommandDefinition(
146146
});
147147
export let shakeDevice =
148148
new CommandDefinition<void>('shakeDevice', [], 'POST', 'appium/device/shake');
149+
export let sendChromiumCommand = new CommandDefinition<void>(
150+
'sendChromiumCommand', ['cmd', 'params'], 'POST', '/chromium/send_command');
151+
export let sendChromiumCommandAndGetResult = new CommandDefinition<Object>(
152+
'sendChromiumCommandAndGetResult', ['cmd', 'params'], 'POST',
153+
'/chromium/send_command_and_get_result');

lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ export interface ExtendedWebDriver extends WebDriver {
141141

142142
// See https://github.com/webdriverio/webdriverio/blob/v4.6.1/lib/protocol/shake
143143
shakeDevice: () => wdpromise.Promise<void>;
144+
145+
sendChromiumCommand: (cmd: string, params: Object) => wdpromise.Promise<void>;
146+
147+
sendChromiumCommandAndGetResult: (cmd: string, params: Object) => wdpromise.Promise<Object>;
144148
}
145149

146150
export function extend(baseDriver: WebDriver, fallbackGracefully = false): ExtendedWebDriver {

spec/command_tests/table_spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ describe('table tests', () => {
6363
openDeviceNotifications: {},
6464
rotationGesture: [{params: {x: 0, y: 0, duration: 1, rotation: 180, touchCount: 2}},
6565
{args: [1,2,3,90,5], params: {x: 1, y: 2, duration: 3, rotation: 90, touchCount: 5}}],
66-
shakeDevice: {}
66+
shakeDevice: {},
67+
sendChromiumCommand: {args: ['DOM.enable', {}]},
68+
sendChromiumCommandAndGetResult: {args: ['DOM.enable', {}]}
6769
}
6870
function runTestcase(commandName: string) {
6971
let itName = 'should correctly call "' + commandName + '"';

spec/mock-server/commands/chromium.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Custom chromium commands
3+
*
4+
* In this file we define all the custom commands which are part of the chromium API but will probably
5+
* never be part of the webdriver spec or JsonWireProtocol.
6+
*/
7+
8+
import {Command} from 'selenium-mock';
9+
import {ChromiumCommandList} from '../interfaces';
10+
import {noopFactory as noop} from './helpers';
11+
12+
export let chromium = {
13+
sendChromiumCommand: noop('chromium/send_command'),
14+
sendChromiumCommandAndGetResult: noop('chromium/send_command_and_get_result')
15+
} as ChromiumCommandList;
16+

spec/mock-server/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {Command} from 'selenium-mock';
66
import {SessionCommandList, ElementCommandList, Session} from '../interfaces';
77
import {noopFactory as noop, getterFactory as getter, setterFactory as setter, constFactory} from './helpers';
88
import {appium} from './appium';
9+
import {chromium} from './chromium';
910
import {storageFactory} from './storage';
1011

1112
export let session = {
1213
element: {} as ElementCommandList,
1314
sessionStorage: storageFactory('session'),
1415
localStorage: storageFactory('local'),
1516
appium: appium,
17+
chromium: chromium,
1618
} as SessionCommandList;
1719

1820
session.currentContext = getter('context', 'currentContext');

spec/mock-server/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export interface AppiumCommandList extends CommandList {
9393
device: AppiumDeviceCommandList;
9494
}
9595

96+
export interface ChromiumCommandList extends CommandList {
97+
sendChromiumCommand: Command<Session>;
98+
sendChromiumCommandAndGetResult: Command<Session>;
99+
}
100+
96101
// Commands which run against a particular webdriver session (as opposed to the whole server).
97102
export interface SessionCommandList extends CommandList {
98103
currentContext: Command<Session>;
@@ -124,4 +129,5 @@ export interface SessionCommandList extends CommandList {
124129
sessionStorage: StorageCommandList;
125130
localStorage: StorageCommandList;
126131
appium: AppiumCommandList;
132+
chromium: ChromiumCommandList;
127133
}

0 commit comments

Comments
 (0)