mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-22 07:08:16 -04:00
fix: get the main renderer instead of the first one in testing as there are multiple windows now
This commit is contained in:
@@ -3,12 +3,13 @@ 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();
|
||||
await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/gatzjames/insomnia-git-example.git');
|
||||
await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/ihexxa/insomnia-git-example.git');
|
||||
await page.getByPlaceholder('Name').fill('J');
|
||||
await page.getByPlaceholder('Email').fill('J');
|
||||
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();
|
||||
});
|
||||
|
||||
@@ -24,11 +25,21 @@ 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');
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../../playwright/test';
|
||||
|
||||
test('Sign in with Gitlab', async ({ app, page }) => {
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user