Добавил LoginPage,а также позитивные UI, API тесты для авторизации пользователя
This commit is contained in:
8
fixtures/users.ts
Normal file
8
fixtures/users.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// fixtures/users.ts
|
||||||
|
export const testUsers = {
|
||||||
|
applicant: {
|
||||||
|
login: 'autotestapplicant',
|
||||||
|
password: '!Test123456',
|
||||||
|
id: '85d99f9f-1abd-45e8-a952-8da45ee7e63f',
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
"test:clean": "rm -rf allure-results allure-report playwright-report",
|
"test:clean": "rm -rf allure-results allure-report playwright-report",
|
||||||
"test:ui": "npx playwright test tests/ui",
|
"test:ui": "npx playwright test tests/ui",
|
||||||
"test:api": "npx playwright test tests/api",
|
"test:api": "npx playwright test tests/api",
|
||||||
|
"test:login": "npx playwright test tests/ui/auth/login-applicant.spec.ts",
|
||||||
"report": "npx playwright show-report",
|
"report": "npx playwright show-report",
|
||||||
"allure:report": "allure generate ./allure-results --clean -o ./allure-report && allure open ./allure-report"
|
"allure:report": "allure generate ./allure-results --clean -o ./allure-report && allure open ./allure-report"
|
||||||
},
|
},
|
||||||
|
|||||||
31
page-objects/LoginPage.ts
Normal file
31
page-objects/LoginPage.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// page-objects/LoginPage.ts
|
||||||
|
|
||||||
|
import { Page } from '@playwright/test';
|
||||||
|
|
||||||
|
export class LoginPage {
|
||||||
|
readonly page: Page;
|
||||||
|
|
||||||
|
constructor(page: Page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
async goto() {
|
||||||
|
await this.page.goto('/authorization'); // или '/auth', если маршрут другой
|
||||||
|
}
|
||||||
|
|
||||||
|
async fillLogin(login: string) {
|
||||||
|
await this.page.fill('input[name="login"]', login);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fillPassword(password: string) {
|
||||||
|
await this.page.fill('input[name="password"]', password);
|
||||||
|
}
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
await this.page.click('button[type="submit"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
async assertSuccessfulLogin() {
|
||||||
|
await this.page.waitForURL('**/account/profile'); // или '/', если перебрасывает на главную
|
||||||
|
}
|
||||||
|
}
|
||||||
18
tests/api/auth/login-applicant.api.spec.ts
Normal file
18
tests/api/auth/login-applicant.api.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const BASE_URL = 'https://rumc.dev.rdcenter.ru/api';
|
||||||
|
|
||||||
|
test('API: успешная авторизация абитуриента', async () => {
|
||||||
|
const payload = {
|
||||||
|
login: 'autotestapplicant',
|
||||||
|
password: '!Test123456',
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await axios.post(`${BASE_URL}/auth/login`, payload);
|
||||||
|
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(res.data).toHaveProperty('access_token');
|
||||||
|
|
||||||
|
console.log('✅ Авторизация успешна. Access token:', res.data.access_token);
|
||||||
|
});
|
||||||
18
tests/ui/auth/login-applicant.spec.ts
Normal file
18
tests/ui/auth/login-applicant.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// tests/ui/auth/login-applicant.spec.ts
|
||||||
|
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { LoginPage } from '../../../page-objects/LoginPage';
|
||||||
|
import { testUsers } from '../../../fixtures/users';
|
||||||
|
|
||||||
|
test('UI: успешная авторизация абитуриента', async ({ page }) => {
|
||||||
|
const loginPage = new LoginPage(page);
|
||||||
|
const user = testUsers.applicant;
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.fillLogin(user.login);
|
||||||
|
await loginPage.fillPassword(user.password);
|
||||||
|
await loginPage.submit();
|
||||||
|
await loginPage.assertSuccessfulLogin();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(/\/account\/profile$/);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user