Files
playwright-tests-ssas/page-objects/RegisterPage.ts

113 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Page, Locator } from '@playwright/test';
export class RegisterPage {
readonly page: Page;
// Поля ввода
readonly nameInput: Locator;
readonly surnameInput: Locator;
readonly patronymicInput: Locator;
readonly academicTitleInput: Locator;
readonly degreeInput: Locator;
readonly positionInput: Locator;
readonly organizationInput: Locator;
readonly emailInput: Locator;
readonly phoneInput: Locator;
readonly passwordInput: Locator;
readonly confirmPasswordInput: Locator;
// Глазики
readonly passwordToggle: Locator;
readonly confirmPasswordToggle: Locator;
// Кнопка регистрации
readonly submitButton: Locator;
// Ссылка "Авторизируйтесь"
readonly loginLink: Locator;
// Ошибки валидации
readonly requiredFieldErrors: Locator;
readonly nameError: Locator;
readonly surnameError: Locator;
readonly positionError: Locator;
readonly emailFormatError: Locator;
readonly passwordLengthError: Locator;
readonly confirmPasswordRequiredError: Locator;
// Модалки
readonly duplicateUserModal: Locator;
readonly invalidOrgModal: Locator;
constructor(page: Page) {
this.page = page;
// Инпуты
this.nameInput = page.getByPlaceholder('Имя*');
this.surnameInput = page.getByPlaceholder('Фамилия*');
this.patronymicInput = page.getByPlaceholder('Отчество');
this.academicTitleInput = page.getByPlaceholder('Учёное звание*');
this.degreeInput = page.getByPlaceholder('Учёная степень*');
this.positionInput = page.getByPlaceholder('Должность');
this.organizationInput = page.getByPlaceholder('Организация*');
this.emailInput = page.getByPlaceholder('Email (логин)*');
this.phoneInput = page.getByPlaceholder('Номер телефона*');
this.passwordInput = page.getByPlaceholder('Придумайте пароль*');
this.confirmPasswordInput = page.getByPlaceholder('Повторите пароль*');
// Глазики
this.passwordToggle = page.locator('input[name="password"] + img');
this.confirmPasswordToggle = page.locator('input[name="confirmPassword"] + img');
// Кнопки
this.submitButton = page.getByRole('button', { name: 'Зарегистрироваться' });
this.loginLink = page.getByText('Авторизируйтесь');
// Ошибки
this.requiredFieldErrors = page.locator('div[name="error"]', { hasText: 'Поле обязательно для заполнения' });
this.nameError = page.getByText('Некорректное имя');
this.surnameError = page.getByText('Некорректная фамилия');
this.positionError = page.getByText('Не более 200 символов!');
this.emailFormatError = page.getByText('Некорректный Email');
this.passwordLengthError = page.getByText('Не менее 8 символов');
this.confirmPasswordRequiredError = page.getByText('Поле обязательно для заполнения');
// Модальные окна
this.duplicateUserModal = page.getByText('Пользователь с таким email или телефоном уже зарегистрирован!');
this.invalidOrgModal = page.getByText('Некорректное название организации!');
}
async goto() {
await this.page.goto('/login/registration');
}
async register(data: {
name: string,
surname: string,
patronymic?: string,
academicTitle: string,
degree: string,
position?: string,
organization: string,
email: string,
phone: string,
password: string,
confirmPassword: string
}) {
await this.nameInput.fill(data.name);
await this.surnameInput.fill(data.surname);
if (data.patronymic) await this.patronymicInput.fill(data.patronymic);
await this.academicTitleInput.click();
await this.page.locator('li', { hasText: data.academicTitle }).click();
await this.degreeInput.click();
await this.page.locator('li', { hasText: data.degree }).click();
if (data.position) await this.positionInput.fill(data.position);
await this.organizationInput.fill(data.organization);
await this.emailInput.fill(data.email);
await this.phoneInput.fill(data.phone);
await this.passwordInput.fill(data.password);
await this.confirmPasswordInput.fill(data.confirmPassword);
await this.submitButton.click();
}
}