Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various stability fixes for E2E #5071

Merged
merged 9 commits into from
Jul 3, 2023
23 changes: 3 additions & 20 deletions e2e/backend.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,23 @@ import _ from 'lodash';
import semver from 'semver';

import { NavPage } from './pages/nav-page';
import { createDefaultSettings, getAlternateSetting, reportAsset, teardown } from './utils/TestUtils';
import { createDefaultSettings, getAlternateSetting, startRancherDesktop, teardown } from './utils/TestUtils';

import { Settings, ContainerEngine } from '@pkg/config/settings';
import fetch from '@pkg/utils/fetch';
import paths from '@pkg/utils/paths';
import { RecursivePartial, RecursiveKeys } from '@pkg/utils/typeUtils';

import type { ElectronApplication, BrowserContext, Page } from '@playwright/test';
import type { ElectronApplication, Page } from '@playwright/test';

test.describe.serial('KubernetesBackend', () => {
let electronApp: ElectronApplication;
let context: BrowserContext;
let page: Page;

test.beforeAll(async() => {
createDefaultSettings();

electronApp = await _electron.launch({
args: [
path.join(__dirname, '../'),
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item as the final option.
'--disable-dev-shm-usage',
'--no-modal-dialogs',
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(__filename, 'log'),
},
});
context = electronApp.context();

await context.tracing.start({ screenshots: true, snapshots: true });
electronApp = await startRancherDesktop(__filename, { mock: false });
page = await electronApp.firstWindow();
});

Expand Down
28 changes: 4 additions & 24 deletions e2e/credentials-server.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import fetch from 'node-fetch';

import { NavPage } from './pages/nav-page';
import {
createDefaultSettings, getFullPathForTool, reportAsset, retry, teardown, tool,
createDefaultSettings, getFullPathForTool, retry, startRancherDesktop, teardown, tool,
} from './utils/TestUtils';

import { ServerState } from '@pkg/main/commandServer/httpCommandServer';
import { spawnFile } from '@pkg/utils/childProcess';
import paths from '@pkg/utils/paths';

import type { ElectronApplication, BrowserContext, Page } from '@playwright/test';
import type { ElectronApplication, Page } from '@playwright/test';

let credStore = '';
let dockerConfigPath = '';
Expand Down Expand Up @@ -113,11 +113,9 @@ const testUnix = os.platform() === 'win32' ? test.skip : test;

describeWithCreds('Credentials server', () => {
let electronApp: ElectronApplication;
let context: BrowserContext;
let serverState: ServerState;
let authString: string;
let page: Page;
const appPath = path.join(__dirname, '../');
const curlCommand = os.platform() === 'win32' ? 'curl.exe' : 'curl';
const initialArgs: string[] = []; // Assigned once we have auth string on first use.

Expand Down Expand Up @@ -226,27 +224,9 @@ describeWithCreds('Credentials server', () => {
test.describe.configure({ mode: 'serial' });

test.beforeAll(async() => {
await tool('rdctl', 'factory-reset', '--verbose');
createDefaultSettings({ kubernetes: { enabled: false } });
electronApp = await _electron.launch({
args: [
appPath,
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item.
'--disable-dev-shm-usage',
'--no-modal-dialogs',
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(__filename, 'log'),
},
});
context = electronApp.context();

await context.tracing.start({
screenshots: true,
snapshots: true,
});
electronApp = await startRancherDesktop(__filename, { mock: false });
page = await electronApp.firstWindow();
});

Expand Down
3 changes: 0 additions & 3 deletions e2e/extensions.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* An E2E test is required to have access to the web page context.
*/

import fs from 'fs';
import os from 'os';
import path from 'path';

Expand Down Expand Up @@ -31,8 +30,6 @@ const rdctl = getFullPathForTool('rdctl');
// and we don't have to deal with unintended escape-sequence processing.
const execPath = process.execPath.replace(/\\/g, '/');

fs.mkdirSync(reportAsset(__filename, 'log'), { recursive: true });

const console = new Log(path.basename(__filename, '.ts'), reportAsset(__filename, 'log'));
const NAMESPACE = 'rancher-desktop-extensions';

Expand Down
16 changes: 14 additions & 2 deletions e2e/lockedFields.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ import path from 'path';
import { expect, test } from '@playwright/test';

import { NavPage } from './pages/nav-page';
import { createDefaultSettings, createUserProfile, startRancherDesktop, teardown } from './utils/TestUtils';
import {
createDefaultSettings, createUserProfile, startRancherDesktop, teardown, tool,
} from './utils/TestUtils';

import type { DeploymentProfileType } from '@pkg/config/settings';
import { readDeploymentProfiles } from '@pkg/main/deploymentProfiles';
import { spawnFile } from '@pkg/utils/childProcess';
import { reopenLogs } from '@pkg/utils/logging';

import type { ElectronApplication, BrowserContext, Page } from '@playwright/test';

Expand Down Expand Up @@ -68,6 +71,11 @@ test.describe('Locked fields', () => {

test.describe.configure({ mode: 'serial' });

test.beforeAll(async() => {
await tool('rdctl', 'factory-reset', '--verbose');
reopenLogs();
});

test.afterAll(async() => {
await restoreUserProfile();
});
Expand All @@ -89,7 +97,11 @@ test.describe('Locked fields', () => {
page = await electronApp.firstWindow();
});

test.afterAll(() => teardown(electronApp, __filename));
test.afterAll(async() => {
await teardown(electronApp, __filename);
await tool('rdctl', 'factory-reset', '--verbose');
reopenLogs();
});

test('should start up', async() => {
const navPage = new NavPage(page);
Expand Down
25 changes: 3 additions & 22 deletions e2e/main.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import path from 'path';

import { test, expect, _electron } from '@playwright/test';

import { NavPage } from './pages/nav-page';
import { createDefaultSettings, reportAsset, teardown } from './utils/TestUtils';
import { createDefaultSettings, startRancherDesktop, teardown } from './utils/TestUtils';

import type { ElectronApplication, BrowserContext, Page } from '@playwright/test';
import type { ElectronApplication, Page } from '@playwright/test';

let page: Page;

Expand All @@ -15,28 +13,11 @@ let page: Page;
* */
test.describe.serial('Main App Test', () => {
let electronApp: ElectronApplication;
let context: BrowserContext;

test.beforeAll(async() => {
createDefaultSettings();

electronApp = await _electron.launch({
args: [
path.join(__dirname, '../'),
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item as the final option.
'--disable-dev-shm-usage',
'--no-modal-dialogs',
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(__filename, 'log'),
},
});
context = electronApp.context();

await context.tracing.start({ screenshots: true, snapshots: true });
electronApp = await startRancherDesktop(__filename);
page = await electronApp.firstWindow();
});

Expand Down
46 changes: 16 additions & 30 deletions e2e/preferences.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os from 'os';
import path from 'path';

import { test, expect, _electron } from '@playwright/test';

import { NavPage } from './pages/nav-page';
import { PreferencesPage } from './pages/preferences';
import { createDefaultSettings, reportAsset, teardown } from './utils/TestUtils';
import { createDefaultSettings, startRancherDesktop, teardown, tool } from './utils/TestUtils';

import type { ElectronApplication, BrowserContext, Page } from '@playwright/test';
import { reopenLogs } from '@pkg/utils/logging';

import type { ElectronApplication, Page } from '@playwright/test';

let page: Page;

Expand All @@ -17,45 +18,30 @@ let page: Page;
* */
test.describe.serial('Main App Test', () => {
let electronApp: ElectronApplication;
let context: BrowserContext;
let preferencesWindow: Page;

test.beforeAll(async() => {
createDefaultSettings();

electronApp = await _electron.launch({
args: [
path.join(__dirname, '../'),
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item as the final option.
'--disable-dev-shm-usage',
'--no-modal-dialogs',
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(__filename, 'log'),
RD_MOCK_BACKEND: '1',
},
});
context = electronApp.context();

await context.tracing.start({ screenshots: true, snapshots: true });
page = await electronApp.firstWindow();
electronApp = await startRancherDesktop(__filename);

page = await electronApp.firstWindow();
await new NavPage(page).preferencesButton.click();

preferencesWindow = await electronApp.waitForEvent('window', page => /preferences/i.test(page.url()));
});

test.afterAll(() => teardown(electronApp, __filename));
test.afterAll(async() => {
adamkpickering marked this conversation as resolved.
Show resolved Hide resolved
await teardown(electronApp, __filename);
await tool('rdctl', 'factory-reset', '--verbose');
reopenLogs();
});

test('should open preferences modal', async() => {
expect(preferencesWindow).toBeDefined();

// Wait for the window to actually load (i.e. transition from
// app://index.html/#/preferences to app://index.html/#/Preferences#general)
await preferencesWindow.waitForURL(/Preferences/);
await preferencesWindow.waitForURL(/Preferences#/i);
});

test('should show application page and render general tab', async() => {
Expand Down Expand Up @@ -104,7 +90,7 @@ test.describe.serial('Main App Test', () => {

test('should render environment tab after close and reopen preferences modal', async() => {
test.skip(os.platform() === 'win32', 'Environment tab not available on Windows');
preferencesWindow.close();
await preferencesWindow.close();

await new NavPage(page).preferencesButton.click();
preferencesWindow = await electronApp.waitForEvent('window', page => /preferences/i.test(page.url()));
Expand Down Expand Up @@ -227,15 +213,15 @@ test.describe.serial('Main App Test', () => {
});

test('should render container engine page after close and reopen preferences modal', async() => {
preferencesWindow.close();
await preferencesWindow.close();

await new NavPage(page).preferencesButton.click();
preferencesWindow = await electronApp.waitForEvent('window', page => /preferences/i.test(page.url()));

expect(preferencesWindow).toBeDefined();
// Wait for the window to actually load (i.e. transition from
// app://index.html/#/preferences to app://index.html/#/Preferences#general)
await preferencesWindow.waitForURL(/Preferences/);
await preferencesWindow.waitForURL(/Preferences#/i);
const { containerEngine } = new PreferencesPage(preferencesWindow);

await expect(containerEngine.nav).toHaveClass('preferences-nav-item active');
Expand All @@ -255,7 +241,7 @@ test.describe.serial('Main App Test', () => {
});

test('should render allowed image tab in container engine page after close and reopen preferences modal', async() => {
preferencesWindow.close();
await preferencesWindow.close();

await new NavPage(page).preferencesButton.click();
preferencesWindow = await electronApp.waitForEvent('window', page => /preferences/i.test(page.url()));
Expand Down
26 changes: 3 additions & 23 deletions e2e/rdctl.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import yaml from 'yaml';

import { NavPage } from './pages/nav-page';
import {
createDefaultSettings, getAlternateSetting, kubectl, reportAsset, retry, teardown, tool,
createDefaultSettings, getAlternateSetting, kubectl, retry, startRancherDesktop, teardown, tool,
} from './utils/TestUtils';

import {
Expand All @@ -49,11 +49,10 @@ import { spawnFile } from '@pkg/utils/childProcess';
import paths from '@pkg/utils/paths';
import { RecursivePartial } from '@pkg/utils/typeUtils';

import type { ElectronApplication, BrowserContext, Page } from '@playwright/test';
import type { ElectronApplication, Page } from '@playwright/test';

test.describe('Command server', () => {
let electronApp: ElectronApplication;
let context: BrowserContext;
let serverState: ServerState;
let page: Page;
const ENOENTMessage = os.platform() === 'win32' ? 'The system cannot find the file specified' : 'no such file or directory';
Expand Down Expand Up @@ -118,26 +117,7 @@ test.describe('Command server', () => {

test.beforeAll(async() => {
createDefaultSettings({ kubernetes: { enabled: true } });
electronApp = await _electron.launch({
args: [
appPath,
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item.
'--disable-dev-shm-usage',
'--no-modal-dialogs',
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(__filename, 'log'),
},
});
context = electronApp.context();

await context.tracing.start({
screenshots: true,
snapshots: true,
});
electronApp = await startRancherDesktop(__filename, { mock: false });
page = await electronApp.firstWindow();
});

Expand Down
6 changes: 3 additions & 3 deletions e2e/start-in-background.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';

import { test, expect, _electron, ElectronApplication } from '@playwright/test';

import { createDefaultSettings, packageLogs, startRancherDesktop } from './utils/TestUtils';
import { createDefaultSettings, packageLogs, startRancherDesktop, teardownApp } from './utils/TestUtils';

/**
* Using test.describe.serial make the test execute step by step, as described on each `test()` order
Expand All @@ -21,7 +21,7 @@ test.describe.serial('startInBackground setting', () => {
const tracePath = path.join(__dirname, 'reports', `${ path.basename(__filename) }-startInBackgroundFalse.zip`);

electronApp.context().tracing.stop({ path: tracePath });
await electronApp.close();
await teardownApp(electronApp);
});

test('window should not appear when startInBackground is true', async() => {
Expand All @@ -32,7 +32,7 @@ test.describe.serial('startInBackground setting', () => {
const tracePath = path.join(__dirname, 'reports', `${ path.basename(__filename) }-startInBackgroundTrue.zip`);

electronApp.context().tracing.stop({ path: tracePath });
await electronApp.close();
await teardownApp(electronApp);
});
});

Expand Down
Loading