mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
test: Spectron (Initial commit) (#838)
* Spectron - Initial commit * Spectron - Only run unit tests on travis * Spectron - Update npm script to copy config and refactor * Spectron - Update readme * Spectron - update test cases * Spectron - Merge upstream Spectron * Spectron - Update spectron to 10.0.0 and fix issues * Spectron - rename travis file * Spectron - install linux specific dependency * Spectron - Fix indentation * Spectron - Fix indentation * Spectron - Remove unwanted script * fix typo
This commit is contained in:
50
spectron/fixtures/robot-actions.ts
Normal file
50
spectron/fixtures/robot-actions.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as robot from 'robotjs';
|
||||
import { isMac } from '../../src/common/env';
|
||||
import { Timeouts } from './spectron-setup';
|
||||
|
||||
class RobotActions {
|
||||
|
||||
constructor() {
|
||||
robot.setKeyboardDelay(Timeouts.oneSec);
|
||||
robot.setMouseDelay(Timeouts.oneSec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes window via keyboard action
|
||||
*/
|
||||
public closeWindow(): void {
|
||||
const modifier = isMac ? [ 'command' ] : [ 'control' ];
|
||||
robot.keyToggle('w', 'down', modifier);
|
||||
robot.keyToggle('w', 'up', modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the application fullscreen via keyboard
|
||||
*/
|
||||
public toggleFullscreen(): void {
|
||||
robot.keyToggle('f', 'down', [ 'command', 'control' ]);
|
||||
robot.keyToggle('f', 'up', [ 'command', 'control' ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click the App menu
|
||||
*/
|
||||
public clickAppMenu(point?: Electron.Point): void {
|
||||
if (isMac) {
|
||||
robot.moveMouse(83, 14);
|
||||
robot.mouseClick();
|
||||
} else {
|
||||
if (!point) {
|
||||
throw new Error('browser window points are required');
|
||||
}
|
||||
robot.moveMouse(point.x + 10, point.y + 14);
|
||||
robot.mouseClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const robotActions = new RobotActions();
|
||||
|
||||
export {
|
||||
robotActions,
|
||||
};
|
||||
97
spectron/fixtures/spectron-setup.ts
Normal file
97
spectron/fixtures/spectron-setup.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import * as path from 'path';
|
||||
import { Application, BasicAppSettings } from 'spectron';
|
||||
|
||||
export const podUrl = 'https://corporate.symphony.com';
|
||||
|
||||
export enum Timeouts {
|
||||
halfSec = 500,
|
||||
oneSec = 1000,
|
||||
threeSec = 3000,
|
||||
fiveSec = 5000,
|
||||
tenSec = 10000,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the electron executable path
|
||||
*/
|
||||
export const getElectronPath = (): string => {
|
||||
let electronPath = path.join(__dirname, '..', '..', '..', 'node_modules', '.bin', 'electron');
|
||||
if (process.platform === 'win32') {
|
||||
electronPath += '.cmd';
|
||||
}
|
||||
return electronPath;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the demo application html path
|
||||
*/
|
||||
export const getDemoFilePath = (): string => {
|
||||
return `file://${path.join(__dirname, '..', '..', '..', '/src/demo/index.html')}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns app init file
|
||||
*/
|
||||
export const getArgs = (): string[] => {
|
||||
return [ path.join(__dirname, '..', '..', '/src/app/init.js') ];
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the application
|
||||
* @param application
|
||||
*/
|
||||
export const stopApplication = async (application): Promise<Application | undefined> => {
|
||||
if (!application || !application.isRunning()) {
|
||||
return;
|
||||
}
|
||||
return await application.stop();
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts and returns the application instance
|
||||
* @param shouldLoadDemoApp {Boolean}
|
||||
* @param options {BasicAppSettings}
|
||||
*/
|
||||
export const startApplication = async (
|
||||
shouldLoadDemoApp: boolean = false,
|
||||
options: BasicAppSettings = {
|
||||
path: getElectronPath(),
|
||||
args: getArgs(),
|
||||
},
|
||||
): Promise<Application> => {
|
||||
// loads demo page correctly
|
||||
if (shouldLoadDemoApp && options.args) {
|
||||
options.args.push(`. --url=file://${getDemoFilePath()}`);
|
||||
}
|
||||
const application = new Application(options);
|
||||
await application.start();
|
||||
return application;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sleep function for tests that needs to wait
|
||||
* @param ms
|
||||
*/
|
||||
export const sleep = (ms) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads the url with try catch due to an issue in Spectron frame work
|
||||
* https://github.com/electron-userland/spectron/issues/493
|
||||
* @param app
|
||||
* @param url
|
||||
*/
|
||||
export const loadURL = async (app: Application, url: string): Promise<void> => {
|
||||
try {
|
||||
return await app.browserWindow.loadURL(url);
|
||||
} catch (error) {
|
||||
const errorIsNavigatedError: boolean = error.message.includes('Inspected target navigated or closed');
|
||||
|
||||
if (!errorIsNavigatedError) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user