How to automate browser-based digest auth dialog triggered after file upload #3128
Replies: 1 comment
|
If you're using Serenity/JS with Playwright Test, using the Using the Playwright Test config fileYou can configure import { defineConfig } from '@playwright/test'
import { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
use: {
httpCredentials: {
username: 'user', // or read the value from process.env
password: 'pass',
},
},
})Using this approach ensures that whenever your server under test requires HTTP authentication, Playwright provides the credentials. Scenario-specific configurationAlternatively, you can configure import { describe, it, test } from '@serenity-js/playwright-test'
describe('Device maintenance', () => {
describe('Firmware', () => {
test.use({
httpCredentials: {
username: 'user', // or read then from process.env
password: 'pass',
}
})
it('allows the user to update firmware', async ({ actor }) => {
await actor.attemptsTo(
DeviceMaintenancePage.open(),
DeviceMaintenancePage.uploadFirmware('./firmware/FUS-Example-H743.I.Signed.xml'),
)
})
})
})Request interceptionIf you need to vary the credentials per test or per route, you can provide the Conveniently, the default Serenity/JS import { describe, it, test } from '@serenity-js/playwright-test'
describe('Device maintenance', () => {
describe('Firmware', () => {
it('allows the user to update firmware', async ({ actor, page }) => {
await page.route('**/firmware/*', async (route, request) => {
const headers = {
...request.headers(),
Authorization: 'Bearer YOUR_TOKEN_HERE',
// or e.g. 'Basic base64(user:pass)'
};
await route.continue({ headers });
})
await actor.attemptsTo(
DeviceMaintenancePage.open(),
DeviceMaintenancePage.uploadFirmware('./firmware/FUS-Example-H743.I.Signed.xml'),
)
})
})
}) |

If you're using Serenity/JS with Playwright Test, using the
httpCredentialsoption is the easiest way to provide the credentials needed to authenticate the request.Using the Playwright Test config file
You can configure
httpCredentialsin your Playwright Test config file:Using this approac…