To add authentication, follow these steps:
// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
projects: [
{
name: 'Setup',
testDir: 'setup',
use: { storageState: 'path/to/storage.json' },
},
// Other test projects
],
};
export default config;
// setup/authenticate.spec.ts
import { test } from '@playwright/test';
test('Authenticate', async ({ page }) => {
await page.goto('https://ray.run/login');
await page.fill('#login_field', 'your-username');
await page.fill('#password', 'your-password');
await page.click('input[type="submit"]');
await page.waitForNavigation();
await page.context().storageState({ path: 'path/to/storage.json' });
});
storageState
for each test file or test group using test.use({ storageState: 'path/to/storage.json' })
.// tests/example.spec.ts
import { test } from '@playwright/test';
test.use({ storageState: 'path/to/storage.json' });
test('Example test', async ({ page }) => {
await page.goto('https://ray.run/dashboard');
// Your test steps
});
BrowserContexts
and Pages
with different storage states to simulate different users interacting with each other.By following these steps, you can implement authentication in a Cucumber with JavaScript on Playwright project.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].