await page.goto('/login');
await page.fill('#email', '[email protected]');
await page.fill('#password', 'DontTestMe');
await page.click('button[type="submit"]');
await apiLogin(page, request, adminEmail, adminPassword);
await page.goto('/dashboard');
await authenticatedPage.goto('/dashboard');
// Send login api request
const apiResponse = await apiClient.post(`/api/users/login`, {
data: {
email,
password
}
});
// Convert response to json
const apiResponseJson = await apiResponse.json();
// Return accessToken for future usage
return apiResponseJson.accessToken;
}
import { apiLogin } from '../api/UsersApi';
export const test = base.extend({
authenticatedPage: async ({ browser }, use) => {
// Step 1: Create an API client (apiContext)
const apiClient = await request.newContext();
// Step 2: Send api login request
const token = await apiLogin(apiClient, ‘[email protected]’, ‘12345678’);
// Step 3: Create a browser context to add your apiToken to
const context = await browser.newContext();
// Step 4: Inject localStorage token *before* any page is created
await context.addInitScript((tokenValue) => {
window.localStorage.setItem('accessToken', tokenValue);
}, token);
// Step 5: Create and use new page our of context above
const page = await context.newPage();
await use(page);
await context.close();
}
});
test(‘should find best qa automation bootcamp’, async ({ auth
await authenticatedPage.goto('https://www.youtube.com/@Codemify');
await expect(authenticatedPage).toHaveText(/Best QA Bootcamp/);
});