mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
feat: add redirect and timeout in request settings (#5672)
* feat: add redirect and timeout in request settings
This commit is contained in:
9
tests/request/settings/collection/bruno.json
Normal file
9
tests/request/settings/collection/bruno.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "settings-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
17
tests/request/settings/collection/max-redirects.bru
Normal file
17
tests/request/settings/collection/max-redirects.bru
Normal file
@@ -0,0 +1,17 @@
|
||||
meta {
|
||||
name: max-redirects-test
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://httpbun.com/redirect/2
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
settings {
|
||||
followRedirects: true
|
||||
maxRedirects: 1
|
||||
timeout: 0
|
||||
}
|
||||
17
tests/request/settings/collection/no-redirects.bru
Normal file
17
tests/request/settings/collection/no-redirects.bru
Normal file
@@ -0,0 +1,17 @@
|
||||
meta {
|
||||
name: no-redirects-test
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://httpbun.com/redirect/2
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
settings {
|
||||
followRedirects: false
|
||||
maxRedirects: 5
|
||||
timeout: 0
|
||||
}
|
||||
17
tests/request/settings/collection/timeout.bru
Normal file
17
tests/request/settings/collection/timeout.bru
Normal file
@@ -0,0 +1,17 @@
|
||||
meta {
|
||||
name: timeout-test
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://httpbun.com/redirect/2
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
settings {
|
||||
followRedirects: false
|
||||
maxRedirects: 0
|
||||
timeout: 5
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{projectRoot}}/tests/request/settings/collection",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "safe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
6
tests/request/settings/init-user-data/preferences.json
Normal file
6
tests/request/settings/init-user-data/preferences.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"maximized": true,
|
||||
"lastOpenedCollections": [
|
||||
"{{projectRoot}}/tests/request/settings/collection"
|
||||
]
|
||||
}
|
||||
46
tests/request/settings/max-redirects.spec.ts
Normal file
46
tests/request/settings/max-redirects.spec.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { test, expect } from '../../../playwright';
|
||||
|
||||
test.describe('Max Redirects Settings Tests', () => {
|
||||
test('should configure and test max redirects settings', async ({
|
||||
pageWithUserData: page
|
||||
}) => {
|
||||
// Navigate to the test collection and request
|
||||
await expect(page.locator('#sidebar-collection-name').getByText('settings-test')).toBeVisible();
|
||||
|
||||
await page.locator('#sidebar-collection-name').getByText('settings-test').click();
|
||||
|
||||
// Navigate to the max-redirects request
|
||||
await page.getByRole('complementary').getByText('max-redirects').click();
|
||||
|
||||
// Go to Settings tab
|
||||
await page.getByRole('tab', { name: 'Settings' }).click();
|
||||
|
||||
// Test Max Redirects Settings
|
||||
const maxRedirectsInput = page.locator('input[id="maxRedirects"]');
|
||||
await expect(maxRedirectsInput).toBeVisible();
|
||||
|
||||
// Verify default value from .bru file (1)
|
||||
await expect(maxRedirectsInput).toHaveValue('1');
|
||||
|
||||
// Test Follow Redirects toggle
|
||||
const followRedirectsToggle = page.getByTestId('follow-redirects-toggle');
|
||||
await expect(followRedirectsToggle).toBeVisible();
|
||||
await expect(followRedirectsToggle).toBeChecked();
|
||||
|
||||
// Send the request
|
||||
await page.getByTestId('send-arrow-icon').click();
|
||||
|
||||
await expect(page.getByTestId('response-status-code')).toContainText('302', { timeout: 15000 });
|
||||
|
||||
// change the max redirects to 2
|
||||
await maxRedirectsInput.fill('2');
|
||||
await page.getByTestId('send-arrow-icon').click();
|
||||
await expect(page.getByTestId('response-status-code')).toContainText('200', { timeout: 15000 });
|
||||
});
|
||||
|
||||
test.afterEach(async ({ pageWithUserData: page }) => {
|
||||
// Close the single open tab
|
||||
await page.locator('.close-icon-container').click();
|
||||
await page.locator('button:has-text("Don\'t Save")').first().click();
|
||||
});
|
||||
});
|
||||
50
tests/request/settings/no-redirects.spec.ts
Normal file
50
tests/request/settings/no-redirects.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { test, expect } from '../../../playwright';
|
||||
|
||||
test.describe('No Redirects Settings Tests', () => {
|
||||
test('should configure and test no redirects settings', async ({
|
||||
pageWithUserData: page
|
||||
}) => {
|
||||
// Navigate to the test collection and request
|
||||
await expect(page.locator('#sidebar-collection-name').getByText('settings-test')).toBeVisible();
|
||||
|
||||
await page.locator('#sidebar-collection-name').getByText('settings-test').click();
|
||||
|
||||
// Navigate to the no-redirects request
|
||||
await page.getByRole('complementary').getByText('no-redirects').click();
|
||||
|
||||
// Go to Settings tab
|
||||
await page.getByRole('tab', { name: 'Settings' }).click();
|
||||
|
||||
// Test No Redirects Settings
|
||||
const maxRedirectsInput = page.locator('input[id="maxRedirects"]');
|
||||
await expect(maxRedirectsInput).toBeVisible();
|
||||
|
||||
// Verify default value from .bru file (5)
|
||||
await expect(maxRedirectsInput).toHaveValue('5');
|
||||
|
||||
// Test Follow Redirects toggle - should be unchecked
|
||||
const followRedirectsToggle = page.getByTestId('follow-redirects-toggle');
|
||||
await expect(followRedirectsToggle).toBeVisible();
|
||||
await expect(followRedirectsToggle).not.toBeChecked();
|
||||
|
||||
// Send the request - should stop at first redirect (302) without following
|
||||
await page.getByTestId('send-arrow-icon').click();
|
||||
|
||||
// Should get 302 because redirects are disabled, regardless of maxRedirects value
|
||||
await expect(page.getByTestId('response-status-code')).toContainText('302', { timeout: 15000 });
|
||||
|
||||
// Toggle follow redirects to true
|
||||
await followRedirectsToggle.click();
|
||||
await expect(followRedirectsToggle).toBeChecked();
|
||||
|
||||
// Send request again - now should follow redirects and get 200
|
||||
await page.getByTestId('send-arrow-icon').click();
|
||||
await expect(page.getByTestId('response-status-code')).toContainText('200', { timeout: 15000 });
|
||||
});
|
||||
|
||||
test.afterEach(async ({ pageWithUserData: page }) => {
|
||||
// Close the single open tab
|
||||
await page.locator('.close-icon-container').click();
|
||||
await page.locator('button:has-text("Don\'t Save")').first().click();
|
||||
});
|
||||
});
|
||||
38
tests/request/settings/timeout.spec.ts
Normal file
38
tests/request/settings/timeout.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { test, expect } from '../../../playwright';
|
||||
import { closeAllCollections } from '../../utils/page';
|
||||
|
||||
test.describe('Timeout Settings Tests', () => {
|
||||
test('should configure and test timeout settings', async ({
|
||||
pageWithUserData: page
|
||||
}) => {
|
||||
// Navigate to the test collection and request
|
||||
await expect(page.locator('#sidebar-collection-name').getByText('settings-test')).toBeVisible();
|
||||
|
||||
await page.locator('#sidebar-collection-name').getByText('settings-test').click();
|
||||
// Navigate to thetimeout request
|
||||
await page.getByRole('complementary').getByText('timeout-test').click();
|
||||
|
||||
// Go to Settings tab
|
||||
await page.getByRole('tab', { name: 'Settings' }).click();
|
||||
|
||||
// Test Timeout Settings
|
||||
const timeoutInput = page.locator('input[id="timeout"]');
|
||||
await expect(timeoutInput).toBeVisible();
|
||||
|
||||
// Verify default value from .bru file (5)
|
||||
await expect(timeoutInput).toHaveValue('5');
|
||||
|
||||
await page.getByTestId('send-arrow-icon').click();
|
||||
|
||||
const responsePane = page.locator('.response-pane');
|
||||
await expect(responsePane).toContainText('timeout of 5ms exceeded');
|
||||
|
||||
// go to welcome page
|
||||
await page.locator('.bruno-logo').click();
|
||||
});
|
||||
|
||||
test.afterEach(async ({ pageWithUserData: page }) => {
|
||||
// cleanup: close all collections
|
||||
await closeAllCollections(page);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user