Files
appium/test/protocol/fake-driver.js
T
greenkeeper[bot] 4eab674f92 Update eslint-config-appium to the latest version 🚀 (#295)
* chore(package): update eslint-config-appium to version 4.0.1

* chore: fix linting
2019-01-07 13:11:57 -06:00

142 lines
2.7 KiB
JavaScript

/* eslint-disable require-await */
import { errors, BaseDriver } from '../..';
import _ from 'lodash';
import UUID from 'uuid-js';
class FakeDriver extends BaseDriver {
constructor () {
super();
this.protocol = BaseDriver.DRIVER_PROTOCOL.MJSONWP;
this.sessionId = null;
this.jwpProxyActive = false;
}
sessionExists (sessionId) {
if (!sessionId) {
return false;
}
return sessionId === this.sessionId;
}
driverForSession (/*sessionId*/) {
return this;
}
async createSession (desiredCapabilities, requiredCapabilities, capabilities) {
// Use a counter to make sure each session has a unique id
this.sessionId = `fakeSession_${UUID.create().hex}`;
if (capabilities) {
return [this.sessionId, capabilities];
} else {
this.desiredCapabilities = desiredCapabilities;
this.requiredCapabilities = requiredCapabilities || {};
return [this.sessionId, _.extend({}, desiredCapabilities, requiredCapabilities)];
}
}
async executeCommand (cmd, ...args) {
if (!this[cmd]) {
throw new errors.NotYetImplementedError();
}
if (cmd === 'createSession') {
this.protocol = BaseDriver.determineProtocol.apply(null, args);
}
return await this[cmd](...args);
}
async deleteSession () {
this.jwpProxyActive = false;
this.sessionId = null;
}
async getStatus () {
return "I'm fine";
}
async setUrl (url) {
return `Navigated to: ${url}`;
}
async getUrl () {
return 'http://foobar.com';
}
async back (sessionId) {
return sessionId;
}
async forward () {}
async refresh () {
throw new Error('Too Fresh!');
}
async getSession () {
throw new errors.NoSuchDriverError();
}
async click (elementId, sessionId) {
return [elementId, sessionId];
}
async implicitWait (ms) {
return ms;
}
async clickCurrent (button) {
return button;
}
async setNetworkConnection (type) {
return type;
}
async moveTo (element, xOffset, yOffset) {
return [element, xOffset, yOffset];
}
async getText () {
return '';
}
async getAttribute (attr, elementId, sessionId) {
return [attr, elementId, sessionId];
}
async setValue (value, elementId) {
return [value, elementId];
}
async performTouch (...args) {
return args;
}
async setFrame (frameId) {
return frameId;
}
async removeApp (app) {
return app;
}
async receiveAsyncResponse () {
// this is here to test a failing command that does not throw an error
return {status: 13, value: 'Mishandled Driver Error'};
}
proxyActive (/*sessionId*/) {
return false;
}
getProxyAvoidList (/*sessionId*/) {
return [];
}
canProxy (/*sessionId*/) {
return false;
}
}
export { FakeDriver };