Add login test helper. Use the new login test helper in targets test

This commit is contained in:
Carlos Alcaide Corvo committed 2021-10-22 08:43:03 -07:00
1 parent ace9e2a3ae
commit dbadbff1b9
2 files changed
+36 -22

No files matched your search

+9 -20
View File
@@ -25,33 +25,22 @@ test.afterEach(async () => {
electronApp = null; // Not sure we should do this.
});
test.describe('Targets end to end test suite', async () => {
test.describe.only('Targets end to end test suite', async () => {
test('Connects to a target', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
// Override local storage origin
await boundaryWindow.evaluate(() =>
window.localStorage.setItem('desktop:origin', null)
);
const originValue = 'http://localhost:9200';
const authLoginNameValue = 'admin';
const authLoginPasswordValue = 'password';
// Fill the origin input
await boundaryWindow.waitForSelector('[name=host]');
await boundaryWindow.fill('[name=host]', originValue);
// Click the submit button
await boundaryWindow.waitForSelector('button[type="submit"]');
await helpers.click(boundaryWindow, 'button[type="submit"]');
// Fill user & password
await boundaryWindow.fill('[name="identification"]', authLoginNameValue);
await boundaryWindow.fill('[name="password"]', authLoginPasswordValue);
// Click submit
await boundaryWindow.waitForSelector('button[type="submit"]');
await helpers.click(boundaryWindow, 'button[type="submit"]');
// Perform the login
await helpers.login(
boundaryWindow,
'http://localhost:9200',
'admin',
'password'
);
// Check we are in Targets
await boundaryWindow.waitForURL('**/#/scopes/global/projects/targets');
+27 -2
View File
@@ -46,9 +46,34 @@ exports.returnExecutablePath = (platform, arch) => {
/**
* Performs a click with a workarouind due to an error with plain playwright click.
* More info about the issue here: https://github.com/microsoft/playwright/issues/1808
* @param {*} appWindow The current electron window.
* @param {*} selector The DOM element selector.
* @param {object} appWindow The electron window to perform the action.
* @param {string} selector The DOM element selector.
*/
exports.click = async (appWindow, selector) => {
await appWindow.$eval(selector, (element) => element.click());
};
/**
* Performs login on the app window provided with the credentials provided.
* @param {object} appWindow The electron window to perform the action.
* @param {string} origin URL origin to set.
* @param {string} username Username to login.
* @param {string} password Password to login.
*/
exports.login = async (appWindow, origin, username, password) => {
// Fill the origin input
await appWindow.waitForSelector('[name=host]');
await appWindow.fill('[name=host]', origin);
// Click the set origin submit button
await appWindow.waitForSelector('button[type="submit"]');
await this.click(appWindow, 'button[type="submit"]');
// Fill user & password
await appWindow.fill('[name="identification"]', username);
await appWindow.fill('[name="password"]', password);
// Click submit
await appWindow.waitForSelector('button[type="submit"]');
await this.click(appWindow, 'button[type="submit"]');
};