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

feat: add hidden browser window for execution [INS-3378] #6897

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f982ef3
feat: enable islated utility process [INS-3378]
ihexxa Dec 2, 2023
c1951e7
fix: disable flaky test and extend timeout
ihexxa Dec 11, 2023
fba6f8f
test: add some logs
ihexxa Dec 11, 2023
bda4d52
chore: add some logs
ihexxa Dec 11, 2023
a098c92
feat: add cookie related objects
ihexxa Dec 12, 2023
f6cc1c1
fix: add script path env for utility process
ihexxa Dec 13, 2023
920a4c0
fix: lint issue
ihexxa Dec 13, 2023
e1643ef
fix: lint error
ihexxa Dec 13, 2023
2ba677e
fix: make vite supporting multiple entries
ihexxa Dec 13, 2023
51209d5
fix: remove utility process building task and use vite instead
ihexxa Dec 13, 2023
d638f69
fix: always outputs utility process bundle to src folder instead of b…
ihexxa Dec 13, 2023
22b0e18
chore: some small fixes
ihexxa Dec 14, 2023
bf41211
fix: make utility process can be triggerred
ihexxa Dec 14, 2023
63055f5
fix: add missing file
ihexxa Dec 14, 2023
5da9cb4
fix: enable smoke tests
ihexxa Dec 15, 2023
757e8c7
fix: revert commented tests
ihexxa Dec 15, 2023
1024144
fix: utility process is a improper name for the browser window
ihexxa Dec 20, 2023
8f1341c
feat: support global object aliases and timeout
ihexxa Dec 20, 2023
00f29ad
chore: keep develop version for other tests
ihexxa Dec 21, 2023
99b1977
fix: improve tests a bit and hide the browser window
ihexxa Dec 22, 2023
fbb60f3
test: add tests for unhappy paths
ihexxa Dec 22, 2023
e2a92b1
fix: get the main renderer instead of the first one in testing as the…
ihexxa Jan 2, 2024
e370516
chore: try keep test timeout untouched
ihexxa Jan 2, 2024
62750bb
fix: pick improvements from the downstream PR
ihexxa Jan 3, 2024
018a3a4
fix: start hidden window on-demand instead of by default
ihexxa Jan 4, 2024
9f08627
test: create a helper function for waiting for a specific window
ihexxa Jan 4, 2024
ae363f4
chore: add logs for hidden browser window initing
ihexxa Jan 4, 2024
1bb9e1a
chore: add log prefix for logs
ihexxa Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/insomnia-smoke-test/playwright/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ElectronApplication, test as baseTest, TraceMode } from '@playwright/test';
import path from 'path';

import { getLoadedPage } from '../playwright/utils';
import {
bundleType,
cwd,
Expand Down Expand Up @@ -96,18 +97,18 @@ export const test = baseTest.extend<{

await electronApp.close();
},
page: async ({ app }, use) => {
const page = await app.firstWindow();

await page.waitForLoadState();

page: async ({ app }, use) => {
const page = await getLoadedPage(app, 'Insomnia');
await use(page);
},

dataPath: async ({ }, use) => {
const insomniaDataPath = randomDataPath();

await use(insomniaDataPath);
},

userConfig: async ({ }, use) => {
await use({
skipOnboarding: true,
Expand Down
36 changes: 36 additions & 0 deletions packages/insomnia-smoke-test/playwright/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ElectronApplication } from '@playwright/test';

import config from '../playwright.config';

export async function getLoadedPage(app: ElectronApplication, pageHTMLTitle: string) {
const pollingInterval = 500;
const timeoutMs = config.timeout;

if (!timeoutMs) {
throw Error('timeout is undefined in playwright.config.ts, probably the config is modifed.');
}

const targetPage = await (async () => {
for (let i = 0; i < timeoutMs / pollingInterval; i++) {
const pages = app.windows();

for (const page of pages) {
const pageTitle = await page.title();
if (pageTitle === pageHTMLTitle) {
return page;
}
}

await new Promise(resolve => setTimeout(resolve, pollingInterval));
}

return undefined;
})();

if (!targetPage) {
throw Error(`page (${pageHTMLTitle}) is not loaded until ${timeoutMs}ms, please manually launch app and check why`);
}

await targetPage.waitForLoadState();
return targetPage;
};
22 changes: 18 additions & 4 deletions packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test } from '../../playwright/test';

test('Clone from github', async ({ page }) => {
await page.getByLabel('Clone git repository').click();
await page.getByRole('tab', { name: ' Git' }).click();
Expand All @@ -8,8 +9,10 @@ test('Clone from github', async ({ page }) => {
await page.getByPlaceholder('MyUser').fill('J');
await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill('J');
await page.getByTestId('git-repository-settings-modal__sync-btn').click();

await page.getByLabel('Toggle preview').click();
});

test('Sign in with GitHub', async ({ app, page }) => {
await page.getByRole('button', { name: 'New Document' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click();
Expand All @@ -22,11 +25,22 @@ test('Sign in with GitHub', async ({ app, page }) => {
// and return the url that would be created by following the GitHub OAuth flow.
// https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#web-application-flow
const fakeGitHubOAuthWebFlow = app.evaluate(electron => {
return new Promise<{ redirectUrl: string }>(resolve => {
const webContents = electron.BrowserWindow.getAllWindows()[0].webContents;
return new Promise<{ redirectUrl: string }>((resolve, reject) => {

const wins = electron.BrowserWindow.getAllWindows();
let mainWin = undefined;
for (let i = 0; i < wins.length; i++) {
mainWin = wins[i].title === 'Insomnia' ? wins[i] : undefined;
}
if (!mainWin) {
reject('main window is not found, probably the title of the mainWindow is modified or it is not started');
}

const webContents = mainWin?.webContents;

// Remove all navigation listeners so that only the one we inject will run
webContents.removeAllListeners('will-navigate');
webContents.on('will-navigate', (event: Event, url: string) => {
webContents?.removeAllListeners('will-navigate');
webContents?.on('will-navigate', (event: Event, url: string) => {
event.preventDefault();
const parsedUrl = new URL(url);
// We use the same state parameter that the app created to assert that we prevent CSRF
Expand Down
20 changes: 16 additions & 4 deletions packages/insomnia-smoke-test/tests/smoke/oauth-gitlab.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect } from '@playwright/test';

import { test } from '../../playwright/test';

test('Sign in with Gitlab', async ({ app, page }) => {
Expand All @@ -8,11 +10,21 @@ test('Sign in with Gitlab', async ({ app, page }) => {
await page.getByRole('tab', { name: 'GitLab' }).click();

const fakeGitLabOAuthWebFlow = app.evaluate(electron => {
return new Promise<{ redirectUrl: string }>(resolve => {
const webContents = electron.BrowserWindow.getAllWindows()[0].webContents;
return new Promise<{ redirectUrl: string }>((resolve, reject) => {
const wins = electron.BrowserWindow.getAllWindows();
let mainWin = undefined;
for (let i = 0; i < wins.length; i++) {
mainWin = wins[i].title === 'Insomnia' ? wins[i] : undefined;
}

if (!mainWin) {
reject('main window is not found, probably the title of the mainWindow is modified or it is not started');
}

const webContents = mainWin?.webContents;
// Remove all navigation listeners so that only the one we inject will run
webContents.removeAllListeners('will-navigate');
webContents.on('will-navigate', (event: Event, url: string) => {
webContents?.removeAllListeners('will-navigate');
webContents?.on('will-navigate', (event: Event, url: string) => {
event.preventDefault();
const parsedUrl = new URL(url);
// We use the same state parameter that the app created to assert that we prevent CSRF
Expand Down
Loading
Loading