Refactor tests

This commit is contained in:
Anoop M D
2025-09-07 03:05:11 +05:30
parent db35e7059c
commit 033c5cc0f7
78 changed files with 154 additions and 116 deletions

View File

@@ -1,33 +0,0 @@
import { test, expect } from '../../playwright';
test.describe.serial('Persistent Environment Test', () => {
test.setTimeout(2 * 10 * 1000);
test('add env using script', async ({ pageWithUserData: page, restartApp }) => {
await page.locator('#sidebar-collection-name').click();
await page.getByRole('button', { name: 'Save' }).click();
await page.getByText('ping', { exact: true }).click();
await page.getByText('No Environment').click();
await page.getByRole('tooltip').locator('div').filter({ hasText: 'Env' }).nth(3).click();
await page.locator('#send-request').getByRole('img').nth(2).click();
await page.waitForTimeout(1000);
await page.locator('div').filter({ hasText: /^Env$/ }).nth(3).click();
await page.getByText('Configure', { exact: true }).click();
await expect(page.getByRole('row', { name: 'persistent-env-test' }).getByRole('cell').nth(3)).toBeVisible();
await page.getByText('×').click();
const newApp = await restartApp();
const newPage = await newApp.firstWindow();
await newPage.locator('#sidebar-collection-name').click();
await newPage.getByRole('button', { name: 'Save' }).click();
await newPage.getByText('ping', { exact: true }).click();
await newPage.getByText('No Environment').click();
await newPage.getByRole('tooltip').locator('div').filter({ hasText: 'Env' }).nth(3).click();
await newPage.locator('div').filter({ hasText: /^Env$/ }).nth(3).click();
await newPage.getByText('Configure', { exact: true }).click();
await expect(newPage.getByRole('row', { name: 'persistent-env-test' }).getByRole('cell').nth(3)).toBeVisible();
await newPage.getByText('×').click();
await newPage.waitForTimeout(1000);
await newPage.close();
});
});

View File

@@ -1,40 +0,0 @@
import { test, expect } from '../../playwright';
test.describe.serial('Persistent Environment Test', () => {
test.setTimeout(2 * 10 * 1000);
test('add env using script', async ({ pageWithUserData: page, restartApp }) => {
await page.locator('#sidebar-collection-name').click();
await page.getByText('ping2', { exact: true }).click();
await page.getByText('Env', { exact: true }).click();
await page.getByText('Stage', { exact: true }).click();
await page.locator('#send-request').getByRole('img').nth(2).click();
await page.waitForTimeout(1000);
await page
.locator('div')
.filter({ hasText: /^Stage$/ })
.nth(3)
.click();
await page.getByText('Configure', { exact: true }).click();
await expect(page.getByRole('row', { name: 'persistent-env-test' }).getByRole('cell').nth(3)).toBeVisible();
await page.getByText('×').click();
const newApp = await restartApp();
const newPage = await newApp.firstWindow();
await newPage.locator('#sidebar-collection-name').click();
await newPage.getByRole('button', { name: 'Save' }).click();
await newPage.getByText('ping2', { exact: true }).click();
await newPage.getByText('No Environment').click();
await newPage.getByText('Stage').click();
await newPage
.locator('div')
.filter({ hasText: /^Stage$/ })
.nth(3)
.click();
await newPage.getByText('Configure', { exact: true }).click();
await expect(newPage.getByRole('row', { name: 'persistent-env-test' }).getByRole('cell').nth(3)).not.toBeVisible();
await newPage.getByText('×').click();
await newPage.waitForTimeout(1000);
await newPage.close();
});
});

View File

@@ -1,4 +0,0 @@
vars {
host: https://testbench-sanity.usebruno.com
persistent-env-test: persistent-env-test-value
}

View File

@@ -1,6 +0,0 @@
{
"maximized": true,
"lastOpenedCollections": [
"{{projectRoot}}/e2e-tests/persistent-env-tests/collection"
]
}

View File

@@ -18,7 +18,7 @@ const EnvironmentSelector = ({ collection }) => {
const Icon = forwardRef((props, ref) => {
return (
<div ref={ref} className="current-environment flex items-center justify-center pl-3 pr-2 py-1 select-none">
<div ref={ref} className="current-environment collection-environment flex items-center justify-center pl-3 pr-2 py-1 select-none">
<p className="text-nowrap truncate max-w-32" title={activeEnvironment ? activeEnvironment.name : 'No Environment'}>{activeEnvironment ? activeEnvironment.name : 'No Environment'}</p>
<IconCaretDown className="caret" size={14} strokeWidth={2} />
</div>

View File

@@ -173,7 +173,7 @@ const EnvironmentVariables = ({ environment, collection, setIsModified, original
return (
<StyledWrapper className="w-full mt-6 mb-6">
<div className="h-[50vh] overflow-y-auto w-full">
<table>
<table className="environment-variables">
<thead>
<tr>
<td className="text-center">Enabled</td>

View File

@@ -19,7 +19,7 @@ const EnvironmentSelector = () => {
const Icon = forwardRef((props, ref) => {
return (
<div ref={ref} className={`current-environment flex flex-row gap-1 rounded-xl text-xs cursor-pointer items-center justify-center select-none ${activeGlobalEnvironmentUid? 'environment-active': ''}`}>
<div ref={ref} className={`current-environment global-environment flex flex-row gap-1 rounded-xl text-xs cursor-pointer items-center justify-center select-none ${activeGlobalEnvironmentUid? 'environment-active': ''}`}>
<ToolHint text="Global Environments" toolhintId="GlobalEnvironmentsToolhintId" className='flex flex-row'>
<IconWorld className="globe" size={16} strokeWidth={1.5} />
{

View File

@@ -112,6 +112,7 @@ const QueryUrl = ({ item, collection, handleRun }) => {
/>
<div className="flex items-center h-full mr-2 cursor-pointer" id="send-request" onClick={handleRun}>
<div
title="Generate Code"
className="infotip mr-3"
onClick={(e) => {
handleGenerateCode(e);
@@ -128,6 +129,7 @@ const QueryUrl = ({ item, collection, handleRun }) => {
</span>
</div>
<div
title="Save Request"
className="infotip mr-3"
onClick={(e) => {
e.stopPropagation();

View File

@@ -7,7 +7,7 @@ if (process.env.CI) {
}
export default defineConfig({
testDir: './e2e-tests',
testDir: './tests',
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,

View File

@@ -5,7 +5,7 @@ async function main() {
const { app, context } = await startApp();
let outputFile = process.argv[2]?.trim();
if (outputFile && !/\.(ts|js)$/.test(outputFile)) {
outputFile = path.join(__dirname, '../e2e-tests/', outputFile + '.spec.ts');
outputFile = path.join(__dirname, '../tests/', outputFile + '.spec.ts');
}
await context._enableRecorder({ language: 'playwright-test', mode: 'recording', outputFile });
}

View File

@@ -1,6 +1,7 @@
import { test, expect } from '../../playwright';
import { test, expect } from '../../../playwright';
test('Create new collection and add a simple HTTP request', async ({ page, createTmpDir }) => {
test('Create collection and add a simple HTTP request', async ({ page, createTmpDir }) => {
// Create a new collection
await page.getByLabel('Create Collection').click();
await page.getByLabel('Name').click();
await page.getByLabel('Name').fill('test-collection');
@@ -8,24 +9,24 @@ test('Create new collection and add a simple HTTP request', async ({ page, creat
await page.getByLabel('Location').fill(await createTmpDir('test-collection'));
await page.getByRole('button', { name: 'Create', exact: true }).click();
await page.getByText('test-collection').click();
// Select safe mode
await page.getByLabel('Safe Mode').check();
await page.getByRole('button', { name: 'Save' }).click();
// Create a new request
await page.locator('#create-new-tab').getByRole('img').click();
await page.getByPlaceholder('Request Name').fill('r1');
await page.locator('#new-request-url .CodeMirror').click();
await page.locator('textarea').fill('http://localhost:8081');
await page.getByRole('button', { name: 'Create' }).click();
// Send a request
await page.locator('#request-url .CodeMirror').click();
await page.locator('textarea').fill('/ping');
await page.locator('#send-request').getByTitle('Save Request').click();
await page.locator('#send-request').getByRole('img').nth(2).click();
await expect(page.getByRole('main')).toContainText('200 OK');
await page.getByRole('tab', { name: 'GET r1' }).locator('circle').click();
await page.getByRole('button', { name: 'Save', exact: true }).click();
await page.getByText('GETr1').click();
await page.getByRole('button', { name: 'Clear response' }).click();
await page.locator('body').press('ControlOrMeta+Enter');
// Verify the response
await expect(page.getByRole('main')).toContainText('200 OK');
});

View File

@@ -0,0 +1,57 @@
import { test, expect } from '../../../playwright';
import fs from 'fs';
import path from 'path';
test.describe.serial('bru.setEnvVar(name, value, { persist: true })', () => {
test.setTimeout(2 * 10 * 1000);
test('set env var with persist using script', async ({ pageWithUserData: page, restartApp }) => {
// Keep a copy of the original Stage.bru file
const originalStageBruPath = path.join(__dirname, 'collection/environments/Stage.bru');
const originalStageBruContent = fs.readFileSync(originalStageBruPath, 'utf8');
// Select the collection and request
await page.locator('#sidebar-collection-name').click();
await page.getByText('api-setEnvVar-with-persist', { exact: true }).click();
// open environment dropdown
await page.locator('div.current-environment.collection-environment').click();
// select stage environment
await expect(page.locator('.dropdown-item').filter({ hasText: 'Stage' })).toBeVisible();
await page.locator('.dropdown-item').filter({ hasText: 'Stage' }).click();
await expect(page.locator('.current-environment').filter({ hasText: /Stage/ })).toBeVisible();
// Send the request
await page.locator('#send-request').getByRole('img').nth(2).click();
await page.waitForTimeout(1000);
// confirm that the environment variable is set
await page.getByTitle('Stage', { exact: true }).click();
await page.getByText('Configure', { exact: true }).click();
await expect(page.getByRole('row', { name: 'token' }).getByRole('cell').nth(1)).toBeVisible();
await expect(page.getByRole('row', { name: 'secret' }).getByRole('cell').nth(2)).toBeVisible();
await page.getByText('×').click();
// we restart the app to confirm that the environment variable is persisted
const newApp = await restartApp();
const newPage = await newApp.firstWindow();
// select the collection and request
await newPage.locator('#sidebar-collection-name').click();
await newPage.getByText('api-setEnvVar-with-persist', { exact: true }).click();
// open environment dropdown
await newPage.locator('div.current-environment.collection-environment').click();
await newPage.getByText('Configure', { exact: true }).click();
await expect(newPage.getByRole('row', { name: 'token' }).getByRole('cell').nth(1)).toBeVisible();
await expect(newPage.getByRole('row', { name: 'secret' }).getByRole('cell').nth(2)).toBeVisible();
// close the environment modal
await newPage.getByText('×').click();
// Restore the original Stage.bru file
fs.writeFileSync(originalStageBruPath, originalStageBruContent);
await newPage.close();
});
});

View File

@@ -0,0 +1,49 @@
import { test, expect } from '../../../playwright';
test.describe.serial('bru.setEnvVar(name, value)', () => {
test.setTimeout(2 * 10 * 1000);
test('set env var using script', async ({ pageWithUserData: page, restartApp }) => {
// Select the collection and request
await page.locator('#sidebar-collection-name').click();
await page.getByText('api-setEnvVar-without-persist', { exact: true }).click();
// open environment dropdown
await page.locator('div.current-environment.collection-environment').click();
// select stage environment
await expect(page.locator('.dropdown-item').filter({ hasText: 'Stage' })).toBeVisible();
await page.locator('.dropdown-item').filter({ hasText: 'Stage' }).click();
await expect(page.locator('.current-environment').filter({ hasText: /Stage/ })).toBeVisible();
// Send the request
await page.locator('#send-request').getByRole('img').nth(2).click();
await page.waitForTimeout(1000);
// confirm that the environment variable is set
await page.getByTitle('Stage', { exact: true }).click();
await page.getByText('Configure', { exact: true }).click();
await expect(page.getByRole('row', { name: 'token' }).getByRole('cell').nth(1)).toBeVisible();
await expect(page.getByRole('row', { name: 'secret' }).getByRole('cell').nth(2)).toBeVisible();
await page.getByText('×').click();
// we restart the app to confirm that the environment variable is not persisted
const newApp = await restartApp();
const newPage = await newApp.firstWindow();
// select the collection and request
await newPage.locator('#sidebar-collection-name').click();
await newPage.getByText('api-setEnvVar-without-persist', { exact: true }).click();
// open environment dropdown
await newPage.locator('div.current-environment.collection-environment').click();
await newPage.getByText('Configure', { exact: true }).click();
// ensure that the environment variable is not persisted
await expect(newPage.locator('table.environment-variables tbody')).not.toContainText('token');
// close the environment variable modal
await newPage.getByText('×').click();
await newPage.close();
});
});

View File

@@ -1,5 +1,5 @@
meta {
name: ping
name: api-setEnvVar-with-persist
type: http
seq: 1
}
@@ -11,5 +11,5 @@ get {
}
script:pre-request {
bru.setEnvVar("persistent-env-test", "persistent-env-test-value", { persist: true });
bru.setEnvVar("token", "secret", { persist: true });
}

View File

@@ -1,5 +1,5 @@
meta {
name: ping2
name: api-setEnvVar-without-persist
type: http
seq: 1
}
@@ -11,5 +11,5 @@ get {
}
script:pre-request {
bru.setEnvVar("persistent-env-test", "persistent-env-test-value");
bru.setEnvVar("token", "secret");
}

View File

@@ -1,3 +1,4 @@
vars {
host: https://testbench-sanity.usebruno.com
token: secret
}

View File

@@ -0,0 +1,10 @@
{
"collections": [
{
"path": "{{projectRoot}}/tests/environments/api-setEnvVar/collection",
"securityConfig": {
"jsSandboxMode": "safe"
}
}
]
}

View File

@@ -0,0 +1,6 @@
{
"maximized": true,
"lastOpenedCollections": [
"{{projectRoot}}/tests/environments/api-setEnvVar/collection"
]
}

View File

@@ -1,7 +1,7 @@
{
"collections": [
{
"path": "{{projectRoot}}/e2e-tests/environments/multiline-variables/collection",
"path": "{{projectRoot}}/tests/environments/multiline-variables/collection",
"securityConfig": {
"jsSandboxMode": "developer"
}

View File

@@ -1,7 +1,7 @@
{
"maximized": true,
"lastOpenedCollections": [
"{{projectRoot}}/e2e-tests/environments/multiline-variables/collection"
"{{projectRoot}}/tests/environments/multiline-variables/collection"
],
"request": {
"sslVerification": false,

View File

@@ -13,8 +13,7 @@ test.describe('Multiline Variables - Read Environment Test', () => {
await page.getByTitle('request', { exact: true }).click();
// open environment dropdown
await expect(page.getByTitle('No Environment')).toBeVisible();
await page.getByTitle('No Environment').click();
await page.locator('div.current-environment.collection-environment').click();
// select test environment
await expect(page.locator('.dropdown-item').filter({ hasText: 'Test' })).toBeVisible();

View File

@@ -13,8 +13,7 @@ test.describe('Multiline Variables - Write Test', () => {
await page.getByTitle('multiline-test', { exact: true }).click();
// open environment dropdown
await expect(page.getByTitle('No Environment')).toBeVisible();
await page.getByTitle('No Environment').click();
await page.locator('div.current-environment.collection-environment').click();
// select test environment
await expect(page.locator('.dropdown-item').filter({ hasText: 'Test' })).toBeVisible();
@@ -34,7 +33,6 @@ test.describe('Multiline Variables - Write Test', () => {
const valueTextarea = page.locator('.bruno-modal-card textarea').last();
await expect(valueTextarea).toBeVisible();
const jsonValue = `{
"user": {
"name": "John Doe",

View File

@@ -1,13 +1,13 @@
import { test, expect } from '../../playwright';
test('Should verify all support links with correct URL in preference > Support tab', async ({ page }) => {
// Open Preferences
await page.getByLabel('Open Preferences').click();
// Verify Support tab
// Go to Support tab
await page.getByRole('tab', { name: 'Support' }).click();
// Verify all support links with correct URL
const locator_twitter = page.getByRole('link', { name: 'Twitter' });
expect(await locator_twitter.getAttribute('href')).toEqual('https://twitter.com/use_bruno');
@@ -22,6 +22,4 @@ test('Should verify all support links with correct URL in preference > Support t
const locator_documentation = page.getByRole('link', { name: 'Documentation', exact: true });
expect(await locator_documentation.getAttribute('href')).toEqual('https://docs.usebruno.com');
});

View File

@@ -1,6 +1,6 @@
import { test, expect } from '../../playwright';
test.describe.parallel('Run Testbench Requests', () => {
test.describe.parallel('Collection Run', () => {
test('Run bruno-testbench in Developer Mode', async ({ pageWithUserData: page }) => {
test.setTimeout(2 * 60 * 1000);