Initial commit: added Playwright tests
This commit is contained in:
78
page-objects/LoginPage.ts
Normal file
78
page-objects/LoginPage.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { type Page, type Locator, expect } from '@playwright/test';
|
||||
|
||||
export class LoginPage {
|
||||
// --- Свойства класса (элементы страницы) ---
|
||||
readonly page: Page;
|
||||
|
||||
// Поля ввода
|
||||
readonly emailInput: Locator;
|
||||
readonly passwordInput: Locator;
|
||||
|
||||
// Кнопки
|
||||
readonly loginButton: Locator;
|
||||
readonly forgotPasswordLink: Locator;
|
||||
readonly registerLink: Locator;
|
||||
|
||||
// Другие элементы
|
||||
readonly passwordVisibilityToggle: Locator; // "Глазик"
|
||||
readonly menuButton: Locator;
|
||||
|
||||
|
||||
// --- Конструктор ---
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
|
||||
// --- Инициализация локаторов ---
|
||||
// Используем рекомендованные Playwright методы для поиска элементов.
|
||||
// Они более надежны, чем классы.
|
||||
|
||||
// Ищем поля по их видимым placeholder'ам
|
||||
this.emailInput = page.getByPlaceholder('Email');
|
||||
this.passwordInput = page.getByPlaceholder('Пароль');
|
||||
|
||||
// Ищем кнопку по ее роли и видимому тексту. Самый надежный способ.
|
||||
this.loginButton = page.getByRole('button', { name: 'Войти', exact: true });
|
||||
|
||||
// Ищем ссылки и кликабельные тексты
|
||||
this.forgotPasswordLink = page.getByText('Забыли пароль?');
|
||||
this.registerLink = page.getByText('Зарегистрируйтесь');
|
||||
|
||||
// "Глазик" для показа/скрытия пароля ищем по alt-тексту картинки
|
||||
this.passwordVisibilityToggle = page.getByAltText('показать пароль');
|
||||
|
||||
// Кнопку меню найдем по уникальному классу, так как другого варианта нет.
|
||||
// Это менее надежно, но в данном случае приемлемо.
|
||||
this.menuButton = page.locator('button.NavBar_NavBarButton__apzgO');
|
||||
}
|
||||
|
||||
// --- Методы (действия на странице) ---
|
||||
|
||||
/**
|
||||
* Метод для перехода на страницу логина.
|
||||
*/
|
||||
async goto() {
|
||||
// Переходим в корень сайта, так как у нас там форма логина.
|
||||
// baseURL подставится автоматически из playwright.config.ts
|
||||
await this.page.goto('/login/authorization');
|
||||
}
|
||||
|
||||
/**
|
||||
* Метод для выполнения полного цикла логина.
|
||||
* @param email - email пользователя
|
||||
* @param password - пароль пользователя
|
||||
*/
|
||||
async login(email: string, password: string) {
|
||||
//await expect(this.loginButton).toBeVisible();
|
||||
|
||||
await this.emailInput.fill(email);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.loginButton.click();
|
||||
}
|
||||
|
||||
/**
|
||||
* Метод для перехода на страницу регистрации.
|
||||
*/
|
||||
async goToRegisterPage() {
|
||||
await this.registerLink.click();
|
||||
}
|
||||
}
|
||||
83
page-objects/RecoverPage.ts
Normal file
83
page-objects/RecoverPage.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { type Page, type Locator } from '@playwright/test';
|
||||
|
||||
export class RecoverPage {
|
||||
readonly page: Page;
|
||||
|
||||
// Этап 1: Ввод email
|
||||
readonly emailInput: Locator;
|
||||
readonly continueButton: Locator;
|
||||
readonly continueButton2: Locator;
|
||||
|
||||
// Этап 2: Ввод кода
|
||||
readonly codeInputs: Locator;
|
||||
readonly resendButton: Locator;
|
||||
|
||||
// Этап 3: Ввод нового пароля
|
||||
readonly newPasswordInput: Locator;
|
||||
readonly repeatPasswordInput: Locator;
|
||||
readonly submitPasswordButton: Locator;
|
||||
|
||||
// --- Ошибки ---
|
||||
readonly emailFormatError: Locator;
|
||||
readonly codeError: Locator;
|
||||
readonly passwordError: Locator;
|
||||
readonly passwordRepeatError: Locator;
|
||||
readonly mismatchPasswordError: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
|
||||
// Этап 1
|
||||
this.emailInput = page.getByPlaceholder('Email');
|
||||
this.continueButton = page.getByRole('button', { name: 'Далее' });
|
||||
|
||||
// Этап 2
|
||||
this.codeInputs = page.locator('input[type="text"]'); // предполагаем, 6 полей или одно поле с 6 символами
|
||||
this.resendButton = page.getByRole('button', { name: 'Отправить код повторно' });
|
||||
|
||||
// Этап 3
|
||||
this.newPasswordInput = page.getByPlaceholder('Придумайте пароль');
|
||||
this.repeatPasswordInput = page.getByPlaceholder('Повторите пароль');
|
||||
this.submitPasswordButton = page.getByRole('button', { name: 'Продолжить' });
|
||||
this.continueButton2 = page.getByRole('button', { name: 'Продолжить' });
|
||||
|
||||
// Ошибки
|
||||
this.emailFormatError = page.getByText('Некорректный email*', { exact: true });
|
||||
this.codeError = page.getByText('Ошибка подтверждения', { exact: true });
|
||||
this.passwordError = page.getByText('Некорректный пароль', { exact: true });
|
||||
this.passwordRepeatError = page.getByText('Поле обязательно для заполнения', { exact: true });
|
||||
this.mismatchPasswordError = page.getByText('Пароли не совпадают', { exact: true });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/recoverpassword');
|
||||
}
|
||||
|
||||
async enterEmail(email: string) {
|
||||
await this.emailInput.fill(email);
|
||||
await this.continueButton.click();
|
||||
}
|
||||
|
||||
async enterVerificationCode(code: string) {
|
||||
// Если это один input — просто заполни его
|
||||
if (await this.codeInputs.count() === 1) {
|
||||
await this.codeInputs.first().fill(code);
|
||||
} else {
|
||||
// Если 6 отдельных инпутов, разделяем
|
||||
for (let i = 0; i < code.length; i++) {
|
||||
await this.codeInputs.nth(i).fill(code[i]);
|
||||
}
|
||||
}
|
||||
await this.continueButton2.click();
|
||||
}
|
||||
|
||||
async resendCode() {
|
||||
await this.resendButton.click();
|
||||
}
|
||||
|
||||
async enterNewPassword(password: string, repeat: string) {
|
||||
await this.newPasswordInput.fill(password);
|
||||
await this.repeatPasswordInput.fill(repeat);
|
||||
await this.submitPasswordButton.click();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user