fix: integration tests with the new design

This commit is contained in:
Audric Ackermann 2022-08-18 16:53:47 +10:00
parent 7bbbc74fa8
commit cac63a7edb
24 changed files with 70 additions and 84 deletions

View File

@ -1,5 +1,6 @@
// tslint:disable-next-line: no-implicit-dependencies
import { PlaywrightTestConfig } from '@playwright/test';
import { toNumber } from 'lodash';
const config: PlaywrightTestConfig = {
timeout: 350000,
@ -10,7 +11,7 @@ const config: PlaywrightTestConfig = {
outputDir: './ts/test/automation/test-results',
retries: 1,
repeatEach: 1,
workers: 1,
workers: toNumber(process.env.PLAYWRIGHT_WORKER_COUNT) || 1,
reportSlowTests: null,
};

View File

@ -1,11 +1,9 @@
import { _electron, expect, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { openAppsAndNewUsers } from './setup/new_user';
import { sendNewMessage } from './send_message';
import { clickOnMatchingText, clickOnTestIdWithText, waitForTestIdWithText } from './utils';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));
@ -21,7 +19,8 @@ test('Block User', async () => {
await sendNewMessage(windowA, userB.sessionid, `A -> B: ${Date.now()}`);
await sendNewMessage(windowB, userA.sessionid, `B -> A: ${Date.now()}`);
// Check to see if User B is a contact
await clickOnTestIdWithText(windowA, 'contact-section');
await clickOnTestIdWithText(windowA, 'new-conversation-button');
await waitForTestIdWithText(windowA, 'module-conversation__user__profile-name', userB.userName);
//Click on three dots menu

View File

@ -1,12 +1,11 @@
import { _electron, expect, Page, test } from '@playwright/test';
import { openAppAndWait } from './setup/open';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { newUser } from './setup/new_user';
import { clickOnTestIdWithText, waitForTestIdWithText } from './utils';
let window: Page | undefined;
test.beforeEach(cleanUpOtherTest);
test.afterEach(async () => {
if (window) {
await forceCloseAllWindows([window]);
@ -14,7 +13,7 @@ test.afterEach(async () => {
});
test('Change profile picture/avatar', async () => {
window = await openAppAndWait('1');
window = await openAppAndWait(`1`);
await newUser(window, 'userA');
// Open profile

View File

@ -1,11 +1,10 @@
import { _electron, expect, Page, test } from '@playwright/test';
import { newUser } from './setup/new_user';
import { openAppAndWait } from './setup/open';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { clickOnTestIdWithText, typeIntoInput } from './utils';
let window: Page | undefined;
test.beforeEach(cleanUpOtherTest);
test.afterEach(async () => {
if (window) {
await forceCloseAllWindows([window]);
@ -14,7 +13,7 @@ test.afterEach(async () => {
test('Change username', async () => {
// Open App
window = await openAppAndWait('1');
window = await openAppAndWait(`1`);
// Create user
await newUser(window, 'userA');
// Open Profile

View File

@ -2,11 +2,10 @@ import { _electron, Page, test } from '@playwright/test';
import { newUser } from './setup/new_user';
import { openAppAndWait } from './setup/open';
import { sleepFor } from '../../session/utils/Promise';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { clickOnMatchingText, clickOnTestIdWithText, waitForTestIdWithText } from './utils';
let window: Page | undefined;
test.beforeEach(cleanUpOtherTest);
test.afterEach(async () => {
if (window) {
await forceCloseAllWindows([window]);
@ -14,7 +13,7 @@ test.afterEach(async () => {
});
test('Create User', async () => {
// Launch Electron app.
window = await openAppAndWait('1');
window = await openAppAndWait(`1`);
// // Create User
const userA = await newUser(window, 'userA');
// Open profile tab

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { openAppsAndNewUsers, openAppsNoNewUsers } from './setup/new_user';
import { sendNewMessage } from './send_message';
import {
@ -12,8 +12,6 @@ import {
} from './utils';
import { sleepFor } from '../../session/utils/Promise';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));
@ -65,8 +63,8 @@ test('Delete account from swarm', async () => {
throw e;
}
}
await clickOnTestIdWithText(restoringWindow, 'contact-section');
// Expect contacts list to be empty
await clickOnTestIdWithText(restoringWindow, 'new-conversation-button'); // Expect contacts list to be empty
const errorDesc2 = 'Should not be found';
try {

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { messageSent } from './message';
import { openAppsAndNewUsers } from './setup/new_user';
import { sendNewMessage } from './send_message';
@ -11,7 +11,6 @@ import {
waitForTestIdWithText,
} from './utils';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { messageSent } from './message';
import { openAppsAndNewUsers } from './setup/new_user';
import { sendNewMessage } from './send_message';
@ -13,8 +13,6 @@ import {
const testGroupName = 'Test Group Name';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));
@ -32,8 +30,9 @@ test('Create group', async () => {
sendNewMessage(windowC, userA.sessionid, `C -> A: ${Date.now()}`),
]);
// Click new closed group tab
await clickOnMatchingText(windowA, 'New Closed Group');
// Enter group name
await clickOnTestIdWithText(windowA, 'new-conversation-button');
await clickOnTestIdWithText(windowA, 'chooser-new-group'); // Enter group name
await typeIntoInput(windowA, 'new-closed-group-name', testGroupName);
// Select user B
await clickOnMatchingText(windowA, userB.userName);

View File

@ -1,5 +1,5 @@
import { _electron, expect, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
// import { recoverFromSeed } from './setup/recovery_using_seed';
import {
clickOnMatchingText,
@ -13,8 +13,6 @@ import { renameGroup } from './rename_group';
import { leaveGroup } from './leave_group';
import { createGroup } from './setup/create_group';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { openAppsNoNewUsers } from './setup/new_user';
import { sendNewMessage } from './send_message';
import { logIn } from './setup/log_in';
@ -11,8 +11,6 @@ import {
testUser,
} from './setup/test_user';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -1,10 +1,8 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { linkedDevice } from './setup/linked_device';
import { clickOnTestIdWithText, typeIntoInput, waitForTestIdWithText } from './utils';
test.beforeEach(cleanUpOtherTest);
const windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));
@ -12,13 +10,13 @@ test('linking device', async () => {
const { windowA1, windowA2, userA } = await linkedDevice();
windows.push(windowA1, windowA2);
await clickOnTestIdWithText(windowA2, 'leftpane-primary-avatar');
await clickOnTestIdWithText(windowA1, 'leftpane-primary-avatar');
// Verify Username
await waitForTestIdWithText(windowA2, 'your-profile-name', userA.userName);
await waitForTestIdWithText(windowA1, 'your-profile-name', userA.userName);
// Verify Session ID
await waitForTestIdWithText(windowA2, 'your-session-id', userA.sessionid);
await waitForTestIdWithText(windowA1, 'your-session-id', userA.sessionid);
// exit profile module
await clickOnTestIdWithText(windowA2, 'modal-close-button');
await clickOnTestIdWithText(windowA1, 'modal-close-button');
// You're almost finished isn't displayed
const errorDesc = 'Should not be found';
try {
@ -46,6 +44,6 @@ test('linking device', async () => {
// Click on profile settings in window B
await clickOnTestIdWithText(windowA2, 'leftpane-primary-avatar');
// Verify username has changed to new username
await waitForTestIdWithText(windowA2, 'your-profile-name', userA.userName);
await waitForTestIdWithText(windowA2, 'your-profile-name', newUsername);
// Check message is deleting on both devices
});

View File

@ -1,10 +1,8 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { clickOnTestIdWithText, typeIntoInput, waitForTestIdWithText } from './utils';
import { createGroup } from './setup/create_group';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -1,11 +1,10 @@
import { _electron, Page, test } from '@playwright/test';
import { sendNewMessage } from './send_message';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { openAppsAndNewUsers } from './setup/new_user';
import { clickOnTestIdWithText, waitForMatchingText, waitForTestIdWithText } from './utils';
const testMessage = 'A -> B';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { sendNewMessage } from './send_message';
import { openAppsAndNewUsers } from './setup/new_user';
@ -7,7 +7,6 @@ import { clickOnTestIdWithText, waitForTestIdWithText } from './utils';
const testMessage = 'A -> B';
const testReply = 'B -> A';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));
@ -25,10 +24,10 @@ test('Send message to new contact', async () => {
await sendNewMessage(windowB, userA.sessionid, `${testReply}${Date.now()}`);
// Navigate to contacts tab in User B's window
await clickOnTestIdWithText(windowA, 'contact-section');
await clickOnTestIdWithText(windowA, 'new-conversation-button');
await windowA.waitForTimeout(2000);
await waitForTestIdWithText(windowB, 'module-conversation__user__profile-name', userA.userName);
// Navigate to contacts tab in User A's window
await clickOnTestIdWithText(windowA, 'contact-section');
await clickOnTestIdWithText(windowA, 'new-conversation-button');
});

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { newUser } from './setup/new_user';
import { openAppAndWait } from './setup/open';
import {
@ -11,7 +11,6 @@ import {
} from './utils';
let window: Page | undefined;
test.beforeEach(cleanUpOtherTest);
test.afterEach(async () => {
if (window) {
await forceCloseAllWindows([window]);
@ -24,7 +23,7 @@ const newTestPassword = '789101112';
test.describe('Password checks', () => {
test('Set Password', async () => {
// open Electron
window = await openAppAndWait('1');
window = await openAppAndWait(`1`);
// Create user
await newUser(window, 'userA');
// Click on settings tab
@ -80,7 +79,7 @@ test.describe('Password checks', () => {
});
test('Wrong password', async () => {
// Check if incorrect password works
window = await openAppAndWait('1');
window = await openAppAndWait(`1`);
// Create user
await newUser(window, 'userA');
// Click on settings tab

View File

@ -4,6 +4,7 @@ import { clickOnTestIdWithText, typeIntoInput } from './utils';
export const sendNewMessage = async (window: Page, sessionid: string, message: string) => {
await clickOnTestIdWithText(window, 'new-conversation-button');
await clickOnTestIdWithText(window, 'chooser-new-conversation-button');
// Enter session ID of USER B
await typeIntoInput(window, 'new-session-conversation', sessionid);
// click next

View File

@ -2,6 +2,7 @@ import { _electron, Page } from '@playwright/test';
import { readdirSync, rmdirSync } from 'fs-extra';
import { dirname, join } from 'path';
import { MULTI_PREFIX, NODE_ENV, openElectronAppOnly } from './open';
// tslint:disable: no-console
const getDirectoriesOfSessionDataPath = (source: string) =>
readdirSync(source, { withFileTypes: true })
@ -9,13 +10,23 @@ const getDirectoriesOfSessionDataPath = (source: string) =>
.map(dirent => dirent.name)
.filter(n => n.startsWith(`Session-${NODE_ENV}-${MULTI_PREFIX}`));
let alreadyCleaned = false;
export const cleanUpOtherTest = async () => {
if (alreadyCleaned) {
return;
}
alreadyCleaned = true;
const electronApp = await openElectronAppOnly('start');
const appPath = await electronApp.evaluate(async ({ app }) => {
return app.getPath('userData');
});
const window = await electronApp.firstWindow();
await window.close();
if (alreadyCleaned) {
return;
}
if (!appPath.length) {
throw new Error('appDataPath unset');
}
@ -24,7 +35,11 @@ export const cleanUpOtherTest = async () => {
if (!parentFolderOfAllDataPath || parentFolderOfAllDataPath.length < 20) {
throw new Error('parentFolderOfAllDataPath not found or invalid');
}
console.info('cleaning other tests leftovers...');
if (alreadyCleaned) {
return;
}
const allAppDataPath = getDirectoriesOfSessionDataPath(parentFolderOfAllDataPath);
allAppDataPath.map(folder => {
if (!appPath) {
@ -33,6 +48,7 @@ export const cleanUpOtherTest = async () => {
const pathToRemove = join(parentFolderOfAllDataPath, folder);
rmdirSync(pathToRemove, { recursive: true });
});
console.info('...done');
};
export const forceCloseAllWindows = async (windows: Array<Page>) => {

View File

@ -30,7 +30,8 @@ export const createGroup = async (groupName: string) => {
// wait for user C to be contact before moving to create group
// Create group with existing contact and session ID (of non-contact)
// Click new closed group tab
await clickOnMatchingText(windowA, 'New Closed Group');
await clickOnTestIdWithText(windowA, 'new-conversation-button');
await clickOnTestIdWithText(windowA, 'chooser-new-group');
// Enter group name
await typeIntoInput(windowA, 'new-closed-group-name', groupName);
// Select user B

View File

@ -1,5 +1,6 @@
import { _electron } from 'playwright-core';
import { openAppsAndNewUsers, openAppsNoNewUsers } from './new_user';
import { logIn } from '../setup/log_in';
export async function linkedDevice() {
const windowLoggedIn = await openAppsAndNewUsers(1);
@ -8,5 +9,7 @@ export async function linkedDevice() {
const [userA] = users;
const [windowA2] = await openAppsNoNewUsers(1);
await logIn(windowA2, userA.recoveryPhrase);
return { windowA1, windowA2, userA };
}

View File

@ -1,6 +1,7 @@
import { _electron, Page } from '@playwright/test';
import { _electron, Page, test } from '@playwright/test';
import _ from 'lodash';
import { clickOnMatchingText, clickOnTestIdWithText, typeIntoInput } from '../utils';
import { clickOnMatchingText, typeIntoInput } from '../utils';
import { cleanUpOtherTest } from './beforeEach';
import { openAppAndWait } from './open';
const multisAvailable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
@ -10,6 +11,9 @@ export type UserLoggedInType = {
recoveryPhrase: string;
};
test.beforeAll(cleanUpOtherTest);
test.afterAll(cleanUpOtherTest);
export const newUser = async (window: Page, userName: string): Promise<UserLoggedInType> => {
// Create User
await clickOnMatchingText(window, 'Create Session ID');
@ -64,27 +68,7 @@ export async function openAppsNoNewUsers(windowToCreate: number) {
const multisToUse = multisAvailable.slice(0, windowToCreate);
return Promise.all(
[...multisToUse].map(async m => {
return openAppAndWait(m);
return openAppAndWait(`${m}`);
})
);
}
export async function existingUser() {
const recoveryPhraseTest =
'pinched total ongoing sushi etched rest gone long oilfield incur code grunt code';
const newUsername = 'new-username';
// const sessionIDTest = '05560802be231abc2fbaa860f09da4c2f20dafa4e5f560f77d61c5f587ef2c741f';
// const contactOne = 'Fish';
// const contactTwo = 'Dragon';
// const contactThree = 'Whale';
// const contactFour = 'Gopher';
const [windowA1] = await openAppsNoNewUsers(1);
await clickOnTestIdWithText(windowA1, 'restore-using-recovery');
await typeIntoInput(windowA1, 'recovery-phrase-input', recoveryPhraseTest);
await typeIntoInput(windowA1, 'display-name-input', newUsername);
await clickOnTestIdWithText(windowA1, 'continue-session-button');
// await clickOnTestIdWithText(windowA1, 'leftpane-primary-avatar');
// const sessionIDTest = await waitForTestIdWithText(windowA1, 'your-session-id');
return existingUser;
}

View File

@ -6,11 +6,11 @@ export const NODE_ENV = 'production';
export const MULTI_PREFIX = 'test-integration-testnet-';
export const openElectronAppOnly = async (multi: string) => {
process.env.NODE_APP_INSTANCE = `${MULTI_PREFIX}-${multi}`;
process.env.NODE_APP_INSTANCE = `${MULTI_PREFIX}-${Date.now()}-${multi}`;
process.env.NODE_ENV = NODE_ENV;
// console.warn(' NODE_ENV', process.env.NODE_ENV);
// console.warn(' NODE_APP_INSTANCE', process.env.NODE_APP_INSTANCE);
console.warn(' NODE_ENV', process.env.NODE_ENV);
console.warn(' NODE_APP_INSTANCE', process.env.NODE_APP_INSTANCE);
const electronApp = await _electron.launch({
args: [join(getAppRootPath(), 'ts', 'mains', 'main_node.js')],
});

View File

@ -1,9 +1,8 @@
import { _electron, expect, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { openAppsAndNewUsers } from './setup/new_user';
import { clickOnTestIdWithText } from './utils';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -1,5 +1,5 @@
import { _electron, Page, test } from '@playwright/test';
import { cleanUpOtherTest, forceCloseAllWindows } from './setup/beforeEach';
import { forceCloseAllWindows } from './setup/beforeEach';
import { openAppsAndNewUsers } from './setup/new_user';
import { sendNewMessage } from './send_message';
import {
@ -12,7 +12,6 @@ import {
const testMessage = 'A -> B: ';
const testReply = 'B -> A: ';
test.beforeEach(cleanUpOtherTest);
let windows: Array<Page> = [];
test.afterEach(() => forceCloseAllWindows(windows));

View File

@ -36,6 +36,7 @@ export async function clickOnTestIdWithText(window: Page, dataTestId: string, te
}
const builtSelector = `css=[data-testid=${dataTestId}]`;
await window.waitForSelector(builtSelector);
return window.click(builtSelector);
}