Skip to content

Commit

Permalink
refactor: add playwright test.step flow
Browse files Browse the repository at this point in the history
  • Loading branch information
vtshly committed Jan 4, 2025
1 parent a66cd6f commit d826aae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
46 changes: 27 additions & 19 deletions cms/tests/playwright/strapi-admin-ui-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,43 @@ test('unauthorized redirect from localhost:1337 to /admin/auth/login', async ({
test.skip('register admin-user to strapi-admin', async ({ page }) => {
checkTestUserCredentialsExist();

await expect(page).toHaveURL('http://localhost:1337/admin/auth/register-admin');
await test.step('Check unauthorized redirect to /auth/register-admin', async () => {
await expect(page).toHaveURL('http://localhost:1337/admin/auth/register-admin');
});

// Fill registration-form fields
await page.fill('input[name="firstname"]', 'Adminiy');
await page.fill('input[name="email"]', TEST_USERS.adminUser.email);
await page.fill('input[name="password"]', TEST_USERS.adminUser.password);
await page.fill('input[name="confirmPassword"]', TEST_USERS.adminUser.password);
await page.click('button[type="submit"]');
await test.step('Fill registration-form fields', async () => {
await page.fill('input[name="firstname"]', 'Adminiy');
await page.fill('input[name="email"]', TEST_USERS.adminUser.email);
await page.fill('input[name="password"]', TEST_USERS.adminUser.password);
await page.fill('input[name="confirmPassword"]', TEST_USERS.adminUser.password);
await page.click('button[type="submit"]');
});

// Ensure there are no validation errors displayed under the input fields
await expect(page.locator('[data-strapi-field-error="true"]')).toHaveCount(0);
await test.step('Ensure there are no validation errors displayed under the input fields', async () => {
await expect(page.locator('[data-strapi-field-error="true"]')).toHaveCount(0);
});

// Verify redirection to the authorized admin dashboard with the welcome message
await expect(page.locator('//h1')).toHaveText('Welcome 👋');
await test.step('Verify redirection to the authorized admin dashboard with the welcome message', async () => {
await expect(page.locator('//h1')).toHaveText('Welcome 👋');
});
});

test('login to strapi-admin', async ({ page }) => {
checkTestUserCredentialsExist();

// Fill in the email and password fields & press Login button
await page.fill('input[name="email"]', TEST_USERS.adminUser.email);
await page.fill('input[name="password"]', TEST_USERS.adminUser.password);
await page.click('button[type="submit"]');
await test.step('Fill in the email and password fields & press Login button', async () => {
await page.fill('input[name="email"]', TEST_USERS.adminUser.email);
await page.fill('input[name="password"]', TEST_USERS.adminUser.password);
await page.click('button[type="submit"]');
});

// Ensure there are no validation errors displayed under the input fields
await expect(page.locator('[data-strapi-field-error="true"]')).toHaveCount(0);
await test.step('Ensure there are no validation errors displayed under the input fields', async () => {
await expect(page.locator('[data-strapi-field-error="true"]')).toHaveCount(0);
});

// Verify redirection to the authorized admin dashboard with the welcome message
await expect(page.locator('//h1')).toHaveText('Welcome 👋');
await test.step('Verify redirection to the authorized admin dashboard with the welcome message', async () => {
await expect(page.locator('//h1')).toHaveText('Welcome 👋');
});
});

async function checkTestUserCredentialsExist() {
Expand Down
6 changes: 5 additions & 1 deletion frontend/tests/playwright/stub-page-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { test, checkConsoleErrors } from './baseTest';
import { expect } from '@playwright/test';

export const PAGE_DATA = {
headerText: 'Скоро здесь будет сайт'
};

test.beforeEach(async ({ page }) => {
await page.goto('/');
});

checkConsoleErrors();

test('has title', async ({ page }) => {
await expect(page.getByRole('heading', {name: 'Скоро здесь будет сайт'})).toBeVisible();
await expect(page.getByRole('heading', {name: PAGE_DATA.headerText})).toBeVisible();
});

0 comments on commit d826aae

Please sign in to comment.