jws-frontend/tests/01-Manage/04-ProductandService/JWS_PD_006_CreatePackageFail.spec.ts

78 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-09-26 11:05:54 +07:00
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
2024-12-03 17:59:46 +07:00
let isLoginSuccessful = false;
2024-09-26 11:05:54 +07:00
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
2024-12-03 17:59:46 +07:00
async function login(page) {
try {
// Login
2025-01-13 11:47:01 +07:00
await page.goto('/');
2024-12-03 17:59:46 +07:00
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;
}
}
2024-09-26 11:05:54 +07:00
test('Login', async () => {
2024-12-03 17:59:46 +07:00
await login(page);
2024-09-26 11:05:54 +07:00
});
test('ทดสอบการเพิ่มประเภท', async () => {
2024-12-03 17:59:46 +07:00
if (!isLoginSuccessful) {
await login(page);
}
2024-09-26 11:05:54 +07:00
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('เกิดข้อผิดการในการทดสอบ');
2024-12-03 17:59:46 +07:00
isLoginSuccessful = false;
2024-09-26 11:05:54 +07:00
throw error;
}
await page.waitForTimeout(2000);
});