5.7 KiB
5.7 KiB
Test info
- Name: Панель администратора — Новости (негативные сценарии редактирования) >> Очистка полей при редактировании и сохранение
- Location: /Users/vladsmykov/Desktop/Work/AUTOTESTS/CCPC_playwright/tests/ui/admin/news/admin-news-update-negative.spec.ts:7:7
Error details
Error: page.goto: Target page, context or browser has been closed
Call log:
- navigating to "https://ssas.dev.rdcenter.ru/login/authorization", waiting until "load"
at NewsAdminPage.loginAsAdmin (/Users/vladsmykov/Desktop/Work/AUTOTESTS/CCPC_playwright/page-objects/NewsAdminPage.ts:60:21)
at /Users/vladsmykov/Desktop/Work/AUTOTESTS/CCPC_playwright/tests/ui/admin/news/admin-news-update-negative.spec.ts:9:20
Test source
1 | import { Page, Locator } from '@playwright/test';
2 | import path from 'path';
3 |
4 | export class NewsAdminPage {
5 | readonly page: Page;
6 |
7 | // Авторизация
8 | readonly emailInput: Locator;
9 | readonly passwordInput: Locator;
10 | readonly loginButton: Locator;
11 |
12 | // Навигация
13 | readonly adminPanelLink: Locator;
14 |
15 | // Элементы добавления новости
16 | readonly addNewsButton: Locator;
17 | readonly titleTextarea: Locator;
18 | readonly contentTextarea: Locator;
19 | readonly fileInput: Locator;
20 | readonly cropSaveButton: Locator;
21 | readonly confirmAddButton: Locator;
22 | readonly deleteFileButton: Locator;
23 |
24 | // Таблица новостей
25 | readonly newsTable: Locator;
26 |
27 | // Ошибки
28 | readonly emptyTitleError: Locator;
29 | readonly emptyContentError: Locator;
30 |
31 | constructor(page: Page) {
32 | this.page = page;
33 |
34 | // Авторизация
35 | this.emailInput = page.getByPlaceholder('Email');
36 | this.passwordInput = page.getByPlaceholder('Пароль');
37 | this.loginButton = page.getByRole('button', { name: 'Войти', exact: true });
38 |
39 | // Навигация
40 | this.adminPanelLink = page.getByText('Панель администратора');
41 |
42 | // Форма добавления новости
43 | this.addNewsButton = page.getByRole('button', { name: 'Добавить новость' });
44 | this.titleTextarea = page.getByPlaceholder('Заголовок');
45 | this.contentTextarea = page.getByPlaceholder('Текст новости');
46 | this.fileInput = page.locator('input[type="file"]');
47 | this.cropSaveButton = page.getByRole('button', { name: 'Сохранить' });
48 | this.confirmAddButton = page.getByRole('button', { name: 'Добавить' });
49 | this.deleteFileButton = page.locator('img[alt="Удалить файл"]');
50 |
51 | // Таблица новостей
52 | this.newsTable = page.locator('table');
53 |
54 | // Ошибки валидации
55 | this.emptyTitleError = page.getByText('Заголовок новости не может быть пустым.');
56 | this.emptyContentError = page.getByText('Текст новости не может быть пустым.');
57 | }
58 |
59 | async loginAsAdmin() {
> 60 | await this.page.goto('https://ssas.dev.rdcenter.ru/login/authorization');
| ^ Error: page.goto: Target page, context or browser has been closed
61 | await this.emailInput.fill('admin@sfedu.ru');
62 | await this.passwordInput.fill('dfDk1oQQ6YGV@');
63 | await this.loginButton.click();
64 | }
65 |
66 | async navigateToNewsSection() {
67 | await this.page.waitForURL('**/');
68 | await this.adminPanelLink.click();
69 | await this.page.waitForURL('**/adminPage/news');
70 | }
71 |
72 | async goto() {
73 | await this.page.waitForURL('**/');
74 | await this.adminPanelLink.click();
75 | await this.page.waitForURL('**/adminPage/news');
76 | }
77 |
78 | async addNews(params: { title: string; content: string; imagePath: string }) {
79 | const { title, content, imagePath } = params;
80 |
81 | await this.addNewsButton.click();
82 | await this.titleTextarea.fill(title);
83 | await this.contentTextarea.fill(content);
84 |
85 | await this.fileInput.setInputFiles(imagePath);
86 | await this.cropSaveButton.click();
87 | await this.confirmAddButton.click();
88 | }
89 |
90 | async verifyNewsAppears(title: string) {
91 | await this.page.waitForLoadState('networkidle');
92 | await this.newsTable.waitFor();
93 | await this.page.getByText(title).waitFor({ state: 'visible' });
94 | }
95 |
96 | async addEmptyNews() {
97 | await this.addNewsButton.click();
98 | await this.confirmAddButton.click();
99 | }
100 |
101 | async verifyValidationErrors() {
102 | await this.emptyTitleError.waitFor({ state: 'visible' });
103 | await this.emptyContentError.waitFor({ state: 'visible' });
104 | }
105 |
106 | async clickEditButtonForNews(title: string) {
107 | await this.page.locator('tr', { hasText: title }).getByRole('button', { name: 'Редактировать' }).click();
108 | }
109 |
110 | async clickDeleteButtonForNews(title: string) {
111 | await this.page.locator('tr', { hasText: title }).getByRole('button', { name: 'Удалить' }).click();
112 | }
113 |
114 | async deleteExistingImage() {
115 | await this.deleteFileButton.click();
116 | }
117 | }
118 |