Skip to content

Commit

Permalink
Tests - Move HTTP requests metadata from Cypress to Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jan 20, 2025
1 parent 97464e0 commit 14ce4ea
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 243 deletions.
222 changes: 0 additions & 222 deletions tests/end2end/cypress/integration/requests-metadata-ghaction.js

This file was deleted.

40 changes: 19 additions & 21 deletions tests/end2end/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { test as setup } from '@playwright/test';
import path from 'path';
import { Page } from '@playwright/test';

const user_in_group_aFile = path.join(__dirname, './.auth/user_in_group_a.json');

setup('authenticate as user_in_group_a', async ({ page }) => {
/**
* Performs the authentication steps
* @param {Page} page The page object
* @param {string} login The login
* @param {string} password The password
* @param {string} user_file The path to the file where the cookies will be stored
*/
export async function auth_using_login(page: Page, login: string, password: string, user_file: string) {
// Perform authentication steps. Replace these actions with your own.
await page.goto('admin.php/auth/login?auth_url_return=%2Findex.php');
await page.locator('#jforms_jcommunity_login_auth_login').fill('user_in_group_a');
await page.locator('#jforms_jcommunity_login_auth_password').fill('admin');
await page.locator('#jforms_jcommunity_login_auth_login').fill(login);
await page.locator('#jforms_jcommunity_login_auth_password').fill(password);
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL('index.php');

// End of authentication steps.
await page.context().storageState({ path: user_file });
}

await page.context().storageState({ path: user_in_group_aFile });
setup('authenticate as user_in_group_a', async ({ page }) => {
await auth_using_login(page, 'user_in_group_a', 'admin', path.join(__dirname, './.auth/user_in_group_a.json'));
});

const adminFile = path.join(__dirname, './.auth/admin.json');

setup('authenticate as admin', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto('admin.php/auth/login?auth_url_return=%2Findex.php');
await page.locator('#jforms_jcommunity_login_auth_login').fill('admin');
await page.locator('#jforms_jcommunity_login_auth_password').fill('admin');
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL('index.php');

// End of authentication steps.
await auth_using_login(page, 'admin', 'admin', path.join(__dirname, './.auth/admin.json'));
});

await page.context().storageState({ path: adminFile });
setup('authenticate as publisher', async ({ page }) => {
await auth_using_login(page, 'publisher', 'admin', path.join(__dirname, './.auth/publisher.json'));
});
Loading

0 comments on commit 14ce4ea

Please sign in to comment.