jws-frontend/tests/01-Manage/04-ProductandService/JWS_PD_006_CreatePackageFail.spec.ts
Linpiing 272183bca9
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 6s
update
2025-05-22 09:26:31 +07:00

77 lines
2.5 KiB
TypeScript

import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page: Page) {
try {
// Login
await page.goto('/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
await page.click('id=menu-icon-product-service');
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
// เข้าสู่หน้าประเภท
await page.waitForSelector('id=tree-enter-ประเภท-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-ประเภท-ประกัน');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มประเภท', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เพิ่มประเภท
await page.click('id=btn-add');
await page.click('id=btn-add-service');
// บันทึกการสร้างประเภท
await page.click('id=btn-form-submit');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const typeCodeError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameTypeError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(typeCodeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameTypeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});