kibana/test/functional/services/remote/remote.js
John Dorlus a31ec148f4
Adding firefox to test suite (#17195)
* Created general driver to accept an argument select the driver to run.

* Added environment variable for driver, changed package.json to use custim leadfoot, and made changes to browserdriver to use any driver.

* Made changes per PR.

* Fixed all nits.
2018-03-16 23:05:10 -04:00

57 lines
1.9 KiB
JavaScript

import { initLeadfootCommand } from './leadfoot_command';
import { createRemoteInterceptors } from './interceptors';
import { BrowserDriverApi } from './browser_driver_api';
export async function RemoteProvider({ getService }) {
const lifecycle = getService('lifecycle');
const config = getService('config');
const log = getService('log');
const possibleBrowsers = ['chrome', 'firefox'];
const browserType = process.env.TEST_BROWSER_TYPE || 'chrome';
if (!possibleBrowsers.includes(browserType)) {
throw new Error(`Unexpected TEST_BROWSER_TYPE "${browserType}". Valid options are ` + possibleBrowsers.join(','));
}
const browserDriverApi = await BrowserDriverApi.factory(log, config.get(browserType + 'driver.url'), browserType);
lifecycle.on('cleanup', async () => await browserDriverApi.stop());
await browserDriverApi.start();
const { command } = await initLeadfootCommand({ log, browserDriverApi: browserDriverApi });
const interceptors = createRemoteInterceptors(command);
log.info('Remote initialized');
lifecycle.on('beforeTests', async () => {
// hard coded default, can be overriden per suite using `remote.setWindowSize()`
// and will be automatically reverted after each suite
await command.setWindowSize(1600, 1000);
});
const windowSizeStack = [];
lifecycle.on('beforeTestSuite', async () => {
windowSizeStack.unshift(await command.getWindowSize());
});
lifecycle.on('afterTestSuite', async () => {
const { width, height } = windowSizeStack.shift();
await command.setWindowSize(width, height);
});
return new Proxy({}, {
get(obj, prop) {
if (prop === 'then' || prop === 'catch' || prop === 'finally') {
// prevent the remote from being treated like a promise by
// hiding it's promise-like properties
return undefined;
}
if (interceptors.hasOwnProperty(prop)) {
return interceptors[prop];
}
return command[prop];
}
});
}