Files
at-digitaltwin/tests/ui/auth/recover-password.spec.ts

45 lines
1.8 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { LoginPage } from '../../../page-objects/LoginPage';
import fs from 'fs';
import {
waitForConfirmationCode
} from '../../../utils/mailTmApi';
test('UI: восстановление пароля', async ({ page }) => {
// Загружаем email пользователя из файла temp/user.json
const loginPage = new LoginPage(page);
const user = JSON.parse(fs.readFileSync('temp/user.json', 'utf-8'));
const newPassword = '!Test12345678';
// Переход на главную
await loginPage.goto();
// Нажимаем "Забыли пароль?"
await page.getByText('Забыли пароль?').click();
await expect(page).toHaveURL(/.*confirmation-code/);
// Вводим почту
await page.fill('input[name="email"]', user.email);
await page.getByRole('button', { name: 'Далее' }).click();
// Получаем код из почты
const code = await waitForConfirmationCode(user.email, user.mailToken, 'recover');
expect(code).toMatch(/^\d{6}$/);
console.log('✅ Код получен:', code);
// Вводим код
await page.fill('input[name="code"]', code);
await page.getByRole('button', { name: 'Далее' }).click();
// Вводим новый пароль
await page.fill('input[name="password"]', newPassword);
await page.fill('input[name="passwordRepeat"]', newPassword);
await page.getByRole('button', { name: 'Далее' }).click();
// Проверяем успешную авторизацию
await expect(page).toHaveURL(/.*\/account\/profile/);
// (необязательно) обновляем сохранённый пароль
//user.password = newPassword;
//fs.writeFileSync('temp/user.json', JSON.stringify(user));
});