jws-frontend/tests/01-Manage/MenuBranch.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

2120 lines
92 KiB
TypeScript

import { test, expect, Page } from '@playwright/test';
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('http://192.168.1.62:20101/');
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');
// ถ้าทั้งหมดสำเร็จ
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('TC_2_1_001', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
const pageBranch = page.locator(
"//span[normalize-space(text())='จัดการสาขา']",
);
await expect(pageBranch).toHaveText('จัดการสาขา');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('TC_2_1_002', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
const formInformation = page.locator('id=form-information');
const formContact = page.locator('id=form-contact');
const formAddress = page.locator('id=form-address');
const formLocation = page.locator('id=form-location');
const formQrCode = page.locator('id=form-qr');
const formBank = page.locator('id=form-bank');
const formManage = page.locator('id=form-branch-admin-view');
const formAttachment = page.locator('id=form-attachment');
const formRemark = page.locator('id=form-remark');
await expect(formInformation).toBeVisible();
await expect(formContact).toBeVisible();
await expect(formAddress).toBeVisible();
await expect(formLocation).toBeVisible();
await expect(formQrCode).toBeVisible();
await expect(formBank).toBeVisible();
await expect(formManage).toBeVisible();
await expect(formAttachment).toBeVisible();
await expect(formRemark).toBeVisible();
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('TC_2_1_003', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'JWS');
await page.fill("(//input[@id='input-tax-no'])[2]", '1082262426222');
await page.fill(
"(//input[@id='input-name'])[2]",
'บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.fill(
"(//input[@id='input-name-en'])[2]",
'Jobs Worker Service co.,Ltd',
);
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill(
"(//input[@id='input-email'])[2]",
'jwssubport@support.com',
);
await page.fill("(//input[@id='input-telephone-no'])[2]", '022202002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณเอ');
await page.fill("(//input[@id='input-contact'])[2]", '0862242826');
await page.fill("(//input[@id='input-line-id'])[2]", 'JWSChat');
// ส่วนที่อยู่
await page.fill(
"(//input[@id='default-input-address-no'])[2]",
'53 ถนนสุขสวัสดิ์',
);
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click('id=default-select-province_1');
await page.waitForTimeout(1000);
await page.click("(//label[@for='default-select-district'])[2]");
// กำหนดตัวเลือกที่ต้องการ
const targetOptionId = 'id=default-select-district_36'; // id ของตัวเลือกที่ต้องการ
let isVisible = false;
const maxScrollAttempts = 10; // จำนวนครั้งสูงสุดในการเลื่อน
let attempt = 0;
while (!isVisible && attempt < maxScrollAttempts) {
// ตรวจสอบว่า dropdown แสดงหรือไม่
const dropdown = page.locator('#default-select-district_lb');
if ((await dropdown.count()) === 0) {
console.error('ไม่พบ dropdown ที่ต้องการ');
break;
}
// ใช้ page.locator() เลื่อน dropdown ลงไป
await dropdown.evaluate((element) => {
element.scrollTop += 150; // เลื่อนลง 150px
});
// รอให้เลื่อนเสร็จ
await page.waitForTimeout(100); // รอ 0.1 วินาทีเพื่อให้การเลื่อนเสร็จสิ้น
// ตรวจสอบว่าตัวเลือกแสดงอยู่ใน viewport หรือไม่
isVisible = await page.locator(targetOptionId).isVisible();
attempt++;
}
// หากตัวเลือกที่ต้องการอยู่ใน viewport ให้คลิก
if (isVisible) {
const targetOption = page.locator(targetOptionId);
await targetOption.click();
} else {
console.error('ไม่พบตัวเลือกที่ต้องการ');
}
await page.waitForTimeout(1000);
await page.click("(//label[@for='default-select-sub-district'])[2]");
await page.click('id=default-select-sub-district_1');
await page.fill(
"(//input[@id='default-input-address-en'])[2]",
'53 Suk Sawat Rd',
);
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const newOfficeLocator = page.locator(
"//td[contains(.,'บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัดJWS00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัดJWS00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('TC_2_1_004', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
await page.click('id=btn-info-basic-save');
const exceptError = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[10]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of exceptError) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('TC_2_1_005', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
const exceptError = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of exceptError) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('TC_2_1_006', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'TES');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220282');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท คนอ จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'chano');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const newOfficeLocator = page.locator(
"//td[contains(.,'บริษัท คนอ จำกัดTES00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท คนอ จำกัดTES00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('สามารถสร้างสำนักงานใหญ่ได้');
});
test('TC_2_1_007', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'CMM');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท คาโมมายด์ จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'CHAMOMIND');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
const exceptError = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกแขวง/ตำบล',
},
];
for (const error of exceptError) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('TC_2_1_008', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'NES');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท คนา จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'chana');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const newOfficeLocator = page.locator(
"//td[contains(.,'บริษัท คนา จำกัดNES00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท คนา จำกัดNES00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('สามารถสร้างสำนักงานใหญ่ได้');
});
test('TC_2_1_009', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'EES');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท คชา จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'chaca');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const newOfficeLocator = page.locator(
"//td[contains(.,'บริษัท คชา จำกัดEES00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท คชา จำกัดEES00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('สามารถสร้างสำนักงานใหญ่ได้');
});
test('TC_2_1_010', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'MES');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท นารา จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'nara');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const newOfficeLocator = page.locator(
"//td[contains(.,'บริษัท นารา จำกัดMES00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท นารา จำกัดMES00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('สามารถสร้างสำนักงานใหญ่ได้');
});
test('TC_2_1_011', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=btn-kebab-action-บริษัท คนอ จำกัด');
await page.waitForSelector('id=btn-kebab-edit-บริษัท คนอ จำกัด');
await page.click('id=btn-kebab-edit-บริษัท คนอ จำกัด');
const pageEditBranch = page.locator(
"//text[normalize-space(text())='แก้ไข']",
);
await expect(pageEditBranch).toHaveText('แก้ไข');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('ระบบแสดงหน้าแก้ไข');
});
test('TC_2_1_012', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=btn-kebab-action-บริษัท คนอ จำกัด');
await page.waitForSelector('id=btn-kebab-edit-บริษัท คนอ จำกัด');
await page.click('id=btn-kebab-edit-บริษัท คนอ จำกัด');
// แก้ไขสำนักงานใหญ่
await page.fill('id=input-name', 'บริษัท ธนา จำกัด');
await page.fill('id=input-name-en', 'Thana');
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const editOfficeLocator = page.locator(
"//td[contains(.,'บริษัท ธนา จำกัดTES00000')]",
);
await editOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await editOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท ธนา จำกัดTES00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('ระบบแก้ไขสำนักงานใหญ่สำเร็จ');
});
test('TC_2_1_013', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// ลบสำนักงานใหญ่
await page.click('id=btn-kebab-action-บริษัท คนา จำกัด');
await page.waitForSelector('id=btn-kebab-delete-บริษัท คนา จำกัด');
await page.click('id=btn-kebab-delete-บริษัท คนา จำกัด');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
// ตรวจสอบการลบสำนักงานใหญ่
const checkBranchDeleted = await page.locator(
"//tr[contains(.,'บริษัท คนา จำกัด') and contains (.,'81120')]",
);
await expect(checkBranchDeleted).toBeHidden();
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('ระบบไม่สามารถลบได้เนื่องจากสำนักงานใหญ่ถูกใช้งานแล้ว');
});
test('TC_2_1_014', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// เปิดปิดสถานะทดสอบการลบสำนักงานใหญ่ที่ถูกใช้งานแล้ว
await page.click('id=btn-kebab-action-บริษัท นารา จำกัด');
await page.waitForSelector('id=btn-kebab-status-บริษัท นารา จำกัด');
await page.click('id=btn-kebab-status-บริษัท นารา จำกัด', { force: true });
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-kebab-action-บริษัท นารา จำกัด');
await page.waitForSelector('id=btn-kebab-status-บริษัท นารา จำกัด');
await page.click('id=btn-kebab-status-บริษัท นารา จำกัด', { force: true });
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
// ลบสำนักงานใหญ่
await page.click('id=btn-kebab-action-บริษัท นารา จำกัด');
await page.waitForSelector('id=btn-kebab-delete-บริษัท นารา จำกัด');
await page.click('id=btn-kebab-delete-บริษัท นารา จำกัด');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
// ตรวจสอบการแจ้งเตือน Pop Up
const headPopUpError = await page.locator(
"//span[normalize-space(text())='แจ้งเตือน']",
);
const popupErrorDeletedBranch = await page.locator(
"//span[normalize-space(text())='สาขาใช้งานอยู่']",
);
await expect(headPopUpError).toHaveText('แจ้งเตือน');
await expect(popupErrorDeletedBranch).toHaveText('สาขาใช้งานอยู่');
await page.click('id=btn-ok-dialog');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
console.log('ระบบไม่สามารถลบได้เนื่องจากสำนักงานใหญ่ถูกใช้งานแล้ว');
});
// test('TC_2_1_015', async () => {});
// test('TC_2_1_016', async () => {
// if (!isLoginSuccessful) {
// await login(page);
// }
// try {
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// isLoginSuccessful = false;
// throw error;
// }
// });
test('TC_2_1_017', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'AOS');
await page.fill("(//input[@id='input-tax-no'])[2]", '1082262426222');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท แอสโอ จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'Asso co.,Ltd');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill(
"(//input[@id='input-email'])[2]",
'jwssubport@support.com',
);
await page.fill("(//input[@id='input-telephone-no'])[2]", '022202002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณเอ');
await page.fill("(//input[@id='input-contact'])[2]", '0862242826');
await page.fill("(//input[@id='input-line-id'])[2]", 'JWSChat');
// ส่วนที่อยู่
await page.fill(
"(//input[@id='default-input-address-no'])[2]",
'53 ถนนสุขสวัสดิ์',
);
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click('id=default-select-province_1');
await page.waitForTimeout(1000);
await page.click("(//label[@for='default-select-district'])[2]");
// กำหนดตัวเลือกที่ต้องการ
const targetOptionId = 'id=default-select-district_36'; // id ของตัวเลือกที่ต้องการ
let isVisible = false;
const maxScrollAttempts = 10; // จำนวนครั้งสูงสุดในการเลื่อน
let attempt = 0;
while (!isVisible && attempt < maxScrollAttempts) {
// ตรวจสอบว่า dropdown แสดงหรือไม่
const dropdown = page.locator('#default-select-district_lb');
if ((await dropdown.count()) === 0) {
console.error('ไม่พบ dropdown ที่ต้องการ');
break;
}
// ใช้ page.locator() เลื่อน dropdown ลงไป
await dropdown.evaluate((element) => {
element.scrollTop += 150; // เลื่อนลง 150px
});
// รอให้เลื่อนเสร็จ
await page.waitForTimeout(100); // รอ 0.1 วินาทีเพื่อให้การเลื่อนเสร็จสิ้น
// ตรวจสอบว่าตัวเลือกแสดงอยู่ใน viewport หรือไม่
isVisible = await page.locator(targetOptionId).isVisible();
attempt++;
}
// หากตัวเลือกที่ต้องการอยู่ใน viewport ให้คลิก
if (isVisible) {
const targetOption = page.locator(targetOptionId);
await targetOption.click();
} else {
console.error('ไม่พบตัวเลือกที่ต้องการ');
}
await page.waitForTimeout(1000);
await page.click("(//label[@for='default-select-sub-district'])[2]");
await page.click('id=default-select-sub-district_1');
await page.fill(
"(//input[@id='default-input-address-en'])[2]",
'53 Suk Sawat Rd',
);
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
const checkAddressSave = await page.locator(
"//tr[contains(.,'บริษัท แอสโอ จำกัด') and contains (.,'10140')]",
);
await expect(checkAddressSave).toContainText('53 ถนนสุขสวัสดิ์');
await expect(checkAddressSave).toContainText('หมู่ 1');
await expect(checkAddressSave).toContainText('แขวงราษฎร์บูรณะ');
await expect(checkAddressSave).toContainText('เขตราษฎร์บูรณะ');
await expect(checkAddressSave).toContainText('จังหวัดกรุงเทพมหานคร');
await expect(checkAddressSave).toContainText('10140');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('สามารถบันทึกที่อยู่ได้');
});
test('TC_2_1_018', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'CMM');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท คาโมมายด์ จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'CHAMOMIND');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
//ส ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
const exceptError = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกแขวง/ตำบล',
},
];
for (const error of exceptError) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('ระบบทำการแจ้งเตือนให้กรอกที่อยู่ให้ครบ');
});
test('TC_2_1_019', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'MOA');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท โมอา จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'Moaa');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'cmm@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222262');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณต่อ');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'local2024');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.fill("(//input[@id='default-input-moo'])[3]", '1');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
//ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '1202282262226');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.click('id=btn-form-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('สามารถเพิ่มบัญชีธนาคารได้');
});
test('TC_2_1_020', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ตรวจสอบหน้าการเพิ่มสาขา
const showSubbranchCrate = page.locator(
"//form[contains(.,'เพิ่ม สาขา JWS00000') and contains (.,'หมายเหตุหมายเหตุ')]",
);
await expect(showSubbranchCrate).toContainText('เพิ่ม สาขา JWS00000');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบแสดงหน้าเพิ่มสาขา');
});
test('TC_2_1_021', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
for (let i = 0; i < 5; i++) {
try {
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนข้อมูลพื้นฐาน
await page.fill(
"(//input[@id='input-tax-no'])[2]",
`126084622028${i + 1}`,
);
await page.fill("(//input[@id='input-name'])[2]", `สีลม${i + 1}`);
await page.fill("(//input[@id='input-name-en'])[2]", `Silom${i + 1}`);
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill(
"(//input[@id='input-email'])[2]",
`host${i + 1}@local.co.th`,
);
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill(
"(//input[@id='input-contact'])[2]",
`08622864${i + 1}`,
);
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
await page.fill(
"(//input[@id='default-input-address-no'])[2]",
`20/0${i + 1}`,
);
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill(
"(//input[@id='default-input-address-en'])[2]",
`20/0${i + 1}`,
);
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click(`id=select-bankbook_${i + 1}`);
await page.fill(
"(//input[@aria-label='เลขบัญชี'])[2]",
`228202002${i + 1}`,
);
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill(
"(//input[@aria-label='ชื่อบัญชี'])[2]",
'Pongpon Kuntana',
);
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
} catch (error) {
console.error(`เกิดข้อผิดพลาดในรอบที่ ${i + 1}:`, error);
continue;
}
}
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
// ตรวจสอบข้อมูลที่สร้างขึ้น
const branches = ['สีลม1', 'สีลม2', 'สีลม3', 'สีลม4', 'สีลม5'];
for (const branch of branches) {
const branchLocator = page.locator(
`//div[normalize-space(text())='${branch}']`,
);
await branchLocator.waitFor({ state: 'visible' });
const actualText = await branchLocator.textContent();
expect(actualText?.trim()).toBe(branch);
}
console.log('การตรวจสอบสำเร็จ : ข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
console.log('ระบบทำการสร้างสาขาและเพิ่มรหัสาขาอัตโนมัติ');
});
test('TC_2_1_022', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบทำการบังคับให้กรอกข้อมูลในช่องที่จำเป็นต้องกรอก');
});
test('TC_2_1_023', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'host@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '08622864');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/0');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/0');
// ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '228202002');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบทำการแจ้งเตือนในช่องที่ถูกบังคับให้กรอก');
});
test('TC_2_1_024', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-tax-no'])[2]", '126084622028');
await page.fill("(//input[@id='input-name'])[2]", 'สามย่าน');
await page.fill("(//input[@id='input-name-en'])[2]", 'Silom');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/0');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/0');
// ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '228202002');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบสามารถทำการสร้างสาขาได้');
});
test('TC_2_1_025', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220281');
await page.fill("(//input[@id='input-name'])[2]", 'สามย่าน');
await page.fill("(//input[@id='input-name-en'])[2]", 'Silom');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1234423123425',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'host@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '08622864');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
// ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '228202002');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกแขวง/ตำบล',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบทำการแจ้งเตือนให้เพิ่มที่อยู่');
});
test('TC_2_1_026', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220220');
await page.fill("(//input[@id='input-name'])[2]", 'สยาม');
await page.fill("(//input[@id='input-name-en'])[2]", 'Silom');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1234423123425',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'host@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '08622864');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/0');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/0');
// ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '228202002');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('สามารถสร้างสาขาในกรณีที่ไม่เลือก Location ได้');
});
test('TC_2_1_027', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220220');
await page.fill("(//input[@id='input-name'])[2]", 'สยาม');
await page.fill("(//input[@id='input-name-en'])[2]", 'Silom');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1234423123425',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'host@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '08622864');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/0');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/0');
// ส่วนบัญชีธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '228202002');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('สามารถสร้างสาขาในกรณีที่ไม่อัปโหลด QR Code ได้');
});
test('TC_2_1_028', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสร้างสาขา
await page.click(
'id=create-sub-branch-btn-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.waitForSelector("(//button[@type='submit']//div)[1]");
await page.click("(//button[@type='submit']//div)[1]");
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220240');
await page.fill("(//input[@id='input-name'])[2]", 'จตุจักร');
await page.fill("(//input[@id='input-name-en'])[2]", 'Silom');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1234423123425',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'host@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '08622864');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/0');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('สามารถสร้างสาขาในกรณีที่ไม่เพิ่มบัญชีธนาคารได้');
});
test('TC_2_1_029', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าแกไขสร้างสาขา
await page.waitForSelector(
'id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.click('id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด');
await page.waitForSelector('id=btn-kebab-action-สีลม1');
await page.click('id=btn-kebab-action-สีลม1');
await page.waitForSelector('id=btn-kebab-edit-สีลม1');
await page.click('id=btn-kebab-edit-สีลม1');
const pageEditSubBranch = page.locator(
"//text[normalize-space(text())='แก้ไข']",
);
await expect(pageEditSubBranch).toHaveText('แก้ไข');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบแสดงหน้าแก้ไขสาขา');
});
test('TC_2_1_030', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าแก้ไขสร้างสาขา
await page.waitForSelector(
'id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.click('id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด');
await page.waitForSelector('id=btn-kebab-action-สีลม1');
await page.click('id=btn-kebab-action-สีลม1', { force: true });
await page.waitForSelector('id=btn-kebab-edit-สีลม1');
await page.click('id=btn-kebab-edit-สีลม1');
// ส่วนข้อมูลพื่นฐาน
await page.fill('id=input-name', 'เจริญนคร');
await page.fill('id=input-name-en', 'charuengnakorn');
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
//ตรวจสอบหลังจากแก้ไข
const editNameBranchShow = await page.locator(
"//div[normalize-space(text())='เจริญนคร']",
);
await expect(editNameBranchShow).toHaveText('เจริญนคร');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบสามารถแก้ไขสาขาได้');
});
test('TC_2_1_031', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// การเข้าหน้าสาขา
await page.waitForSelector(
'id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
);
await page.click('id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด');
// ลบสาขา
// await page.waitForSelector('id=btn-kebab-action-สีลม5');
await page.waitForTimeout(2000);
await page.click('id=btn-kebab-action-สีลม5', { timeout: 2000 });
await page.waitForSelector('id=btn-kebab-delete-สีลม5');
await page.click('id=btn-kebab-delete-สีลม5');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
//ตรวจสอบหลังจากทำการลบ
const checkBranchDeleted = await page.locator(
"//div[normalize-space(text())='สีลม5']",
);
await expect(checkBranchDeleted).toBeHidden();
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบสามารถทำการลบสาขาได้');
});
// test('TC_2_1_032', async () => {
// if (!isLoginSuccessful) {
// await login(page);
// }
// try {
// // เข้าสู่เมนูสาขา
// await page.click('id=menu.manage');
// await page.waitForSelector('id=sub-menu-branch');
// await page.click('id=sub-menu-branch');
// // การเข้าหน้าแก้ไขสร้างสาขา
// await page.waitForSelector(
// 'id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
// );
// await page.click('id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด');
// // ปิดสถานะ
// await page.waitForSelector('id=btn-kebab-action-สีลม3');
// await page.click('id=btn-kebab-action-สีลม3');
// await page.waitForSelector('id=btn-kebab-status-สีลม3');
// await page.click('id=btn-kebab-status-สีลม3', { force: true });
// await page.waitForSelector('id=btn-ok-dialog');
// await page.click('id=btn-ok-dialog');
// // เปิดสถานะ
// await page.waitForSelector('id=btn-kebab-action-สีลม3');
// await page.click('id=btn-kebab-action-สีลม3');
// await page.waitForTimeout(2000);
// await page.click('id=btn-kebab-status-สีลม3');
// await page.waitForSelector('id=btn-ok-dialog');
// await page.click('id=btn-ok-dialog');
// // ลบสาขา
// await page.waitForSelector('id=btn-kebab-action-สีลม3');
// await page.click('id=btn-kebab-action-สีลม3', { force: true });
// await page.waitForSelector('id=btn-kebab-delete-สีลม3');
// await page.click('idbtn-kebab-delete-สีลม3');
// await page.waitForSelector('id=btn-ok-dialog');
// await page.click('id=btn-ok-dialog');
// //ตรวจสอบหลังจากแก้ไข
// const headPopUpError = await page.locator(
// "//span[normalize-space(text())='แจ้งเตือน']",
// );
// const detailPopupError = await page.locator(
// "//span[normalize-space(text())='สาขาใช้งานอยู่']",
// );
// await expect(headPopUpError).toHaveText('แจ้งเตือน');
// await expect(detailPopupError).toHaveText('สาขาใช้งานอยู่');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// isLoginSuccessful = false;
// throw error;
// }
// await page.waitForTimeout(2000);
// console.log('ระบบไม่สามารถทำการลบสาขาได้เนื่องจากสาขาถูกใช้งานไปแล้ว');
// });
test('TC_2_1_033', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
const showAmountBranch = page.locator(
"(//div[contains(@class,'stat-card__content row')])[1]",
);
const showAmountSubBranch = page.locator(
"(//div[contains(@class,'stat-card__content row')])[2]",
);
const showAmountServicepoint = page.locator(
"(//div[contains(@class,'stat-card__content row')])[3]",
);
// รอ Locator แสดง
await showAmountBranch.waitFor({ state: 'visible' });
await showAmountSubBranch.waitFor({ state: 'visible' });
await showAmountServicepoint.waitFor({ state: 'visible' });
// ดึงค่าข้อความ
const branchText = await showAmountBranch.textContent();
const subBranchText = await showAmountSubBranch.textContent();
const servicePointText = await showAmountServicepoint.textContent();
console.log(`สำนักงานใหญ่ : ${branchText?.trim()}`);
console.log(`สาขา : ${subBranchText?.trim()}`);
console.log(`จุดรับบริการ : ${servicePointText?.trim()}`);
// ตรวจสอบว่าค่าแสดงตัวเลขหรือไม่
expect(branchText).toMatch(/\d+/);
expect(subBranchText).toMatch(/\d+/);
expect(servicePointText).toMatch(/\d+/);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
console.log('ระบบแสดงจำนวนสำนักงานใหญ่,สาขา,จุดรับบริการ');
});
// test('TC_2_1_034', async () => {
// if (!isLoginSuccessful) {
// await login(page);
// }
// try {
// // เข้าสู่เมนูสาขา
// await page.click('id=menu.manage');
// await page.waitForSelector('id=sub-menu-branch');
// await page.click('id=sub-menu-branch');
// // การเข้าหน้าสาขา
// await page.waitForSelector(
// 'id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด',
// );
// await page.click('id=tree-enter-บริษัทจ็อบเวิร์คเกอร์ เซอร์วิส จำกัด');
// const showAmountBranch = page.locator(
// "(//div[contains(@class,'stat-card__content row')])[1]",
// );
// const showAmountSubBranch = page.locator(
// "(//div[contains(@class,'stat-card__content row')])[2]",
// );
// const showAmountServicepoint = page.locator(
// "(//div[contains(@class,'stat-card__content row')])[3]",
// );
// // รอ Locator แสดง
// await showAmountBranch.waitFor({ state: 'visible' });
// await showAmountSubBranch.waitFor({ state: 'visible' });
// await showAmountServicepoint.waitFor({ state: 'visible' });
// // ดึงค่าข้อความ
// const branchText = await showAmountBranch.textContent();
// const subBranchText = await showAmountSubBranch.textContent();
// const servicePointText = await showAmountServicepoint.textContent();
// console.log(`สำนักงานใหญ่ : ${branchText?.trim()}`);
// console.log(`สาขา : ${subBranchText?.trim()}`);
// console.log(`จุดรับบริการ : ${servicePointText?.trim()}`);
// // ตรวจสอบว่าค่าแสดงตัวเลขหรือไม่
// expect(branchText).toMatch(/\d+/);
// expect(subBranchText).toMatch(/\d+/);
// expect(servicePointText).toMatch(/\d+/);
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// isLoginSuccessful = false;
// throw error;
// }
// await page.waitForTimeout(2000);
// console.log('ระบบแสดงจำนวนสำนักงานใหญ่,สาขา,จุดรับบริการ');
// });