This commit is contained in:
parent
0150f80ba2
commit
272183bca9
77 changed files with 9957 additions and 144 deletions
365
tests/02-Sales/MenuQuotation.spec.ts
Normal file
365
tests/02-Sales/MenuQuotation.spec.ts
Normal file
|
|
@ -0,0 +1,365 @@
|
|||
import { test, expect, Page } from '@playwright/test';
|
||||
import { de, fakerEN, fakerTH } from '@faker-js/faker';
|
||||
import { isAwaitExpression } from 'typescript';
|
||||
|
||||
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.sales');
|
||||
await page.waitForSelector('id=sub-menu-quotation');
|
||||
await page.click('id=sub-menu-quotation');
|
||||
|
||||
// ถ้าทั้งหมดสำเร็จ
|
||||
isLoginSuccessful = true;
|
||||
console.log('ระบบทำการ Login สำเร็จ');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการ Login');
|
||||
isLoginSuccessful = false;
|
||||
}
|
||||
}
|
||||
test('Login', async () => {
|
||||
await login(page);
|
||||
});
|
||||
|
||||
test('TC_3_0_001', async () => {
|
||||
// ถ้ายังไม่ได้ Login ให้ทำการ Login
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
try {
|
||||
// เข้าสู่เมนูใบเสนอราคา
|
||||
const pageAgencies = page.locator(
|
||||
"//span[contains(@class,'title-gradient text-weight-bold')]",
|
||||
);
|
||||
await expect(pageAgencies).toHaveText('ใบเสนอราคา');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
await page.waitForTimeout(2000);
|
||||
console.log('ระบบแสดงหน้าเมนูใบเสนอราคา');
|
||||
});
|
||||
|
||||
test('TC_3_0_002', async () => {
|
||||
// ถ้ายังไม่ได้ Login ให้ทำการ Login
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
try {
|
||||
// เข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
await page.click('id=btn-add');
|
||||
|
||||
const pageQuatationTitle = page.locator(
|
||||
"//div[contains(@class,'col text-subtitle1')]",
|
||||
);
|
||||
const dropdownServiceQuatation = page.locator('id=select-hq-id');
|
||||
const dropdownSelectCustomer = page.locator('id=select-customer');
|
||||
|
||||
await expect(pageQuatationTitle).toHaveText('เพิ่มใบเสนอราคา');
|
||||
await expect(dropdownServiceQuatation).toBeVisible();
|
||||
await expect(dropdownSelectCustomer).toBeVisible();
|
||||
|
||||
await page.click('id=btn-form-cancel');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
await page.waitForTimeout(2000);
|
||||
console.log('ระบบแสดง Pop Up เพิ่มใบเสนอราคา');
|
||||
});
|
||||
|
||||
test('TC_3_0_003', async () => {
|
||||
// ถ้ายังไม่ได้ Login ให้ทำการ Login
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
try {
|
||||
// เข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
await page.click('id=btn-add');
|
||||
|
||||
// เพิ่มใบเสนอราคาเพื่อเข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
await page.waitForSelector('id=select-hq-id');
|
||||
await page.click('id=select-hq-id');
|
||||
await page.waitForSelector('id=select-hq-id_1');
|
||||
await page.click('id=select-hq-id_1');
|
||||
await page.waitForSelector('id=select-customer');
|
||||
await page.click('id=select-customer');
|
||||
await page.waitForSelector('id=select-customer_1');
|
||||
await page.click('id=select-customer_1');
|
||||
await page.waitForSelector('id=btn-form-submit');
|
||||
await page.click('id=btn-form-submit');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// ตรวจสอบหลังจากเข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
|
||||
const titlePageQuotation = page.locator(
|
||||
"//header[contains(.,'ใบเสนอราคา')]",
|
||||
);
|
||||
await expect(titlePageQuotation).toBeVisible();
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
await page.waitForTimeout(2000);
|
||||
console.log('ระบบเข้าสู่หน้าเพิ่มใบเสนอราคา');
|
||||
});
|
||||
|
||||
test('TC_3_0_004', async () => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
// เข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
await page.click('id=btn-add');
|
||||
|
||||
// เลือก HQ
|
||||
await page.waitForSelector('id=select-hq-id');
|
||||
await page.click('id=select-hq-id');
|
||||
await page.waitForSelector('id=select-hq-id_1');
|
||||
await page.click('id=select-hq-id_1');
|
||||
|
||||
// เลือกลูกค้า
|
||||
await page.waitForSelector('id=select-customer');
|
||||
await page.click('id=select-customer');
|
||||
await page.waitForSelector('id=select-customer_1');
|
||||
await page.click('id=select-customer_1');
|
||||
|
||||
// ตรวจสอบว่าหน้าเปลี่ยนใน tab เดิม หรือเปิดหน้าใหม่
|
||||
const [newPage] = await Promise.all([
|
||||
page
|
||||
.context()
|
||||
.waitForEvent('page')
|
||||
.catch(() => null), // ตรวจจับหน้าใหม่
|
||||
page.click('id=btn-form-submit'),
|
||||
]);
|
||||
|
||||
// ใช้หน้าใหม่ถ้ามี หรือหน้าเดิมถ้าไม่มี
|
||||
const newTab = newPage || page;
|
||||
await newTab.waitForLoadState('networkidle');
|
||||
|
||||
// ตรวจสอบ URL เพื่อ debug
|
||||
console.log(' URL ปัจจุบัน:', newTab.url());
|
||||
|
||||
// กรอกข้อมูลในฟอร์ม
|
||||
await newTab.fill('id=input-work-name', 'MOU');
|
||||
await newTab.fill('id=input-contact-name', fakerTH.person.fullName());
|
||||
await newTab.fill('id=input-telephone', '0882273282');
|
||||
|
||||
// บันทึกใบเสนอราคา
|
||||
await newTab.click('id=btn-save');
|
||||
|
||||
// ตรวจสอบว่าแสดงปุ่ม Edit
|
||||
const showButtonEdit = newTab.locator('id=btn-edit');
|
||||
await expect(showButtonEdit).toBeVisible();
|
||||
// ปิดหน้าต่างใบเสนอราคา
|
||||
await newTab.click('id=btn-close');
|
||||
await newTab.waitForSelector('id=btn-ok-dialog');
|
||||
await newTab.click('id=btn-ok-dialog');
|
||||
} catch (error) {
|
||||
console.error(' เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
await page.waitForTimeout(2000);
|
||||
console.log(' ระบบบันทึกใบเสนอราคาและเห็นปุ่มแก้ไข');
|
||||
});
|
||||
|
||||
test('TC_3_0_005', async ({ page, context }) => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
// เก็บจำนวนหน้าเดิมก่อนกด
|
||||
const oldPages = context.pages();
|
||||
|
||||
// เข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
await page.click('id=btn-add');
|
||||
|
||||
// เลือก HQ
|
||||
await page.waitForSelector('id=select-hq-id');
|
||||
await page.click('id=select-hq-id');
|
||||
await page.waitForSelector('id=select-hq-id_1');
|
||||
await page.click('id=select-hq-id_1');
|
||||
|
||||
// เลือกลูกค้า
|
||||
await page.waitForSelector('id=select-customer');
|
||||
await page.click('id=select-customer');
|
||||
await page.waitForSelector('id=select-customer_1');
|
||||
await page.click('id=select-customer_1');
|
||||
|
||||
// ตรวจสอบว่าหน้าเปลี่ยนใน tab เดิม หรือเปิดหน้าใหม่
|
||||
await Promise.all([
|
||||
page.click('id=btn-form-submit'),
|
||||
context.waitForEvent('page').catch(() => null),
|
||||
page.waitForLoadState('networkidle'),
|
||||
]);
|
||||
|
||||
// ตรวจจับหน้าใหม่ถ้ามี
|
||||
const newPages = context.pages().filter((p) => !oldPages.includes(p));
|
||||
const newTab = newPages.length > 0 ? newPages[0] : page;
|
||||
|
||||
// ตรวจสอบ URL เพื่อ debug
|
||||
console.log(' URL ปัจจุบัน:', newTab.url());
|
||||
|
||||
// ข้อมูลที่ต้องการทดสอบ
|
||||
const initialContactName = fakerTH.person.fullName();
|
||||
const updatedContactName = fakerTH.person.fullName();
|
||||
|
||||
// กรอกข้อมูลในฟอร์ม
|
||||
await newTab.fill('id=input-work-name', 'MOU');
|
||||
await newTab.fill('id=input-contact-name', initialContactName);
|
||||
await newTab.fill('id=input-telephone', '0882273282');
|
||||
|
||||
// บันทึกใบเสนอราคา
|
||||
await newTab.click('id=btn-save');
|
||||
|
||||
// ทดสอบการแก้ไขใบเสนอราคา
|
||||
await newTab.click('id=btn-edit');
|
||||
await newTab.fill('id=input-contact-name', updatedContactName);
|
||||
await newTab.click('id=btn-save');
|
||||
|
||||
// ตรวจสอบว่าข้อมูลถูกแก้ไขสำเร็จ
|
||||
const editedContactName = newTab.locator(
|
||||
`//input[@value='${updatedContactName}']`,
|
||||
);
|
||||
await expect(editedContactName).toBeVisible();
|
||||
|
||||
// ปิดหน้าต่างใบเสนอราคา
|
||||
await newTab.click('id=btn-close');
|
||||
await newTab.waitForSelector('id=btn-ok-dialog');
|
||||
await newTab.click('id=btn-ok-dialog');
|
||||
} catch (error) {
|
||||
console.error(' เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
console.log(' ระบบสามารถแก้ไขใบเสนอราคาได้');
|
||||
await page.waitForTimeout(2000);
|
||||
});
|
||||
|
||||
test('TC_3_0_006', async ({ page, context }) => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
// เก็บจำนวนหน้าเดิมก่อนกด
|
||||
const oldPages = context.pages();
|
||||
|
||||
// // เข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
// await page.click("(//button[@id='btn-eye-MOU'])[1]");
|
||||
|
||||
// ตรวจสอบว่าหน้าเปลี่ยนใน tab เดิม หรือเปิดหน้าใหม่
|
||||
await Promise.all([
|
||||
page.click("(//button[@id='btn-eye-MOU'])[1]"),
|
||||
context.waitForEvent('page').catch(() => null),
|
||||
page.waitForLoadState('networkidle'),
|
||||
]);
|
||||
|
||||
// ตรวจจับหน้าใหม่ถ้ามี
|
||||
const newPages = context.pages().filter((p) => !oldPages.includes(p));
|
||||
const newTab = newPages.length > 0 ? newPages[0] : page;
|
||||
|
||||
// ตรวจสอบ URL เพื่อ debug
|
||||
console.log(' URL ปัจจุบัน:', newTab.url());
|
||||
|
||||
// เปิดแท็ปลูกค้าตอบรับ
|
||||
await newTab.click('id=btn-status-Accepted');
|
||||
|
||||
// ยืนยันลูกค้าตอบรับ
|
||||
await newTab.waitForSelector('id=btn-submit-accepted');
|
||||
await newTab.click('id=btn-submit-accepted');
|
||||
await newTab.waitForSelector('id=btn-ok-dialog');
|
||||
await newTab.click('id=btn-ok-dialog');
|
||||
|
||||
// ตรวจสอบว่าลูกค้าตอบรับแล้ว
|
||||
const acceptedSubmit = newTab.locator('id=btn-submit-accepted');
|
||||
await expect(acceptedSubmit).toBeHidden();
|
||||
|
||||
// ปิดหน้าต่างใบเสนอราคา
|
||||
await newTab.click('id=btn-close');
|
||||
await newTab.waitForSelector('id=btn-ok-dialog');
|
||||
await newTab.click('id=btn-ok-dialog');
|
||||
} catch (error) {
|
||||
console.error(' เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
console.log(' ระบบทำการยืนยันลูกค้าตอบรับ');
|
||||
await page.waitForTimeout(2000);
|
||||
});
|
||||
|
||||
test('TC_3_0_007', async ({ page, context }) => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
// เก็บจำนวนหน้าเดิมก่อนกด
|
||||
const oldPages = context.pages();
|
||||
|
||||
// // เข้าสู่หน้าเพิ่มใบเสนอราคา
|
||||
await page.click("(//div[@role='tab'])[2]");
|
||||
|
||||
// ตรวจสอบว่าหน้าเปลี่ยนใน tab เดิม หรือเปิดหน้าใหม่
|
||||
await Promise.all([
|
||||
page.click('id=btn-eye-MOU'),
|
||||
context.waitForEvent('page').catch(() => null),
|
||||
page.waitForLoadState('networkidle'),
|
||||
]);
|
||||
|
||||
// ตรวจจับหน้าใหม่ถ้ามี
|
||||
const newPages = context.pages().filter((p) => !oldPages.includes(p));
|
||||
const newTab = newPages.length > 0 ? newPages[0] : page;
|
||||
|
||||
// ตรวจสอบ URL เพื่อ debug
|
||||
console.log(' URL ปัจจุบัน:', newTab.url());
|
||||
|
||||
// เปิดแท็ปใบแจ้งหนี้
|
||||
await newTab.click('id=btn-status-Invoice');
|
||||
|
||||
// อนุมัติใบแจ้งหนี้
|
||||
await newTab.waitForSelector('id=btn-approve-invoice');
|
||||
await newTab.click('id=btn-approve-invoice');
|
||||
|
||||
// ตรวจสอบว่าอนุมัติใบแจ้งหนี้แล้ว
|
||||
const acceptedSubmit = newTab.locator('id=btn-approve-invoice');
|
||||
await expect(acceptedSubmit).toBeHidden();
|
||||
|
||||
// ปิดหน้าต่างใบเสนอราคา
|
||||
await newTab.click('id=btn-close');
|
||||
await newTab.waitForSelector('id=btn-ok-dialog');
|
||||
await newTab.click('id=btn-ok-dialog');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
console.log('ระบบทำการอนุมัติใบแจ้งหนี้');
|
||||
await page.waitForTimeout(2000);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue