update test

This commit is contained in:
Linpiing 2024-12-03 17:59:46 +07:00 committed by Thanaphon Frappet
parent f3982978fa
commit c4bdd18deb
123 changed files with 12136 additions and 5001 deletions

View file

@ -0,0 +1,181 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Corporate Customer', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'corporatecus');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_0');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'บุญมา');
await page.fill('id=form-dialog-personnel-input-last-name', 'พามา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Bunma');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Pama');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill(
'id=form-dialog-personnel-input-email',
'cocustomer@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-24']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='บุญมา พามา']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('บุญมา พามา');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Corporate Customer ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'corporatecus');
await page.fill("input[name='password']", 'corporatecus');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'corporcu@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Corporate Customer']")
.textContent();
expect(useRole?.trim()).toBe('Corporate Customer');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Corporate Customer');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Corporate Customer ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Corporate Cutomer สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,185 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Head of Admin', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'headofad');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_1');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธนินทร์');
await page.fill('id=form-dialog-personnel-input-last-name', 'ประเสริฐปัตตนา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thanin');
await page.fill(
'id=form-dialog-personnel-input-last-name-en',
'Prasertpattana',
);
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'hoa@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธนินทร์ ประเสริฐปัตตนา']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธนินทร์ ประเสริฐปัตตนา');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Head of Admin ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'headofad');
await page.fill("input[name='password']", 'headofad');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'headofadmin@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Head Of Admin']")
.textContent();
expect(useRole?.trim()).toBe('Head Of Admin');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Head of Admin');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Head of Admin ปรากฏ
const menuBranchManagement = await page.isVisible('id=drawer-menu.branch');
const menuPersonnelManagement = await page.isVisible('id=drawer-menu.user');
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuBranchManagement).toBe(true);
expect(menuPersonnelManagement).toBe(true);
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Head of Admin สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,184 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Sale', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'sale');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_2');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'เกียรติ');
await page.fill(
'id=form-dialog-personnel-input-last-name',
'อินทรประสิทธิ์ ',
);
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Kiat');
await page.fill(
'id=form-dialog-personnel-input-last-name-en',
'Intaraprasith',
);
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'sale@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='เกียรติ อินทรประสิทธิ์']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('เกียรติ อินทรประสิทธิ์');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Sale ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'sale');
await page.fill("input[name='password']", 'sale');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'sale@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Sale']")
.textContent();
expect(useRole?.trim()).toBe('Sale');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Sale');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Sale ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Sale สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,178 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Document Checker', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'doccheck');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_3');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'พสธร');
await page.fill('id=form-dialog-personnel-input-last-name', 'เลิศวิทยา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Possathorn');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Lertwittaya');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'doccheck@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='พสธร เลิศวิทยา']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('พสธร เลิศวิทยา');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Document Checker ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'doccheck');
await page.fill("input[name='password']", 'doccheck');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'docchecker@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Document Checker']")
.textContent();
expect(useRole?.trim()).toBe('Document Checker');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Document Checker');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Document Checker ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Document Checker สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,178 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Sale Agent', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'saleag');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_4');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ภาสกร');
await page.fill('id=form-dialog-personnel-input-last-name', 'อุดมเสก');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Passorn');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Udomsek');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'saleag@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ภาสกร อุดมเสก']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ภาสกร อุดมเสก');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Sale Agent ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'saleag');
await page.fill("input[name='password']", 'saleag');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'saleag@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Sale Agent']")
.textContent();
expect(useRole?.trim()).toBe('Sale Agent');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Sale Agent');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Sale Agent ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Sale Agent สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,178 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Messenger', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'message');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_5');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธนัท');
await page.fill('id=form-dialog-personnel-input-last-name', 'จรัสวงศ์');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thanat');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Jaraswong');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'message@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธนัท จรัสวงศ์']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธนัท จรัสวงศ์');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Messenger ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'message');
await page.fill("input[name='password']", 'message');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'message@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Messenger']")
.textContent();
expect(useRole?.trim()).toBe('Messenger');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Messenger');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Messenger ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Messenger สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,176 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Account', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'account');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธาวัน');
await page.fill('id=form-dialog-personnel-input-last-name', 'บุญดี');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thawan');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Boondee');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'account@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธาวัน บุญดี']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธาวัน บุญดี');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Account ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'account');
await page.fill("input[name='password']", 'account');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'account@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Account']")
.textContent();
expect(useRole?.trim()).toBe('Account');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Account');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Account ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Account สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,180 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Admin', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'admins');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_7');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธีรญาณ');
await page.fill('id=form-dialog-personnel-input-last-name', 'สุขเกษม');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Theerayan');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Sukkasem');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'admin@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธีรญาณ สุขเกษม']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธีรญาณ สุขเกษม');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Admin ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'admins');
await page.fill("input[name='password']", 'admins');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'admins@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Admin']")
.textContent();
expect(useRole?.trim()).toBe('Admin');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Admin');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Admin ปรากฏ
const menuBranchManagement = await page.isVisible('id=drawer-menu.branch');
const menuPersonnelManagement = await page.isVisible('id=drawer-menu.user');
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuBranchManagement).toBe(true);
expect(menuPersonnelManagement).toBe(true);
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Admin สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,179 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Executive', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'executive');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_8');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ทีปกร');
await page.fill('id=form-dialog-personnel-input-last-name', 'สุวรรณเวชธาดา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Teepakorn');
await page.fill(
'id=form-dialog-personnel-input-last-name-en',
'Suwanwechatada',
);
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'executive@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ทีปกร สุวรรณเวชธาดา']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ทีปกร สุวรรณเวชธาดา');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Executive ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'executive');
await page.fill("input[name='password']", 'executive');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'executive@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Executive']")
.textContent();
expect(useRole?.trim()).toBe('Executive');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Executive');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Executive ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Executive สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,176 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Data Entry', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'dataentry');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_9');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'กนกพงศ์');
await page.fill('id=form-dialog-personnel-input-last-name', 'ดุสิตวรรณ');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Kanokpong');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Dusitwan');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'dataen@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='กนกพงศ์ ดุสิตวรรณ']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('กนกพงศ์ ดุสิตวรรณ');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Data Entry ', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'dataentry');
await page.fill("input[name='password']", 'dataentry');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'dataen@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Data Entry']")
.textContent();
expect(useRole?.trim()).toBe('Data Entry');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Data Entry');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Data Entry ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Data Entry สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,178 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Head of Account', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'headacc');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_10');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ฐิติกร');
await page.fill('id=form-dialog-personnel-input-last-name', 'วงวรางค์');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thitikorn');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Wongwarang');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'headac@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ฐิติกร วงวรางค์']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ฐิติกร วงวรางค์');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Head of Account', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'headacc');
await page.fill("input[name='password']", 'headacc');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'headac@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Head Of Account']")
.textContent();
expect(useRole?.trim()).toBe('Head Of Account');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Head of Account');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Head of Account ปรากฏ
const menuBranchManagement = await page.isVisible('id=drawer-menu.branch');
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuBranchManagement).toBe(true);
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Head of Account สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,179 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Head of Sale', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'headsale');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_11');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'พลภัทร');
await page.fill('id=form-dialog-personnel-input-last-name', 'ธนเจริญกิจ');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Polapat');
await page.fill(
'id=form-dialog-personnel-input-last-name-en',
'Tanajaroenkij',
);
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'headsale@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='พลภัทร ธนเจริญกิจ']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('พลภัทร ธนเจริญกิจ');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Head of Sale', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'headsale');
await page.fill("input[name='password']", 'headsale');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'headsale@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Head Of Sale']")
.textContent();
expect(useRole?.trim()).toBe('Head Of Sale');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Head of Sale');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Head of Sale ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Head of Sale สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,179 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Personal Customer', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'personal');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_12');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ทีปกร');
await page.fill('id=form-dialog-personnel-input-last-name', 'จันทรประการ');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Teepakorn');
await page.fill(
'id=form-dialog-personnel-input-last-name-en',
'Jantaraprakarn',
);
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'personal@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ทีปกร จันทรประการ']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ทีปกร จันทรประการ');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Personal Customer', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'personal');
await page.fill("input[name='password']", 'personal');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'personal@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Personal Customer']")
.textContent();
expect(useRole?.trim()).toBe('Personal Customer');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Personal Customer');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Personal Customer ปรากฏ
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Personal Customer สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,178 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import { waitForDebugger } from 'inspector';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('Create Personnel - ตำแหน่ง Branch Manager', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'branch');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_13');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'จิรัณ');
await page.fill('id=form-dialog-personnel-input-last-name', 'ดุสิตวรรณ');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Jiran');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Dusitwan');
await page.fill('id=form-dialog-personnel-input-telephone', '08422644482');
await page.fill('id=form-dialog-personnel-input-email', 'branch@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("//div[@id='2024-09-08']/div[1]");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[@id='2024-09-12']/div[1]");
await page.click('id=input-retire-date');
await page.click("//div[@id='2024-09-16']/div[1]");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='จิรัณ ดุสิตวรรณ']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('จิรัณ ดุสิตวรรณ');
console.log(displayName);
console.log('ตรวจสอบการสร้างตำแหน่งงานถูกต้อง');
await page.waitForTimeout(4000);
});
test('ทดสอบการเข้าใช้งาน ผู้ใช้งานสิทธิ์ Branch Manager', async () => {
try {
// ออกจากระบบและเข้าสู่ระบบด้วย Role ใหม่
await page.click('id=btn-profile-menu');
await page.click('id=btn-logout');
await page.click('id=btn-ok-dialog');
await page.fill("input[name='username']", 'branch');
await page.fill("input[name='password']", 'branch');
await page.click('id=kc-login');
// ใส่รหัสใหม่
await page.fill('id=password-new', '1234');
await page.fill('id=password-confirm', '1234');
await page.click("//input[@type='submit']");
// กรอกอีเมลเพื่อสร้างผู้ใช้งานใหม่
await page.fill('id=email', 'branch@email.com');
await page.click("//input[@type='submit']");
await page.waitForTimeout(2000);
// ตรวจสอบข้อมูลหลังจากทำการเข้าสู่ระบบ
const useRole = await page
.locator("//div[normalize-space(text())='Branch Manager']")
.textContent();
expect(useRole?.trim()).toBe('Branch Manager');
console.log('ตรวจสอบสำเร็จ : สิทธิ์ผู้ใช้งานประเภท Branch Manager');
// ตรวจสอบเมนูสำหรับสิทธิ์ผู้ใช้งานประเภท Branch Manager ปรากฏ
const menuPersonnelManagement = await page.isVisible('id=drawer-menu.user');
const menuCustomerManagement = await page.isVisible(
'id=drawer-menu.customer',
);
const menuProductAndService = await page.isVisible(
'id=drawer-menu.product',
);
const menuDocumentManagement = await page.isVisible('id=drawer-menu.dms');
// ตรวจสอบว่าเมนูปรากฏ
expect(menuPersonnelManagement).toBe(true);
expect(menuCustomerManagement).toBe(true);
expect(menuProductAndService).toBe(true);
expect(menuDocumentManagement).toBe(true);
console.log('ตรวจสอบเมนูต่าง ๆ ของ สิทธิ์ Branch Manager สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,227 @@
import { test, expect, Page } from '@playwright/test';
import path from 'path';
import { off } from 'process';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// ถ้าทั้งหมดสำเร็จ
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Branch Managenment', 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.click('id=btn-Add');
// await page.click("(//div[@class='q-avatar relative-position'])[2]");
// const fileInput = page.locator(
// "//div[@class='image-dialog-body']//button[1]",
// );
// await fileInput.waitFor({ state: 'visible' });
// // อัปโหลดไฟล์
// await fileInput.setInputFiles(
// '/Users/linping/Desktop/Chamomind&FrappeT/JWS_TestScript/tests/Datafile/Pic1.jpg',
// ); // เปลี่ยน path ให้ตรง
// await page.setInputFiles(
// "//div[@class='image-dialog-body']//button[1]",
// '/Users/linping/Desktop/Chamomind&FrappeT/JWS_TestScript/tests/Datafile/Pic1.jpg',
// );
// // UploadFile
// ส่วนข้อมูลพื้นฐาน
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.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(.,'บริษัท คาโมมายด์ จำกัดCMM00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท คาโมมายด์ จำกัดCMM00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('Create Branch Managenment Second', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
// ส่วนข้อมูลพื้นฐาน
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'CMO');
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]", 'COMO');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill("(//input[@id='input-email'])[2]", 'como@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022010100');
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]", 'como20');
// ส่วนที่อยู่
await page.fill("(//input[@id='default-input-address-no'])[2]", '40/04');
await page.fill("(//input[@id='default-input-moo'])[3]", '2');
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]", '40/04');
await page.fill("(//input[@aria-label='Moo'])[2]", '1');
// ส่วนธนาคาร
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_4');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2022822624262');
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(.,'บริษัท โคโม่ จำกัดCMO00000')]",
);
await newOfficeLocator.waitFor({ state: 'visible' });
// ดึงข้อความจาก <td> ที่ตรงกับ XPath
const newOfficeName = await newOfficeLocator.textContent();
// ตรวจสอบว่าเนื้อหาที่บันทึกถูกต้อง
if (newOfficeName !== null) {
const trimmedName = newOfficeName.trim();
expect(trimmedName).toBe('บริษัท โคโม่ จำกัดCMO00000');
console.log('การตรวจสอบสำเร็จ: ข้อมูลถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึกใน <td>');
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,206 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import exp from 'constants';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Branch Management - ไม่มีการกรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
await page.click('id=hq-add-btn');
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'Please select Province.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'Please select District.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'Please select Sub-district.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[10]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Branch Managenment - กรณีที่กรอกชื่อย่อที่ไม่ใช่ภาษาอังกฤษ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'ภาษาไทย');
const invalidDataabbreviationError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[contains(@class,'q-field__bottom row')])[1]",
);
await expect(invalidDataabbreviationError).toHaveText(
'Invalid value. Only _ letters and number are allowed',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่ไม่ใช่ภาษาอังกฤษถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Branch Management - กรอกเลขนิติบุคคลในกรณีที่กรอกไม่ครบจำนวน 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
const taxNoError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(taxNoError).toHaveText(
'Invalid value. Please enter 13 character',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Branch Management - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-email'])[2]", '123');
const emailError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('Invalid value.', {
timeout: 2000,
});
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,210 @@
import { test, expect, Page, errors } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import exp from 'constants';
import { errorMonitor } from 'stream';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// ถ้าขั้นตอนสำเร็จ
isLoginSuccessful = true;
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Branch Management - ไม่มีการกรอกข้อมูล', 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('Create Branch Managenment - กรณีที่กรอกชื่อย่อที่ไม่ใช่ภาษาอังกฤษ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'ภาษาไทย');
const invalidDataabbreviationError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[contains(@class,'q-field__bottom row')])[1]",
);
await expect(invalidDataabbreviationError).toHaveText(
'ข้อมูลไม่ถูกต้อง โปรดใช้เฉพาะ _ ตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่ไม่ใช่ภาษาอังกฤษถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Branch Management - กรอกเลขนิติบุคคลในกรณีที่กรอกไม่ครบจำนวน 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
const taxNoError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Branch Management - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-email'])[2]", '123');
const emailError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง', {
timeout: 2000,
});
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,133 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
}
test('Login', async () => {
await login(page);
});
test('Create Sub Branch Managenment', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
for (let i = 0; i < 5; i++) {
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[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');
}
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const subBranchErrors = ['สีลม1', 'สีลม2', 'สีลม3', 'สีลม4', 'สีลม5'];
for (const branch of subBranchErrors) {
const subBranchErrors = page.locator(
`//div[normalize-space(text())='${branch}']`,
);
await subBranchErrors.waitFor({ state: 'visible' });
const newOfficeName = await subBranchErrors.textContent();
const trimmedName = newOfficeName?.trim();
expect(trimmedName).toBe(branch);
}
console.log('การตรวจสอบสำเร็จ : ข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,207 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { fstat } from 'fs';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
//ถ้าขั้นตอนสำเร็จ
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
}
test('Login', async () => {
await login(page);
});
test('Create Sub-Branch Managenment - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
await page.click('id=create-sub-branch-btn-COMO');
await page.click("(//button[@type='submit'])[1]");
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'Please select Province.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'Please select District.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'Please select District.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('การตรวจสอบ Validation ถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-COMO');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'Invalid value. Please enter 13 character',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-COMO');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('Invalid value.');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - กรอกชื่อสาขาในกรณีที่ไม่ใช่ภาษาอังกฤษ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-COMO');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-name-en'])[2]", 'ทดสอบ');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('Only letters are allowed');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,194 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Sub-Branch Managenment - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[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(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Sub-Branch Managenment - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - กรอกชื่อสาขาในกรณีที่ไม่ใช่ภาษาอังกฤษ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-name-en'])[2]", 'ทดสอบ');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,139 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Service Point Managenment', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
for (let i = 0; i < 5; i++) {
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
// ส่วนข้อมูลพื้นฐาน
await page.fill(
"(//input[@id='input-tax-no'])[2]",
`202282628264${i + 1}`,
);
await page.fill("(//input[@id='input-name'])[2]", `บางรัก${i + 1}`);
await page.fill("(//input[@id='input-name-en'])[2]", `Bangrak${i + 1}`);
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
// ส่วนติดต่อ
await page.fill(
"(//input[@id='input-email'])[2]",
`cmm${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]", `082262286${i + 1}`);
await page.fill("(//input[@id='input-line-id'])[2]", 'cmmsupport');
await page.fill(
"(//input[@id='default-input-address-no'])[2]",
`40/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]",
`40/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]",
`282264220${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');
}
// ตรวจสอบความถูกต้องหลังจากทำการบันทึกสร้างสำนักงานใหญ่
const subBranchErrors = [
'บางรัก1',
'บางรัก2',
'บางรัก3',
'บางรัก4',
'บางรัก5',
];
for (const branch of subBranchErrors) {
const subBranchErrors = page.locator(
`//div[normalize-space(text())='${branch}']`,
);
await subBranchErrors.waitFor({ state: 'visible' });
const newOfficeName = await subBranchErrors.textContent();
const trimmedName = newOfficeName?.trim();
expect(trimmedName).toBe(branch);
}
console.log('การตรวจสอบสำเร็จ : ข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,176 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
import { error } from 'console';
import exp from 'constants';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Service Point - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
await page.click('id=create-sub-branch-btn-CHAMOMIND');
await page.click("(//button[@type='submit'])[2]");
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'Please select Province.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'Please select District.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'Please select Sub-district.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('การตรวจสอบ Validation ถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Service Point - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-CHAMOMIND');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'Invalid value. Please enter 13 character',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Service Point - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-CHAMOMIND');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('Invalid value.');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,167 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Service Point - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
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);
}
console.log('การตรวจสอบ Validation ถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Service Point - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Service Point - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,427 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { sign } from 'crypto';
import { watchFile } from 'fs';
import { waitForDebugger } from 'inspector';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับที่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_0');
const column1Cells = page.locator(
"//th[normalize-space(text())='ลำดับที่']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 1 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_0'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 1 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 2
await page.click('id=select-field_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_1');
const column1Cells = page.locator(
"//th[normalize-space(text())='สำนักงาน']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 2 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 2 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 2
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_1'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 2 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 2 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลทะเบียนนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 3
await page.click('id=select-field_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_2');
const column1Cells = page.locator(
"//th[normalize-space(text())='ทะเบียนนิติบุคคล']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 3 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 3
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_2'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 3 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลเบอร์โทรสำนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 4
await page.click('id=select-field_3');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_3');
const column1Cells = page.locator(
"//th[normalize-space(text())='เบอร์โทรสำนักงาน']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 4 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 4
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_3'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 4 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 5
await page.click('id=select-field_4');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_4');
const column1Cells = page.locator("//th[normalize-space(text())='ติดต่อ']");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 5 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 5
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_4'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 5 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลที่อยู่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 6
await page.click('id=select-field_5');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_5');
const column1Cells = page.locator(
"//th[normalize-space(text())='ที่อยู่']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 6 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 6 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 6
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_5'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 6 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 6 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,235 @@
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
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-kebab-action-บริษัท โคโม่ จำกัด');
await page.click('id=btn-kebab-view-detail-บริษัท โคโม่ จำกัด');
const detailTitle = page.locator(
"//span[text()='บริษัท โคโม่ จำกัด ']/following-sibling::span",
);
await expect(detailTitle).toHaveText('CMO00000'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('ทดสอบการดูรายละเอียดสาขา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
await page.click('id=btn-kebab-action-สีลม1');
await page.click('id=btn-kebab-view-detail-สีลม1');
const detailTitle = page.locator("//span[text()='สีลม1 ']");
await detailTitle.waitFor({ state: 'visible' });
await expect(detailTitle).toHaveText('สีลม1'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('ทดสอบการดูรายละเอียดจุดรับบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
await page.click('id=btn-kebab-action-บางรัก1');
await page.click('id=btn-kebab-view-detail-บางรัก1');
const detailTitle = page.locator("//span[text()='บางรัก1 ']");
await detailTitle.waitFor({ state: 'visible' });
await expect(detailTitle).toHaveText('บางรัก1'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('ทดสอบการดูรายละเอียดสำนักงานใหญ่ในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
await page.reload();
await page.click("//button[@aria-pressed='false']");
await page.waitForTimeout(2000);
try {
const nameBrnach = page.locator(
"//b[normalize-space(text())='บริษัท คาโมมายด์ จำกัด']",
);
const legalPerson = page.locator(
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
);
const cellPhone = page.locator(
"(//div[text()='เบอร์โทรสำนักงาน']/following-sibling::div)[1]",
);
const contactName = page.locator("//div[normalize-space(text())='คุณต่อ']");
const address = page.locator(
"//div[normalize-space(text())='20/02 หมู่ 1, พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
);
await expect(nameBrnach).toHaveText('บริษัท คาโมมายด์ จำกัด');
await expect(legalPerson).toHaveText('1260846220284');
await expect(cellPhone).toHaveText('0866224228');
await expect(contactName).toHaveText('คุณต่อ');
await expect(address).toHaveText(
'20/02 หมู่ 1, พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
);
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
});
test('ทดสอบการดูรายละเอียดสาขาในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
await page.waitForTimeout(2000);
const legalPerson = page.locator(
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
);
const contactName = page.locator(
"(//div[text()='ติดต่อ']/following-sibling::div)[1]",
);
const address = page.locator(
"//div[normalize-space(text())='40/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
);
await expect(legalPerson).toHaveText('2022826282641');
await expect(contactName).toHaveText('คุณอุล');
await expect(address).toHaveText(
'40/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
);
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
});
test('ทดสอบการดูรายละเอียดจุดรับบริการในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
await page.waitForTimeout(2000);
const legalPerson = page.locator(
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
);
const contactName = page.locator(
"(//div[text()='ติดต่อ']/following-sibling::div)[1]",
);
const address = page.locator(
"//div[normalize-space(text())='20/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
);
await expect(legalPerson).toHaveText('1260846220281');
await expect(contactName).toHaveText('คุณอาท');
await expect(address).toHaveText(
'20/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
);
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -0,0 +1,160 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
import { sign } from 'crypto';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Edit Headquter Branch', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แก้ไขสำนักงานใหญ่
await page.click('id=btn-kebab-action-บริษัท โคโม่ จำกัด');
await page.click('id=btn-kebab-edit-บริษัท โคโม่ จำกัด');
await page.fill('id=input-name', 'บริษัท โคโมโดะ จำกัด');
await page.fill('id=input-name-en', 'COMODO');
await page.click('id=btn-info-basic-save');
//ตรวจสอบรายละเอียดการแก้ไข
await page.click('id=btn-kebab-action-บริษัท โคโมโดะ จำกัด');
await page.click('id=btn-kebab-view-detail-บริษัท โคโมโดะ จำกัด');
//ตรวจสอบว่าได้ทำการแก้ไขถูกต้องหรือไม่
const detailEditName = await page.inputValue(
"//input[@value='บริษัท โคโมโดะ จำกัด']",
);
const detailEditNameEn = await page.inputValue(
"//input[@aria-label='ชื่อสำนักงานใหญ่ (EN)']",
);
await expect(detailEditName).toBe('บริษัท โคโมโดะ จำกัด');
await expect(detailEditNameEn).toBe('COMODO');
console.log('ตรวจสอบการแก้ไขข้อมูลสำนักงานใหญ่ถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('Edit Sub Branch', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แก้ไขสำนักงานใหญ่
await page.click("//div[@id='tree-enter-บริษัท โคโมโดะ จำกัด']/div[1]");
await page.waitForSelector('id=btn-kebab-action-สีลม1', {
state: 'visible',
});
await page.click('id=btn-kebab-action-สีลม1');
await page.waitForTimeout(1000);
await page.click('id=btn-kebab-edit-สีลม1');
await page.fill('id=input-name', 'สินสาทร');
await page.fill('id=input-name-en', 'Sinsathorn');
await page.click('id=btn-info-basic-save');
//ตรวจสอบรายละเอียดการแก้ไข
await page.click('id=btn-kebab-action-สินสาทร');
await page.click('id=btn-kebab-view-detail-สินสาทร');
//ตรวจสอบว่าได้ทำการแก้ไขถูกต้องหรือไม่
const detailEditName = await page.inputValue("//input[@value='สินสาทร']");
const detailEditNameEn = await page.inputValue(
"//input[@value='Sinsathorn']",
);
await expect(detailEditName).toBe('สินสาทร');
await expect(detailEditNameEn).toBe('Sinsathorn');
console.log('ตรวจสอบการแก้ไขข้อมูลสาขาถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('Edit Visual Branch', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แก้ไขสำนักงานใหญ่
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
await page.click('id=btn-kebab-action-บางรัก1');
await page.click('id=btn-kebab-edit-บางรัก1');
await page.fill('id=input-name', 'บางจาก');
await page.fill('id=input-name-en', 'Bangjak');
await page.click('id=btn-info-basic-save');
//ตรวจสอบรายละเอียดการแก้ไข
await page.click('id=btn-kebab-action-บางจาก');
await page.click('id=btn-kebab-view-detail-บางจาก');
//ตรวจสอบว่าได้ทำการแก้ไขถูกต้องหรือไม่
const detailEditName = await page.inputValue("//input[@value='บางจาก']");
const detailEditNameEn = await page.inputValue("//input[@value='Bangjak']");
await expect(detailEditName).toBe('บางจาก');
await expect(detailEditNameEn).toBe('Bangjak');
console.log('ตรวจสอบการแก้ไขข้อมูลสาขาเสมือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});

View file

@ -0,0 +1,249 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงผลสถานะการใช้งาน เปิด/ปิด สำนักงานใหญ่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=field-select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=field-select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=field-select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
// test('ตรวจสอบการแสดงผลสถานะการใช้งาน เปิด/ปิด สาขา', async () => {
// try {
// // คลิกเข้าสู่สาขา
// await page.click("//div[@id='tree-enter-บริษัท โคโมโดะ จำกัด']/div[1]");
// // แสดงสถานะที่ใช้งาน
// // คลิกเพื่อเปิด dropdown
// await page.click('id=field-select-status');
// await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// // คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
// await page.click('id=field-select-status_1');
// await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// // ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
// const statusActive = await page.isVisible('id=field-select-status_1');
// console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
// expect(statusActive).toBe(false);
// console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// // แสดงสถานะที่ไม่ใช้งาน
// // คลิกเพื่อเปิด dropdown
// await page.keyboard.press('Escape');
// await page.click('id=field-select-status');
// await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// // คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
// await page.click('id=field-select-status_2');
// await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// // ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
// const statusInActive = await page.isVisible('id=field-select-status_1');
// console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
// expect(statusActive).toBe(false);
// console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// // แสดงสถานะทั้งหมด
// // คลิกเพื่อเปิด dropdown
// await page.keyboard.press('Escape');
// await page.click('id=field-select-status');
// await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// // คลิกเพื่อแสดงสถานะทั้งหมด
// await page.click('id=field-select-status_0');
// await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// // ตรวจสอบว่าแสดงทุกสถานะหรือไม่
// const statusAll = await page.isVisible('id=field-select-status_1');
// console.log('สถานะทั้งหมด', statusAll); // เช็ค
// expect(statusActive).toBe(false);
// console.log('ตรวจสอบสถานะทั้งหมด');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
// throw error;
// }
// await page.waitForTimeout(2000);
// });
// test('ตรวจสอบการแสดงผลสถานะการใช้งาน เปิด/ปิด จุดรับบริการ', async () => {
// try {
// // คลิกเข้าสู่สาขาเสมือน
// await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
// // แสดงสถานะที่ใช้งาน
// // คลิกเพื่อเปิด dropdown
// await page.click('id=field-select-status');
// await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// // คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
// await page.click('id=field-select-status_1');
// await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// // ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
// const statusActive = await page.isVisible('id=field-select-status_1');
// console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
// expect(statusActive).toBe(false);
// console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// // แสดงสถานะที่ไม่ใช้งาน
// // คลิกเพื่อเปิด dropdown
// await page.keyboard.press('Escape');
// await page.click('id=field-select-status');
// await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// // คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
// await page.click('id=field-select-status_2');
// await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// // ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
// const statusInActive = await page.isVisible('id=field-select-status_1');
// console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
// expect(statusActive).toBe(false);
// console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// // แสดงสถานะทั้งหมด
// // คลิกเพื่อเปิด dropdown
// await page.keyboard.press('Escape');
// await page.click('id=field-select-status');
// await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// // คลิกเพื่อแสดงสถานะทั้งหมด
// await page.click('id=field-select-status_0');
// await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// // ตรวจสอบว่าแสดงทุกสถานะหรือไม่
// const statusAll = await page.isVisible('id=field-select-status_1');
// console.log('สถานะทั้งหมด', statusAll); // เช็ค
// expect(statusActive).toBe(false);
// console.log('ตรวจสอบสถานะทั้งหมด');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
// throw error;
// }
// await page.waitForTimeout(2000);
// });

View file

@ -0,0 +1,106 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, 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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Search Data Branch Management', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// กำหนดคำที่จะค้นหา
const searchDatas = [
'โคโมโดะ',
'คาโมมายด์',
'CM',
'CMO',
'00000',
'บางจาก',
'บางรัก',
'สีลม1',
];
for (const searchData of searchDatas) {
// พิมพ์คำที่ต้องการค้นหา
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
await page.waitForTimeout(2000);
// ดึงผลลัพฑ์การค้นหาทั้งหมด
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
const resultCount = await searchResults.count();
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
if (resultCount === 0) {
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
continue; // ข้ามคำค้นหาคำถัดไป
}
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
const searchResultTexts = await searchResults.allTextContents();
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
const allResultContainSearchData = searchResultTexts.every((result) =>
result.includes(searchData),
);
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
if (!allResultContainSearchData) {
console.error(
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
);
continue; // ข้ามไปคำค้นหาถัดไป
}
expect(allResultContainSearchData).toBe(true);
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,127 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, 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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
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-kebab-action-บริษัท คาโมมายด์ จำกัด');
await page.click('id=btn-kebab-status-บริษัท คาโมมายด์ จำกัด', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//td[contains(.,'บริษัท คาโมมายด์ จำกัดCMM00000')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดการใช้งานสำนักงานใหญ่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-บริษัท คาโมมายด์ จำกัด');
await page.click('id=btn-kebab-status-บริษัท คาโมมายด์ จำกัด', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//td[contains(.,'บริษัท คาโมมายด์ จำกัดCMM00000')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,247 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import exp from 'constants';
import { it } from 'node:test';
import { prependOnceListener } from 'process';
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) {
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');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการลบจัดการสาขา', async () => {
// จำลองการสร้างสำนักงานใหญ่
// 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]", '1260846220284');
// await page.fill("(//input[@id='input-name'])[2]", 'บริษัท จำลอง จำกัด');
// await page.fill("(//input[@id='input-name-en'])[2]", 'JOMLONG');
// await page.fill("(//input[@id='input-license-number'])[2]", '2938227328292');
// await page.fill("(//input[@id='input-email'])[2]", 'JOM@support.com');
// await page.fill("(//input[@id='input-telephone-no'])[2]", '022010100');
// 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]", 'como20');
// await page.fill("(//input[@id='default-input-address-no'])[2]", '40/04');
// 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]", '40/04');
// await page.click("(//input[@id='select-bankbook'])[3]");
// await page.click('id=select-bankbook_4');
// await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2022822624262');
// 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');
if (!isLoginSuccessful) {
await login(page);
}
// จำลองการสร้างสาขา
try {
await page.click('id=create-sub-branch-btn-บริษัท จำลอง จำกัด');
await page.click("(//button[@type='submit'])[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]", 'SAKAJOMLONG');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
await page.fill("(//input[@id='input-email'])[2]", 'test@support.com');
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]", '0822262228');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
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/02');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2282020021');
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');
// จำลองการสร้างสาขาเสมือน
await page.click('id=create-sub-branch-btn-บริษัท จำลอง จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '2022826282642');
await page.fill("(//input[@id='input-name'])[2]", 'สาขาเสมือน');
await page.fill("(//input[@id='input-name-en'])[2]", 'VISUALBRANCH');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
await page.fill("(//input[@id='input-email'])[2]", 'visual@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]", '0822622862');
await page.fill("(//input[@id='input-line-id'])[2]", 'cmmsupport');
await page.fill("(//input[@id='default-input-address-no'])[2]", '40/04');
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]", '40/04');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_2');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2822642201');
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');
await page.waitForTimeout(1000);
// ลบสาขาและตรวจสอบการลบสาขา
await page.click('id=btn-kebab-action-สาขาจำลอง');
await page.click('id=btn-kebab-delete-สาขาจำลอง');
// ยืนยันการลบ
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(1000);
// ตรวจสอบการลบสาขา
const itemLocator = page.locator(
"//tr[contains(.,'1 สาขาจำลองTES0000112608462202810822262228คุณอาท20/02')]",
);
// ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
await expect(itemLocator).toBeHidden();
console.log('ตรวจสอบข้อมูลการลบสาขาสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการลบสาขา', error);
throw error;
}
// ลบสาขาเสมือนและตรวจสอบการลบสาขาเสมือน
try {
await page.click('id=btn-kebab-action-สาขาเสมือน');
await page.click('id=btn-kebab-delete-สาขาเสมือน');
// ยืนยันการลบ
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(1000);
// ตรวจสอบการลบสาขาเสมือน
const itemLocator = page.locator(
"//tr[contains(.,'2 สาขาเสมือนTES0000220228262826420822622862คุณอุล40/04')]",
);
// ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
await expect(itemLocator).toBeHidden();
console.log('ตรวจสอบข้อมูลการลบสาขาเสมือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการลบสาขาเสมือน', error);
isLoginSuccessful = false;
throw error;
}
// // ลบสำนักงานใหญ่และตรวจสอบการลบสำนักงานใหญ่
// await page.click("//div[@id='tree-enter-บริษัท จำลอง จำกัด']/div[1]");
// try {
// await page.click('id=btn-kebab-action-บริษัท จำลอง จำกัด');
// await page.click('id=btn-kebab-delete-บริษัท จำลอง จำกัด');
// // ยืนยันการลบ
// await page.click('id=btn-ok-dialog');
// await page.waitForTimeout(1000);
// // ตรวจสอบการลบสำนักงานใหญ่
// const itemLocator = page.locator(
// "//tr[contains(.,'9 บริษัท จำลอง จำกัดTES0000012608462202840866224228คุณอาท40/04')]",
// );
// // ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
// await expect(itemLocator).toBeHidden();
// console.log('ตรวจสอบข้อมูลการลบสำนักงานใหญ่สำเร็จ');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการลบสำนักงานใหญ่', error);
// throw error;
// }
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,961 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
import { prependOnceListener } from 'process';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Personnel พนักงาน ชาย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-Add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'employeem');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_2');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธรรมรงด์');
await page.fill('id=form-dialog-personnel-input-last-name', 'ดำรงธรรม');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thamrong');
await page.fill(
'id=form-dialog-personnel-input-last-name-en',
'Dumrongtum',
);
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill(
'id=form-dialog-personnel-input-email',
'employeem@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2000']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2000-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2010']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2010-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธรรมรงด์ ดำรงธรรม']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธรรมรงด์ ดำรงธรรม');
console.log(displayName);
console.log('ตรวจสอบการสร้างพนักงานชายถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('Create Personnel พนักงาน หญิง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'employeew');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'อารยา');
await page.fill('id=form-dialog-personnel-input-last-name', 'มาลา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Araya');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Mala');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill(
'id=form-dialog-personnel-input-email',
'employeew@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2001']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2001-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2011']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2011-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='อารยา มาลา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('อารยา มาลา');
console.log('ตรวจสอบการสร้างพนักงานหญิงถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel พนักงานส่งเอกสาร หญิง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'courierw');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'มาตา');
await page.fill('id=form-dialog-personnel-input-last-name', 'ลดา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Mata');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Lada');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill(
'id=form-dialog-personnel-input-email',
'courierw@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2002']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2002-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2012']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2012-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='มาตา ลดา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('มาตา ลดา');
console.log('ตรวจสอบการสร้างพนักงานส่งเอกสารหญิงถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel พนักงานส่งเอกสาร ชาย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'courierm');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธันวา');
await page.fill('id=form-dialog-personnel-input-last-name', 'มานา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thanwa');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Mana');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill(
'id=form-dialog-personnel-input-email',
'courierm@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2003']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2003-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2013']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2013-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธันวา มานา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธันวา มานา');
console.log('ตรวจสอบการสร้างพนักงานส่งเอกสารชายถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel ตัวแทน ชาย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[4]");
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'delegatem');
await page.click('id=select-user-role');
await page.click('id=select-user-role_8');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'อาคม');
await page.fill('id=form-dialog-personnel-input-last-name', 'พลัง');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Akom');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Palang');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill(
'id=form-dialog-personnel-input-email',
'delegatem@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2004']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2004-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2014']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2014-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-discount-condition', 'ทดสอบข้อมูลการทำงาน');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='อาคม พลัง']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('อาคม พลัง');
console.log('ตรวจสอบการสร้างตัวแทนชายถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel ตัวแทน หญิง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'delegatew');
await page.click('id=select-user-role');
await page.click('id=select-user-role_10');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'สโรชา');
await page.fill('id=form-dialog-personnel-input-last-name', 'มีนา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Sarocha');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Mena');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill(
'id=form-dialog-personnel-input-email',
'delegatew@mail.com',
);
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2005']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2005-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2015']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2015-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-discount-condition', 'ทดสอบข้อมูลการทำงาน');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='สโรชา มีนา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('สโรชา มีนา');
console.log('ตรวจสอบการสร้างตัวแทนหญิงถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel เอเจนซี่ หญิง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[5]");
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'agencyw');
await page.click('id=select-user-role');
await page.click('id=select-user-role_2');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธิดา');
await page.fill('id=form-dialog-personnel-input-last-name', 'งามตา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thida');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Yamta');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'agencyw@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2006']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2006-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2016']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2016-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.click('id=input-source-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=input-import-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=select-trainig-place');
await page.click("//span[text()='สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก']");
await page.fill('id=input-checkpoint', 'แม่สอด');
await page.fill('id=input-checkpoint-en', 'Maesod');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธิดา งามตา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธิดา งามตา');
console.log('ตรวจสอบการสร้างเอเจนซี่หญิงถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel เอเจนซี่ ชาย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'agencym');
await page.click('id=select-user-role');
await page.click('id=select-user-role_8');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click(
"//label[@for='form-dialog-personnel-select-prefix-name']",
);
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'อันดา');
await page.fill('id=form-dialog-personnel-input-last-name', 'ธรรมา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Aunda');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Thamma');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'agencym@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2007']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2007-01-02']/div[1]");
// วันออกบัตร
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2017']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ม.ค.']");
await page.click("//div[@id='2017-01-02']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector(
'id=drawer-info-personnel-select-sub-district_1',
{
state: 'visible',
},
);
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.click('id=input-source-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=input-import-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=select-trainig-place');
await page.click("//span[text()='สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก']");
await page.fill('id=input-checkpoint', 'แม่สอด');
await page.fill('id=input-checkpoint-en', 'Maesod');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='อันดา ธรรมา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('อันดา ธรรมา');
console.log('ตรวจสอบการสร้างเอเจนซี่ชายถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,220 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
import { getSystemErrorMap } from 'util';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Personnel - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
await page.click('id=btn-add');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
const expectedErrors = [
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select User Type.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select User Role.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select Birth Date.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select Citizen Issue.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select Province.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select District.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'Please select Sub-district.',
},
{
locator: "(//div[@role='alert'])[1]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel - ในกรณีที่กรอกชื่อผู้ใช้งานที่ไม่ตรงกับตัวอักษรที่กำหนด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=input-username', 'ทดสอบ');
const usernameError = page.locator("(//div[@role='alert'])[1]");
await expect(usernameError).toHaveText(
'Only _ letters and number are allowed',
);
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel - ในกรณีที่กรอกชื่อและนามสกุลภาษาอังกฤษไม่ตรงตามรูปแบบ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=form-dialog-personnel-input-first-name-en', 'ทดสอบ');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'ทดสอบ');
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
const lastNameEnError = page.locator("(//div[@role='alert'])[2]");
await expect(firstNameEnError).toHaveText('Only letters are allowed');
await expect(lastNameEnError).toHaveText('Only letters are allowed');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel - ในกรณีที่กรอกอีเมลไม่ตรงรูปแบบ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=form-dialog-personnel-input-email', 'ทดสอบ');
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
await expect(firstNameEnError).toHaveText('Invalid value.');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,217 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Personnel - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
const expectedErrors = [
{
locator: "(//div[@role='alert'])[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[2]",
message: 'โปรดเลือกประเภทผู้ใช้งาน',
},
{
locator: "(//div[@role='alert'])[3]",
message: 'โปรดเลือกสิทธิ์ผู้ใช้งาน',
},
{
locator: "(//div[@role='alert'])[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[6]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[7]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[8]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[9]",
message: 'โปรดเลือกวันเดือนปีเกิด',
},
{
locator: "(//div[@role='alert'])[10]",
message: 'โปรดเลือกวันที่ออกบัตร',
},
{
locator: "(//div[@role='alert'])[11]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@role='alert'])[12]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@role='alert'])[13]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@role='alert'])[14]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@role='alert'])[15]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel - ในกรณีที่กรอกชื่อผู้ใช้งานที่ไม่ตรงกับตัวอักษรที่กำหนด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=input-username', 'ทดสอบ');
const usernameError = page.locator("(//div[@role='alert'])[1]");
await expect(usernameError).toHaveText(
'โปรดใช้เฉพาะ _ ตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
);
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel - ในกรณีที่กรอกชื่อและนามสกุลภาษาอังกฤษไม่ตรงตามรูปแบบ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=form-dialog-personnel-input-first-name-en', 'ทดสอบ');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'ทดสอบ');
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
const lastNameEnError = page.locator("(//div[@role='alert'])[2]");
await expect(firstNameEnError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
await expect(lastNameEnError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Personnel - ในกรณีที่กรอกอีเมลไม่ตรงรูปแบบ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=form-dialog-personnel-input-email', 'ทดสอบ');
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
await expect(firstNameEnError).toHaveText('ข้อมูลไม่ถูกต้อง');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,248 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
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("(//div[@role='tab'])[2]");
try {
await page.waitForSelector('id=btn-kebab-action-employeem', {
state: 'visible',
});
await page.click('id=btn-kebab-action-employeem');
await page.click('id=btn-kebab-view-detail-employeem');
const detailTitle = page.locator("//span[text()='ธรรมรงด์ ดำรงธรรม']");
await expect(detailTitle).toHaveText('ธรรมรงด์ ดำรงธรรม');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('ดูรายละเอียดพนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-kebab-action-courierw');
await page.click('id=btn-kebab-view-detail-courierw');
const detailTitle = page.locator("//span[text()='มาตา ลดา']");
await expect(detailTitle).toHaveText('มาตา ลดา');
console.log('ตรวจสอบรายละเอียดพนักงานส่งเอกสารถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('ดูรายละเอียดตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[4]");
await page.click('id=btn-kebab-action-delegatem');
await page.click('id=btn-kebab-view-detail-delegatem');
const detailTitle = page.locator("//span[text()='อาคม พลัง']");
await expect(detailTitle).toHaveText('อาคม พลัง');
console.log('ตรวจสอบรายละเอียดตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('ดูรายละเอียดเอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[5]");
await page.click('id=btn-kebab-action-agencyw');
await page.waitForSelector('id=btn-kebab-view-detail-agencyw', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-agencyw');
const detailTitle = await page.locator("//span[text()='ธิดา งามตา']");
await expect(detailTitle).toHaveText('ธิดา งามตา');
console.log('ตรวจสอบรายละเอียดเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
// ---------------------------------- รูปแบบการ์ด ----------------------------//
test('ดูรายละเอียดพนักงานในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click("//button[@aria-pressed='false']");
await page.click("(//div[@role='tab'])[2]");
const namePersonal = page.locator(
"//div[normalize-space(text())='ธรรมรงด์ ดำรงธรรม']",
);
await expect(namePersonal).toHaveText('ธรรมรงด์ ดำรงธรรม');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ดูรายละเอียดพนักงานส่งเอกสารในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[3]");
const namePersonal = page.locator(
"//div[normalize-space(text())='มาตา ลดา']",
);
await expect(namePersonal).toHaveText('มาตา ลดา');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ดูรายละเอียดตัวแทนในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[4]");
const namePersonal = page.locator(
"//div[normalize-space(text())='อาคม พลัง']",
);
await expect(namePersonal).toHaveText('อาคม พลัง');
console.log('ตรวจสอบรายละเอียดตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ดูรายละเอียดเอเจนซี่ในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[5]");
const namePersonal = page.locator(
"//div[normalize-space(text())='ธิดา งามตา']",
);
await expect(namePersonal).toHaveText('ธิดา งามตา');
console.log('ตรวจสอบรายละเอียดเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,283 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
import { log } from 'console';
import { writeFileSync } from 'fs';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Edit Personnel - พนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[2]");
await page.waitForSelector('id=btn-kebab-action-employeem', {
state: 'visible',
});
await page.click('id=btn-kebab-action-employeem');
// ตรวจสอบการคลิกว่าได้มีการคลิกหรือการแสดงจริงหรือไม่
// const isElementVisible = await page.isVisible(
// 'id=btn-kebab-edit-employeem',
// );
// console.log('Element visibility:', isElementVisible);
await page.click('id=btn-kebab-edit-employeem');
// แก้ไขข้อมูล
await page.fill('id=drawer-info-personnel-input-first-name', 'อานน');
await page.fill('id=drawer-info-personnel-input-last-name', 'รักมาก');
await page.fill('id=drawer-info-personnel-input-first-name-en', 'Arnon');
await page.fill('id=drawer-info-personnel-input-last-name-en', 'Rakmak');
await page.click('id=btn-info-basic-save'); // คลิกปุ่มบันทึก
// ตรวจสอบหลังแก้ไขเสร็จ
await page.waitForSelector('id=btn-kebab-action-employeem', {
state: 'visible',
});
await page.click('id=btn-kebab-action-employeem');
await page.waitForSelector('id=btn-kebab-view-detail-employeem', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-employeem');
// ตรวจสอบข้อมูลว่าทำการแก้ไขถูกหรือไม่
const detailEditFistName = await page.inputValue("//input[@value='อานน']");
const detailEditLastName = await page.inputValue(
"//input[@value='รักมาก']",
);
const detailEditFistNameEn = await page.inputValue(
"//input[@value='Arnon']",
);
const detailEditLastNameEn = await page.inputValue(
"//input[@value='Rakmak']",
);
await expect(detailEditFistName).toBe('อานน');
await expect(detailEditLastName).toBe('รักมาก');
await expect(detailEditFistNameEn).toBe('Arnon');
await expect(detailEditLastNameEn).toBe('Rakmak');
console.log('ตรวจสอบการแก้ไขข้อมูลพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('Edit Personnel - พนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-kebab-action-courierw');
await page.waitForSelector('id=btn-kebab-edit-courierw');
await page.click('id=btn-kebab-edit-courierw');
// แก้ไขข้อมูล
await page.fill('id=drawer-info-personnel-input-first-name', 'ลาดา');
await page.fill('id=drawer-info-personnel-input-last-name', 'มดา');
await page.fill('id=drawer-info-personnel-input-first-name-en', 'Lada');
await page.fill('id=drawer-info-personnel-input-last-name-en', 'Mada');
await page.click('id=btn-info-basic-save'); // คลิกปุ่มบันทึก
// ตรวจสอบหลังแก้ไขเสร็จ
await page.waitForSelector('id=btn-kebab-action-courierw', {
state: 'visible',
});
await page.click('id=btn-kebab-action-courierw');
await page.waitForSelector('id=btn-kebab-view-detail-courierw', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-courierw');
// ตรวจสอบข้อมูลว่าทำการแก้ไขถูกหรือไม่
const detailEditFistName = await page.inputValue("//input[@value='ลาดา']");
const detailEditLastName = await page.inputValue("//input[@value='มดา']");
const detailEditFistNameEn = await page.inputValue(
"//input[@value='Lada']",
);
const detailEditLastNameEn = await page.inputValue(
"//input[@value='Mada']",
);
await expect(detailEditFistName).toBe('ลาดา');
await expect(detailEditLastName).toBe('มดา');
await expect(detailEditFistNameEn).toBe('Lada');
await expect(detailEditLastNameEn).toBe('Mada');
console.log('ตรวจสอบการแก้ไขข้อมูลพนักงานส่งเอกสารถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('Edit Personnel - ตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[4]");
await page.waitForTimeout(1000);
await page.click('id=btn-kebab-action-delegatem');
await page.waitForSelector('id=btn-kebab-edit-delegatem');
await page.click('id=btn-kebab-edit-delegatem');
// แก้ไขข้อมูล
await page.fill('id=drawer-info-personnel-input-first-name', 'ธนกร');
await page.fill('id=drawer-info-personnel-input-last-name', 'ลอยฟ้า');
await page.fill(
'id=drawer-info-personnel-input-first-name-en',
'Thanakorn',
);
await page.fill('id=drawer-info-personnel-input-last-name-en', 'Loifa');
await page.click('id=btn-info-basic-save'); // คลิกปุ่มบันทึก
// ตรวจสอบหลังแก้ไขเสร็จ
await page.waitForSelector('id=btn-kebab-action-delegatem', {
state: 'visible',
});
await page.click('id=btn-kebab-action-delegatem');
await page.waitForSelector('id=btn-kebab-view-detail-delegatem', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-delegatem');
// ตรวจสอบข้อมูลว่าทำการแก้ไขถูกหรือไม่
const detailEditFistName = await page.inputValue("//input[@value='ธนกร']");
const detailEditLastName = await page.inputValue(
"//input[@value='ลอยฟ้า']",
);
const detailEditFistNameEn = await page.inputValue(
"//input[@value='Thanakorn']",
);
const detailEditLastNameEn = await page.inputValue(
"//input[@value='Loifa']",
);
await expect(detailEditFistName).toBe('ธนกร');
await expect(detailEditLastName).toBe('ลอยฟ้า');
await expect(detailEditFistNameEn).toBe('Thanakorn');
await expect(detailEditLastNameEn).toBe('Loifa');
console.log('ตรวจสอบการแก้ไขข้อมูลตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('Edit Personnel - เอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[5]");
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-kebab-action-agencyw', {
state: 'visible',
});
await page.click('id=btn-kebab-action-agencyw');
await page.waitForSelector('id=btn-kebab-edit-agencyw');
await page.click('id=btn-kebab-edit-agencyw');
// แก้ไขข้อมูล
await page.fill('id=drawer-info-personnel-input-first-name', 'นิดา');
await page.fill('id=drawer-info-personnel-input-last-name', 'อามา');
await page.fill('id=drawer-info-personnel-input-first-name-en', 'Nida');
await page.fill('id=drawer-info-personnel-input-last-name-en', 'Arma');
await page.click('id=btn-info-basic-save'); // คลิกปุ่มบันทึก
// ตรวจสอบหลังแก้ไขเสร็จ
await page.waitForSelector('id=btn-kebab-action-agencyw', {
state: 'visible',
});
await page.click('id=btn-kebab-action-agencyw');
await page.waitForSelector('id=btn-kebab-view-detail-agencyw', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-agencyw');
// ตรวจสอบข้อมูลว่าทำการแก้ไขถูกหรือไม่
const detailEditFistName = await page.inputValue("//input[@value='นิดา']");
const detailEditLastName = await page.inputValue("//input[@value='อามา']");
const detailEditFistNameEn = await page.inputValue(
"//input[@value='Nida']",
);
const detailEditLastNameEn = await page.inputValue(
"//input[@value='Arma']",
);
await expect(detailEditFistName).toBe('นิดา');
await expect(detailEditLastName).toBe('อามา');
await expect(detailEditFistNameEn).toBe('Nida');
await expect(detailEditLastNameEn).toBe('Arma');
console.log('ตรวจสอบการแก้ไขข้อมูลเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});

View file

@ -0,0 +1,124 @@
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
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-kebab-action-employeem');
await page.click('id=btn-kebab-status-employeem', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='อานน รักมาก']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะการใช้งานบุคลากร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-employeem');
await page.click('id=btn-kebab-status-employeem', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='อานน รักมาก']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,104 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { errorMonitor } from 'events';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Search Personnel', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// กำหนดคำที่จะค้นหา
const searchDatas = [
'อานน',
'0842262228',
'1000001',
'10',
'20',
'30',
'40',
];
for (const searchData of searchDatas) {
// พิมพ์คำที่ต้องการค้นหา
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
await page.waitForTimeout(2000);
// ดึงผลลัพฑ์การค้นหาทั้งหมด
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
const resultCount = await searchResults.count();
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
if (resultCount === 0) {
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
continue; // ข้ามคำค้นหาคำถัดไป
}
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
const searchResultTexts = await searchResults.allTextContents();
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
const allResultContainSearchData = searchResultTexts.every((result) =>
result.includes(searchData),
);
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
if (!allResultContainSearchData) {
console.error(
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
);
continue; // ข้ามไปคำค้นหาถัดไป
}
expect(allResultContainSearchData).toBe(true);
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,392 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
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 {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.waitForTimeout(1000);
await page.click('id=field-select-status');
//รอให้ dropdown เปิด
await page.waitForSelector('id=field-select-status_1');
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=field-select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=field-select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=field-select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด พนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงาน
await page.click("(//div[@role='tab'])[2]");
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=field-select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=field-select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=field-select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด พนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงานส่งเอกสาร
await page.click("(//div[@role='tab'])[3]");
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=field-select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=field-select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=field-select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด ตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab ตัวแทน
await page.click("(//div[@role='tab'])[4]");
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=field-select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=field-select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=field-select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด เอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab เอเจนซี่
await page.click("(//div[@role='tab'])[5]");
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=field-select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=field-select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=field-select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=field-select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,145 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import fs from 'fs';
import path from 'path';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://chamomind.ddns.net:20001/');
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');
});
test('สร้างลูกจ้างในสาขา', async () => {
const names = [
{
firstName: 'อริญา',
lastName: 'จิตรเกียรติ',
firstNameEn: 'Arinya',
lastNameEn: 'Jitkiat',
},
{
firstName: 'เกียรติศักดิ์',
lastName: 'อำนวย',
firstNameEn: 'Kiatsakd',
lastNameEn: 'Amnuy',
},
{
firstName: 'ภัทรพล',
lastName: 'รุ่งโรจน์',
firstNameEn: 'Phatthapon',
lastNameEn: 'Rungroj',
},
{
firstName: 'ศิริพร',
lastName: 'พงษ์รัตน์',
firstNameEn: 'Siriporn',
lastNameEn: 'Phongrat',
},
{
firstName: 'กรกมล',
lastName: 'กิตติสมบัติ',
firstNameEn: 'Karakamon',
lastNameEn: 'Kittisombat',
},
];
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.click(
"//td[contains(.,'บริษัท เทคโนโลยีอินโนเวต จำกัดInnovative Technology Co., Ltd.')]",
);
await page.click("//table[@class='q-table']/tbody[1]/tr[3]/td[6]/button[1]");
try {
for (const user of names) {
await page.click("(//th[@class='text-right']//button)[2]");
await page.click('id=form-employee-select-prefix-name');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill('id=form-employee-input-first-name', user.firstName);
await page.fill('id=form-employee-input-last-name', user.lastName);
await page.fill('id=form-employee-input-first-name-en', user.firstNameEn);
await page.fill('id=form-employee-input-last-name-en', user.lastNameEn);
// วันเกิด
await page.click('id=form-employee-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2000']");
await page.click("//div[@id='2000-11-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.click('id=form-employee-select-nationality_3');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
}
} catch (error) {
console.error('error');
}
});
test('สร้างลูกจ้างในสาขา 2', async () => {
const namestwo = [
{
firstName: 'สุทิน',
lastName: 'ภาณุวงศ์',
firstNameEn: 'Suthin',
lastNameEn: 'Phanuwong',
},
];
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.click(
"//td[contains(.,'บริษัท เทคโนโลยีอินโนเวต จำกัดInnovative Technology Co., Ltd.')]",
);
await page.click("//table[@class='q-table']/tbody[1]/tr[5]/td[6]/button[1]");
try {
for (const user of namestwo) {
await page.click("(//th[@class='text-right']//button)[3]");
await page.click('id=form-employee-select-prefix-name');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill('id=form-employee-input-first-name', user.firstName);
await page.fill('id=form-employee-input-last-name', user.lastName);
await page.fill('id=form-employee-input-first-name-en', user.firstNameEn);
await page.fill('id=form-employee-input-last-name-en', user.lastNameEn);
// วันเกิด
await page.click('id=form-employee-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2000']");
await page.click("//div[@id='2000-11-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.click('id=form-employee-select-nationality_3');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
}
} catch (error) {
console.error('error');
}
});

View file

@ -0,0 +1,191 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
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.waitForTimeout(2000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
// ส่วนเกี่ยวกับ
await page.fill('id=input-card-number', '1524428220420');
await page.waitForSelector('id=form-select-prefix-name');
await page.click('id=form-select-prefix-name');
await page.waitForSelector('id=form-select-prefix-name_0');
await page.click('id=form-select-prefix-name_0');
await page.fill('id=form-input-first-name', 'ยศพัฒน์');
await page.fill('id=form-input-last-name', 'ธนากานต์');
await page.fill('id=form-input-first-name-en', 'Yossapat');
await page.fill('id=form-input-last-name-en', 'Tanakarn');
await page.fill('id=form-input-telephone', '0842262228');
await page.waitForSelector('id=form-input-birth-date');
await page.click('id=form-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1999']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ต.ค.']");
await page.click("//div[@id='1999-10-02']/div[1]");
// ส่วนข้อมูลธุรกิจ
await page.waitForSelector("(//div[@aria-selected='false'])[2]");
await page.click("(//div[@aria-selected='false'])[2]");
await page.waitForSelector('id=form-select-business-type');
await page.click('id=form-select-business-type');
await page.click('id=form-select-business-type_6');
await page.waitForSelector('id=form-select-job-position');
await page.click('id=form-select-job-position');
await page.click('id=form-select-job-position_0');
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '22282205202');
await page.fill('id=form-input-address-no', '200');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_4');
await page.click('id=form-select-province_4');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_8');
await page.click('id=form-select-district_8');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_7');
await page.click('id=form-select-sub-district_7');
await page.fill('id=form-input-address-en', '200');
await page.click("//button[@type='submit']");
await page.click('id=btn-form-close');
// กำหนดค่าเพื่อตรวจสอบความถูกต้องหลังสร้าง
const nameTitleNatrualPerson = await page.locator(
"//tr[contains(.,'นาย ยศพัฒน์ ธนากานต์') and contains (.,'--')]",
);
expect(nameTitleNatrualPerson).toContainText('ยศพัฒน์ ธนากานต์');
expect(nameTitleNatrualPerson).toContainText('--');
console.log('ระบบสามารถสร้างนายจ้างบุคคลธรรมดาได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาครั้งที่ 2', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForTimeout(2000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
// ส่วนเกี่ยวกับ
await page.fill('id=input-card-number', '1886222422008');
await page.waitForSelector('id=form-select-prefix-name');
await page.click('id=form-select-prefix-name');
await page.waitForSelector('id=form-select-prefix-name_0');
await page.click('id=form-select-prefix-name_0');
await page.fill('id=form-input-first-name', 'สุรวัฒน์');
await page.fill('id=form-input-last-name', 'จันทรสมบัติ ');
await page.fill('id=form-input-first-name-en', 'Surawat');
await page.fill('id=form-input-last-name-en', 'Jantarasombat');
await page.fill('id=form-input-telephone', '0864240842');
await page.waitForSelector('id=form-input-birth-date');
await page.click('id=form-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1999']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ต.ค.']");
await page.click("//div[@id='1999-10-02']/div[1]");
// ส่วนข้อมูลธุรกิจ
await page.waitForSelector("(//div[@aria-selected='false'])[2]");
await page.click("(//div[@aria-selected='false'])[2]");
await page.waitForSelector('id=form-select-business-type');
await page.click('id=form-select-business-type');
await page.click('id=form-select-business-type_6');
await page.waitForSelector('id=form-select-job-position');
await page.click('id=form-select-job-position');
await page.click('id=form-select-job-position_0');
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '22282205202');
await page.fill('id=form-input-address-no', '200');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_4');
await page.click('id=form-select-province_4');
await page.click('id=form-select-district');
await page.waitForTimeout(1000);
await page.waitForSelector('id=form-select-district_8');
await page.click('id=form-select-district_8');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_7');
await page.click('id=form-select-sub-district_7');
await page.fill('id=form-input-address-en', '200');
await page.click("//button[@type='submit']");
await page.click('id=btn-form-close');
// กำหนดค่าเพื่อตรวจสอบความถูกต้องหลังสร้าง
const nameTitleNatrualPerson = await page.locator(
"//tr[contains(.,'นาย สุรวัฒน์ จันทรสมบัติ') and contains (.,'--')]",
);
expect(nameTitleNatrualPerson).toContainText('สุรวัฒน์ จันทรสมบัติ');
expect(nameTitleNatrualPerson).toContainText('--');
console.log('ระบบสามารถสร้างนายจ้างบุคคลธรรมดาได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,541 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { formToJSON } from 'axios';
import { exec } from 'child_process';
import { ToastHeader } from 'react-bootstrap';
import { toHandlerKey } from 'vue';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
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.waitForTimeout(1000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("//button[@type='submit']");
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'Please select Birth Date.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ตรวจสอบการแจ้งเตือนทั้งหมดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนเกี่ยวกับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.fill('id=input-legal-person-no', '1222202282262');
await page.click('id=form-select-prefix-name');
await page.waitForSelector('id=form-select-prefix-name_0');
await page.click('id=form-select-prefix-name_0');
await page.fill("(//input[@id='form-input-first-name'])[1]", 'มานะ');
await page.fill("(//input[@id='form-input-last-name'])[1]", 'แมน');
await page.fill("(//input[@id='form-input-first-name'])[3]", 'Mana');
await page.fill("(//input[@id='form-input-last-name'])[2]", 'Man');
await page.click('id=form-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='2002']");
await page.click("//div[text()='2002']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='May']");
await page.click("//div[@id='2002-05-02']/div[1]");
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on Business, Address page']",
);
await expect(textPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on Business, Address page',
);
console.log('ตรวจสอบการแจ้งเตือน Pop-up สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่ได้กรอกข้อมูลส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[2]");
await page.click("//button[@type='submit']");
const expectedErrors = [
{
locator: "//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "//div[@class='q-field__messages col']//div)[2]",
message: 'This field is required.',
},
{
locator: "//div[@class='q-field__messages col']//div)[3]",
message: 'This field is required.',
},
{
locator: "//div[@class='q-field__messages col']//div)[4]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[2]");
await page.click('id=form-select-business-type');
await page.waitForSelector('id=form-select-business-type_1');
await page.click('id=form-select-business-type_1');
await page.click('id=form-select-job-position');
await page.waitForSelector('id=form-select-job-position_1');
await page.click('id=form-select-job-position_1');
await page.fill('id=form-input-job-description', 'รายละเอียด');
await page.fill("(//input[@id='form-input-pay-rate'])[1]", 'วันจ่ายเงิน');
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay Day');
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '2000');
await page.fill("//input[@aria-label='Pay Rate (Text)']", '2000');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Address page']",
);
await expect(textPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Address page',
);
console.log('การแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่กรอกข้อมูลส่วนที่อยู่นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[3]");
await page.click("//button[@type='submit']");
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'Please select Province.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'Please select District.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'Please select Sub-district.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลรหัสประจำบ้านไม่ครบ 11 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '111');
await page.click("//button[@type='submit']");
// กำหนดค่าการแจ้งเตือน
const codeAddress = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
// ตรวจสอบการแจ้งเตือน
expect(codeAddress).toHaveText('Invalid value. Please enter 11 character');
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนที่อยู่นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForTimeout(1000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '22282202202');
await page.fill('id=form-input-address-no', '800');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_4');
await page.click('id=form-select-province_4');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_8');
await page.click('id=form-select-district_8');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_7');
await page.click('id=form-select-sub-district_7');
await page.fill('id=form-input-address-en', '800');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business page']",
);
await expect(textPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business page',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่กรอกข้อมูลส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[4]");
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(textPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[4]");
await page.fill('id=form-input-contact-name', 'คุณอาท');
await page.fill('id=form-input-mail', 'art@mail.com');
await page.fill("(//input[@id='form-input-telephone'])[1]", '0882622426');
await page.fill("(//input[@id='form-input-telephone'])[2]", '022222002');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(textPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกรูปแบบอีเมลส่วนข้อมูลติดต่อไม่ถูกต้อง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[4]");
await page.fill('id=form-input-mail', 'art');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const emailError = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(emailError).toHaveText('Invalid value.');
console.log('ตรวจสอบการแจ้งเตือนรูปแบบอีเมลไม่ถูกต้อง : Success ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่อัปโหลดข้อมูลส่วนเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[5]");
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(textPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
// test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่อัปโหลดเอกสารเฉพาะส่วนเอกสาร', async () => {
// await page.click('id=menu-icon-customer-management');
// try {
// await page.click('id=btn-add');
// await page.click('id=add-customer-natural-person');
// await page.click("(//div[@aria-selected='false'])[5]");
// await page.click("//button[@type='submit']");
// // กำหนดค่าแจ้งเตือน
// const popupError = await page.locator(
// "//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// );
// // ตรวจสอบการแจ้งเตือน
// expect(popupError).toHaveText('กรอกข้อมูลไม่ครบ');
// console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// throw error;
// }
// await page.waitForSelector('id=btn-ok-dialog');
// await page.click('id=btn-ok-dialog');
// await page.waitForTimeout(2000);
// await page.click('id=btn-form-close');
// });

View file

@ -0,0 +1,545 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { formToJSON } from 'axios';
import { exec } from 'child_process';
import e from 'express';
import { ToastHeader } from 'react-bootstrap';
import { toHandlerKey } from 'vue';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
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.waitForTimeout(1000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("//button[@type='submit']");
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col'])[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col'])[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col'])[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col'])[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col'])[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col'])[6]",
message: 'โปรดเลือกวันเดือนปีเกิด',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ตรวจสอบการแจ้งเตือนทั้งหมดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนเกี่ยวกับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.fill('id=input-legal-person-no', '1222202282262');
await page.click('id=form-select-prefix-name');
await page.waitForSelector('id=form-select-prefix-name_0');
await page.click('id=form-select-prefix-name_0');
await page.fill("(//input[@id='form-input-first-name'])[1]", 'มานะ');
await page.fill("(//input[@id='form-input-last-name'])[1]", 'แมน');
await page.fill("(//input[@id='form-input-first-name'])[3]", 'Mana');
await page.fill("(//input[@id='form-input-last-name'])[2]", 'Man');
await page.click('id=form-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='2002']");
await page.click("//div[text()='2002']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='พ.ค.']");
await page.click("//div[@id='2002-05-02']/div[1]");
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า ข้อมูลธุรกิจ, ที่อยู่นายจ้าง']",
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า ข้อมูลธุรกิจ, ที่อยู่นายจ้าง',
);
console.log('ตรวจสอบการแจ้งเตือน Pop-up สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่ได้กรอกข้อมูลส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[2]");
await page.click("//button[@type='submit']");
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);
}
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[2]");
await page.click('id=form-select-business-type');
await page.waitForSelector('id=form-select-business-type_1');
await page.click('id=form-select-business-type_1');
await page.click('id=form-select-job-position');
await page.waitForSelector('id=form-select-job-position_1');
await page.click('id=form-select-job-position_1');
await page.fill('id=form-input-job-description', 'รายละเอียด');
await page.fill("(//input[@id='form-input-pay-rate'])[1]", 'วันจ่ายเงิน');
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay Day');
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '2000');
await page.fill("//input[@aria-label='อัตราค่าจ้าง/วัน (Text)']", '2000');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ที่อยู่นายจ้าง']",
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ที่อยู่นายจ้าง',
);
console.log('การแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่กรอกข้อมูลส่วนที่อยู่นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[3]");
await page.click("//button[@type='submit']");
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: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลรหัสประจำบ้านไม่ครบ 11 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '111');
await page.click("//button[@type='submit']");
// กำหนดค่าการแจ้งเตือน
const codeAddress = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
// ตรวจสอบการแจ้งเตือน
expect(codeAddress).toHaveText('ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 11 หลัก');
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนที่อยู่นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForTimeout(1000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '22282202202');
await page.fill('id=form-input-address-no', '800');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_4');
await page.click('id=form-select-province_4');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_8');
await page.click('id=form-select-district_8');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_7');
await page.click('id=form-select-sub-district_7');
await page.fill('id=form-input-address-en', '800');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ']",
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่กรอกข้อมูลส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[4]");
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง']",
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[4]");
await page.fill('id=form-input-contact-name', 'คุณอาท');
await page.fill('id=form-input-mail', 'art@mail.com');
await page.fill("(//input[@id='form-input-telephone'])[1]", '0882622426');
await page.fill("(//input[@id='form-input-telephone'])[2]", '022222002');
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง']",
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกรูปแบบอีเมลส่วนข้อมูลติดต่อไม่ถูกต้อง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[4]");
await page.fill('id=form-input-mail', 'art');
await page.click("//button[@type='submit']");
// กำหนดค่าการแจ้งเตือน
const emailFomatError = await page.locator(
"//div[normalize-space(text())='ข้อมูลไม่ถูกต้อง']",
);
// ตรวจสอบการแจ้งเตือน
expect(emailFomatError).toHaveText('ข้อมูลไม่ถูกต้อง');
console.log('ตรวจสอบการแจ้งเตือนรูปแบบอีเมลไม่ถูกต้อง : Success ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่อัปโหลดข้อมูลส่วนเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
await page.click("(//div[@aria-selected='false'])[5]");
await page.click("//button[@type='submit']");
// รอการเกิด Dialog
const textPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง']",
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง',
);
console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
// test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่อัปโหลดเอกสารเฉพาะส่วนเอกสาร', async () => {
// await page.click('id=menu-icon-customer-management');
// try {
// await page.click('id=btn-add');
// await page.click('id=add-customer-natural-person');
// await page.click("(//div[@aria-selected='false'])[5]");
// await page.click("//button[@type='submit']");
// // กำหนดค่าแจ้งเตือน
// const popupError = await page.locator(
// "//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// );
// // ตรวจสอบการแจ้งเตือน
// expect(popupError).toHaveText('กรอกข้อมูลไม่ครบ');
// console.log('ตรวจสอบการแจ้งเตือนถูกต้อง');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// throw error;
// }
// await page.waitForSelector('id=btn-ok-dialog');
// await page.click('id=btn-ok-dialog');
// await page.waitForTimeout(2000);
// await page.click('id=btn-form-close');
// });

View file

@ -0,0 +1,118 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
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("(//button[@id='btn-eye-ยศพัฒน์'])[2]");
await page.waitForTimeout(2000);
const fullName = page.locator("//span[text()='ยศพัฒน์ ธนากานต์']");
await expect(fullName).toHaveText('ยศพัฒน์ ธนากานต์');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
});
test('ตรวจสอบดูรายละเอียดบุคคลธรรมดาผ่านเมนูย่อยจุดสามจุด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ยศพัฒน์');
await page.waitForSelector('id=btn-kebab-view-detail-ยศพัฒน์');
await page.click('id=btn-kebab-view-detail-ยศพัฒน์');
await page.waitForTimeout(2000);
const fullName = page.locator("//span[text()='ยศพัฒน์ ธนากานต์']");
await expect(fullName).toHaveText('ยศพัฒน์ ธนากานต์');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
});
test('ตรวจสอบดูรายละเอียดบุคคลธรรมดาในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const fullName = await page.locator(
"//b[normalize-space(text())='ยศพัฒน์ ธนากานต์']",
);
const citizenId = await page.locator(
"//span[normalize-space(text())='1524428220420']",
);
const typeBussiness = await page.locator(
"(//span[text()='ประเภทกิจการ']/following-sibling::span)[1]",
);
await expect(fullName).toHaveText('ยศพัฒน์ ธนากานต์');
await expect(citizenId).toHaveText('1524428220420');
await expect(typeBussiness).toHaveText('กรรมกร');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,78 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Edit Naturalperson', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-สุรวัฒน์');
await page.waitForSelector('id=btn-kebab-edit-สุรวัฒน์');
await page.click('id=btn-kebab-edit-สุรวัฒน์');
// แก้ไขนายจ้างบุคคลธรรมดา
await page.fill("(//input[@id='info-input-first-name'])[1]", 'ธนพล');
await page.fill("(//input[@id='info-input-last-name'])[1]", 'รุ่งเรือง');
await page.fill("(//input[@id='info-input-first-name'])[3]", 'Thanapol');
await page.fill("(//input[@id='info-input-last-name'])[2]", 'Rungreung');
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.waitForTimeout(1000);
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
const nameEditCheck = await page.locator(
"//tr[contains(.,'นาย ธนพล รุ่งเรือง') and contains(.,'--')]",
);
await expect(nameEditCheck).toContainText('ธนพล รุ่งเรือง');
await expect(nameEditCheck).toContainText('--');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,72 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { it } from 'node: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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Delete Naturalperson', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
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');
await page.waitForTimeout(2000);
const itemLocator = await page.locator(
"//tr[contains(.,'นาย สุรวัฒน์ รุ่งเรือง') and contains (.,'--')]",
);
await expect(itemLocator).toBeHidden();
console.log('ระบบทำการลบนายจ้างบุคคลธรรมดาแล้ว ');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,125 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
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-kebab-action-ยศพัฒน์');
await page.click('id=btn-kebab-status-ยศพัฒน์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'นาย ยศพัฒน์ ธนากานต์')and contains (.,'--')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะนายจ้างบุคคลธรรมดา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ยศพัฒน์');
await page.click('id=btn-kebab-status-ยศพัฒน์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'นาย ยศพัฒน์ ธนากานต์')and contains (.,'--')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,265 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Legalentitly Person', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForTimeout(2000);
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
// ส่วนเกี่ยวกับ
await page.fill(
'id=input-register-name',
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด ',
);
await page.fill('id=input-register-name-en', 'AsiaTech Systems Co., Ltd.');
await page.fill('id=input-legal-person-no', 'อนุชา ศรีสวัสดิ์');
await page.fill('id=input-legal-person-code', '2022822642228');
// จดทะเบียนเมื่อ
await page.click("(//input[@id='form-input-register-date'])[1]");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2020']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ก.ย.']");
await page.click("//div[@id='2020-09-18']/div[1]");
await page.fill('id=input-authorized-capital', '10000000');
await page.fill('id=input-telephone-no', '022202002');
// ส่วนข้อมูลธุรกิจ
await page.click("(//div[@class='q-tab__label'])[2]");
await page.click('id=form-select-business-type');
await page.waitForSelector('id=form-select-business-type_3');
await page.click('id=form-select-business-type_3');
await page.click('id=form-select-job-position');
await page.waitForSelector('id=form-select-job-position_0');
await page.click('id=form-select-job-position_0');
await page.fill('id=form-input-job-description', 'รายละเอียดงาน');
await page.fill(
"(//input[@id='form-input-pay-rate'])[1]",
'วันจ่ายเงินเดือน',
);
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay day');
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '2000');
// ส่วนผู้มีอำนาจลงนาม
await page.click("(//div[@class='q-tab__label'])[3]");
await page.fill(
"(//input[@id='form-input-contact-name'])[1]",
'อนุชา ศรีสวัสดิ์',
);
await page.fill(
"(//input[@id='form-input-contact-name'])[2]",
'Anucha Srisawat',
);
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill("(//input[@id='form-input-address'])[1]", '20228226242');
await page.fill(
'id=form-input-address-no',
'1234 อาคารซิตี้ทาวเวอร์ ชั้น 12',
);
await page.fill("(//input[@id='form-input-street'])[1]", 'สาทรใต้');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_0');
await page.click('id=form-select-province_0');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_11');
await page.click('id=form-select-district_11');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_1');
await page.click('id=form-select-sub-district_1');
await page.fill(
'id=form-input-address-en',
'1234 City Tower Building, 12th Floor',
);
await page.fill("(//input[@id='form-input-street'])[2]", 'South Sathorn');
// ส่วนข้อมูลผู้ติดต่อ
await page.click("(//div[@class='q-tab__label'])[5]");
await page.fill('id=form-input-contact-name', 'วราภรณ์ ศรีสวัสดิ์');
await page.fill('id=form-input-mail', 'asiatech@support.com');
await page.fill("(//input[@id='form-input-telephone'])[1]", '0866522622');
await page.fill("(//input[@id='form-input-telephone'])[2]", '022022002');
await page.click('id=quotation-branch');
await page.waitForSelector('id=quotation-branch_1');
await page.click('id=quotation-branch_1');
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const legalentitlyNameCheck = await page.locator(
"//tr[contains(.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด') and contains (.,'022022002')]",
);
await expect(legalentitlyNameCheck).toContainText(
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด',
);
await expect(legalentitlyNameCheck).toContainText('022022002');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('Create Legalentitly Person Second', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
// ส่วนเกี่ยวกับ
await page.fill(
'id=input-register-name',
'บริษัท กรีนโกลบอล โซลูชั่นส์ จำกัด',
);
await page.fill(
'id=input-register-name-en',
'Green Global Solutions Co., Ltd.',
);
await page.fill('id=input-legal-person-no', 'ณัฐวุฒิ เกียรติกุล');
await page.fill('id=input-legal-person-code', '2022822642229');
// จดทะเบียนเมื่อ
await page.click("(//input[@id='form-input-register-date'])[1]");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2021']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ก.ย.']");
await page.click("//div[@id='2021-09-18']/div[1]");
await page.fill('id=input-authorized-capital', '10000000');
await page.fill('id=input-telephone-no', '022202002');
// ส่วนข้อมูลธุรกิจ
await page.click("(//div[@class='q-tab__label'])[2]");
await page.click('id=form-select-business-type');
await page.waitForSelector('id=form-select-business-type_2');
await page.click('id=form-select-business-type_2');
await page.click('id=form-select-job-position');
await page.waitForSelector('id=form-select-job-position_0');
await page.click('id=form-select-job-position_0');
await page.fill('id=form-input-job-description', 'รายละเอียดงาน');
await page.fill(
"(//input[@id='form-input-pay-rate'])[1]",
'วันจ่ายเงินเดือน',
);
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay day');
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '2000');
// ส่วนผู้มีอำนาจลงนาม
await page.click("(//div[@class='q-tab__label'])[3]");
await page.fill(
"(//input[@id='form-input-contact-name'])[1]",
'ณัฐวุฒิ เกียรติกุล',
);
await page.fill(
"(//input[@id='form-input-contact-name'])[2]",
'Nattawut Kiatkul',
);
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill("(//input[@id='form-input-address'])[1]", '20228226244');
await page.fill(
'id=form-input-address-no',
'5678 อาคารอินฟินิท พลาซ่า ชั้น 8',
);
await page.fill("(//input[@id='form-input-street'])[1]", 'เพลินจิต');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_0');
await page.click('id=form-select-province_0');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_6');
await page.click('id=form-select-district_6');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_3');
await page.click('id=form-select-sub-district_3');
await page.fill(
'id=form-input-address-en',
'5678 Infinite Plaza Building, 8th Floor',
);
await page.fill("(//input[@id='form-input-street'])[2]", 'Ploenchit');
// ส่วนข้อมูลผู้ติดต่อ
await page.click("(//div[@class='q-tab__label'])[5]");
await page.fill('id=form-input-contact-name', 'ณัฐวุฒิ เกียรติกุล');
await page.fill('id=form-input-mail', 'asiatech@support.com');
await page.fill("(//input[@id='form-input-telephone'])[1]", '0866522624');
await page.fill("(//input[@id='form-input-telephone'])[2]", '022022000');
await page.click('id=quotation-branch');
await page.waitForSelector('id=quotation-branch_0');
await page.click('id=quotation-branch_0');
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const legalentitlyNameCheck = await page.locator(
"//tr[contains(.,'บริษัท กรีนโกลบอล โซลูชั่นส์ จำกัด') and contains (.,'022022000')]",
);
await expect(legalentitlyNameCheck).toContainText(
'บริษัท กรีนโกลบอล โซลูชั่นส์ จำกัด',
);
await expect(legalentitlyNameCheck).toContainText('022022000');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,557 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
import exp from 'constants';
import e from 'express';
import { execPath } from 'process';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
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.waitForTimeout(2000);
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.click("//button[@type='submit']");
const companyNameError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const legalCodeError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(companyNameError).toHaveText('This field is required.');
await expect(legalCodeError).toHaveText('This field is required.');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกเฉพาะส่วนเกี่ยวกับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
// ส่วนเกี่ยวกับ
await page.fill(
'id=input-register-name',
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด ',
);
await page.fill('id=input-register-name-en', 'AsiaTech Systems Co., Ltd.');
await page.fill('id=input-legal-person-no', 'อนุชา ศรีสวัสดิ์');
await page.fill('id=input-legal-person-code', '2022822642228');
// จดทะเบียนเมื่อ
await page.click("(//input[@id='form-input-register-date'])[1]");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2020']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='Sep']");
await page.click("//div[@id='2020-09-18']/div[1]");
await page.fill('id=input-authorized-capital', '10000000');
await page.fill('id=input-telephone-no', '022202002');
await page.click("//button[@type='submit']");
const headPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on Business, Address page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on Business, Address page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[2]");
await page.click("(//div[@class='q-tab__label'])[2]");
await page.click("//button[@type='submit']");
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[2]");
await page.click("(//div[@class='q-tab__label'])[2]");
await page.click('id=form-select-business-type');
await page.waitForSelector('id=form-select-business-type_5');
await page.click('id=form-select-business-type_5');
await page.click('id=form-select-job-position');
await page.waitForSelector('id=form-select-job-position_2');
await page.click('id=form-select-job-position_2');
await page.fill('id=form-input-job-description', 'รายละเอียดงาน');
await page.fill(
"(//input[@id='form-input-pay-rate'])[1]",
'วันที่จ่ายเงินเดือน',
);
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay Day');
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '500');
await page.click("//button[@type='submit']");
const headPopupError = page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Address page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Address page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนผู้มีอำนาจลงนาม', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[3]");
await page.click("(//div[@class='q-tab__label'])[3]");
await page.click("//button[@type='submit']");
const headPopupError = page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกข้อมูลเฉพาะส่วนผู้มีอำนาจลงนาม', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[3]");
await page.click("(//div[@class='q-tab__label'])[3]");
await page.fill(
"(//input[@id='form-input-contact-name'])[1]",
'ผู้มีอำนาจลงนาม',
);
await page.fill(
"(//input[@id='form-input-contact-name'])[2]",
'ผู้มีอำนาจลงนาม EN',
);
await page.click("//button[@type='submit']");
const headPopupError = page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนที่อยู๋นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[4]");
await page.click("(//div[@class='q-tab__label'])[4]");
await page.click("//button[@type='submit']");
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'This field is required.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'Please select Province.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'Please select District.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'Please select Sub-district.',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'This field is required.',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกเฉพาะข้อมูลส่วนที่อยู๋นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[4]");
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill("(//input[@id='form-input-address'])[1]", '22082202202');
await page.fill('id=form-input-address-no', '20/02');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_3');
await page.click('id=form-select-province_3');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_5');
await page.click('id=form-select-district_5');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_2');
await page.click('id=form-select-sub-district_2');
await page.fill('id=form-input-address-en', '20/02');
await page.click("//button[@type='submit']");
const headPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกช่องรหัสประจำบ้านไม่ครบ 11 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[4]");
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill("(//input[@id='form-input-address'])[1]", '123');
const addressNumberError = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(addressNumberError).toHaveText(
'Invalid value. Please enter 11 character',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[5]");
await page.click("(//div[@class='q-tab__label'])[5]");
await page.click("//button[@type='submit']");
const headPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[5]");
await page.click("(//div[@class='q-tab__label'])[5]");
await page.fill('id=form-input-contact-name', 'ชื่อผู้ติดต่อ');
await page.fill('id=form-input-mail', 'mail@mail.com');
await page.fill("(//input[@id='form-input-telephone'])[1]", '0886224228');
await page.fill("(//input[@id='form-input-telephone'])[2]", '022002800');
await page.click('id=quotation-branch');
await page.waitForSelector('id=quotation-branch_0');
await page.click('id=quotation-branch_0');
await page.click("//button[@type='submit']");
const headPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete Data Entry']",
);
const detailPopupError = await page.locator(
"//span[normalize-space(text())='Incomplete data entry on About, Business, Address page']",
);
await expect(headPopupError).toHaveText('Incomplete Data Entry');
await expect(detailPopupError).toHaveText(
'Incomplete data entry on About, Business, Address page',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกอีเมลไม่ตรงรูปแบบของส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[5]");
await page.click("(//div[@class='q-tab__label'])[5]");
await page.fill('id=form-input-mail', 'mail');
const emailError = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(emailError).toHaveText('Invalid value.');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,550 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
import exp from 'constants';
import e from 'express';
import { execPath } from 'process';
import { urlToHttpOptions } from 'url';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
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.waitForTimeout(2000);
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.click("//button[@type='submit']");
const companyNameError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const legalCodeError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(companyNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(legalCodeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกเฉพาะส่วนเกี่ยวกับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
// ส่วนเกี่ยวกับ
await page.fill(
'id=input-register-name',
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด ',
);
await page.fill('id=input-register-name-en', 'AsiaTech Systems Co., Ltd.');
await page.fill('id=input-legal-person-no', 'อนุชา ศรีสวัสดิ์');
await page.fill('id=input-legal-person-code', '2022822642228');
// จดทะเบียนเมื่อ
await page.click("(//input[@id='form-input-register-date'])[1]");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2020']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ก.ย.']");
await page.click("//div[@id='2020-09-18']/div[1]");
await page.fill('id=input-authorized-capital', '10000000');
await page.fill('id=input-telephone-no', '022202002');
await page.click("//button[@type='submit']");
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.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[2]");
await page.click("(//div[@class='q-tab__label'])[2]");
await page.click("//button[@type='submit']");
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.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[2]");
await page.click("(//div[@class='q-tab__label'])[2]");
await page.click('id=form-select-business-type');
await page.waitForSelector('id=form-select-business-type_5');
await page.click('id=form-select-business-type_5');
await page.click('id=form-select-job-position');
await page.waitForSelector('id=form-select-job-position_2');
await page.click('id=form-select-job-position_2');
await page.fill('id=form-input-job-description', 'รายละเอียดงาน');
await page.fill(
"(//input[@id='form-input-pay-rate'])[1]",
'วันที่จ่ายเงินเดือน',
);
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay Day');
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '500');
await page.click("//button[@type='submit']");
const headPopupError = page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ที่อยู่นายจ้าง']",
);
await expect(headPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ที่อยู่นายจ้าง',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนผู้มีอำนาจลงนาม', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[3]");
await page.click("(//div[@class='q-tab__label'])[3]");
await page.click("//button[@type='submit']");
const headPopupError = page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง']",
);
await expect(headPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกข้อมูลเฉพาะส่วนผู้มีอำนาจลงนาม', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[3]");
await page.click("(//div[@class='q-tab__label'])[3]");
await page.fill(
"(//input[@id='form-input-contact-name'])[1]",
'ผู้มีอำนาจลงนาม',
);
await page.fill(
"(//input[@id='form-input-contact-name'])[2]",
'ผู้มีอำนาจลงนาม EN',
);
await page.click("//button[@type='submit']");
const headPopupError = page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
);
const detailPopupError = page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง']",
);
await expect(headPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
await expect(detailPopupError).toHaveText(
'กรอกข้อมูลไม่ครบในหน้า เกี่ยวกับ, ข้อมูลธุรกิจ, ที่อยู่นายจ้าง',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนที่อยู๋นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[4]");
await page.click("(//div[@class='q-tab__label'])[4]");
await page.click("//button[@type='submit']");
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: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกเฉพาะข้อมูลส่วนที่อยู๋นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[4]");
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill("(//input[@id='form-input-address'])[1]", '22082202202');
await page.fill('id=form-input-address-no', '20/02');
await page.click('id=form-select-province');
await page.waitForSelector('id=form-select-province_3');
await page.click('id=form-select-province_3');
await page.click('id=form-select-district');
await page.waitForSelector('id=form-select-district_5');
await page.click('id=form-select-district_5');
await page.click('id=form-select-sub-district');
await page.waitForSelector('id=form-select-sub-district_2');
await page.click('id=form-select-sub-district_2');
await page.fill('id=form-input-address-en', '20/02');
await page.click("//button[@type='submit']");
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.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกช่องรหัสประจำบ้านไม่ครบ 11 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[4]");
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill("(//input[@id='form-input-address'])[1]", '123');
const addressNumberError = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(addressNumberError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 11 หลัก',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่ไม่กรอกข้อมูลส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[5]");
await page.click("(//div[@class='q-tab__label'])[5]");
await page.click("//button[@type='submit']");
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.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[5]");
await page.click("(//div[@class='q-tab__label'])[5]");
await page.fill('id=form-input-contact-name', 'ชื่อผู้ติดต่อ');
await page.fill('id=form-input-mail', 'mail@mail.com');
await page.fill("(//input[@id='form-input-telephone'])[1]", '0886224228');
await page.fill("(//input[@id='form-input-telephone'])[2]", '022002800');
await page.click('id=quotation-branch');
await page.waitForSelector('id=quotation-branch_0');
await page.click('id=quotation-branch_0');
await page.click("//button[@type='submit']");
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.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มนิติบุคคลในกรณีที่กรอกอีเมลไม่ตรงรูปแบบของส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=add-customer-legal-entity');
await page.click('id=add-customer-legal-entity');
await page.waitForSelector("(//div[@class='q-tab__label'])[5]");
await page.click("(//div[@class='q-tab__label'])[5]");
await page.fill('id=form-input-mail', 'mail');
const emailError = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,120 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { LOADIPHLPAPI } from 'dns';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
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("(//button[@id='btn-eye-อนุชา ศรีสวัสดิ์'])[2]");
await page.waitForTimeout(2000);
const fullNamelegal = await page.locator(
"//div[@class='col column']//span[1]",
);
await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการดูรายละเอียดนิติบุคคลโดยการคลิกเมนูย่อย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-อนุชา ศรีสวัสดิ์');
await page.waitForSelector('id=btn-kebab-view-detail-อนุชา ศรีสวัสดิ์');
await page.click('id=btn-kebab-view-detail-อนุชา ศรีสวัสดิ์');
await page.waitForTimeout(2000);
const fullNamelegal = await page.locator(
"//div[@class='col column']//span[1]",
);
await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการดูรายละเอียดนิติบุคคลในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const isCardView = await page
.locator("(//div[@id='branch-card-undefined'])[2]")
.isVisible();
const fullNamelegal = await page.locator(
"//b[normalize-space(text())='บริษัท เอเชียเทค ซิสเต็มส์ จำกัด']",
);
await expect(isCardView).toBe(true);
await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
console.log('ระบบทำการเปลี่ยนรูปแบบเป็นการ์ดแล้ว');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,113 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
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.waitForSelector('id=btn-kebab-action-ณัฐวุฒิ เกียรติกุล');
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-register-name',
'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด',
);
await page.fill(
'id=input-register-name-en',
'Siam Energy Solutions Co., Ltd.',
);
await page.fill('id=input-legal-person-no', 'ภาคิน วงศ์ศรีสุข');
await page.fill('id=input-authorized-capital', '15000000');
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill(
'id=info-input-address-no',
'123/45 อาคารเพิร์ล ทาวเวอร์ ชั้น 10',
);
await page.fill("(//input[@id='info-input-street'])[1]", 'พหลโยธิน');
await page.click('id=info-select-province');
await page.waitForSelector('id=info-select-province_0');
await page.click('id=info-select-province_0');
await page.click('id=info-select-district');
await page.waitForSelector('id=info-select-district_26');
await page.click('id=info-select-district_26');
await page.click('id=info-select-sub-district');
await page.waitForSelector('id=info-select-sub-district_1');
await page.click('id=info-select-sub-district_1');
await page.fill(
'id=info-input-address-en',
'123/45 Pearl Tower, 10th Floor',
);
await page.fill("(//input[@id='info-input-street'])[2]", 'Phahonyothin');
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
await page.waitForTimeout(2000);
const legalAfterEdit = await page.locator(
"//tr[contains(.,'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด') and contains (.,'022022000')]",
);
await expect(legalAfterEdit).toContainText(
'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด',
);
await expect(legalAfterEdit).toContainText('022022000');
console.log('ระบบทดสอบการแก้ไขสำเร็จ');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,72 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { it } from 'node: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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Delete Legalentitly', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
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 itemLocator = await page.locator(
"//tr[contains(.,'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด') and contains (.,'022022000')]",
);
await expect(itemLocator).toBeHidden();
console.log('ระบบทำการลบนายจ้างนิติบุคคลแล้ว');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,122 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ปิดสถานะนายจ้างนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-อนุชา ศรีสวัสดิ์');
await page.click('id=btn-kebab-status-อนุชา ศรีสวัสดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด') and contains (.,'022022002')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะนายจ้างนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-อนุชา ศรีสวัสดิ์');
await page.click('id=btn-kebab-status-อนุชา ศรีสวัสดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด') and contains (.,'022022002')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,477 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงลำดับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_0');
const column1Cells = page.locator("//th[normalize-space(text())='ลําดับ']");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 1 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_0'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 1 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อ บริษัท/นิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_1');
const column1Cells = page.locator(
"//th[normalize-space(text())='ชื่อ บริษัท/นิติบุคคล']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 1 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_1'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 2 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 2 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลประเภทกิจการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_2');
const column1Cells = page.locator(
"//th[normalize-space(text())='ประเภทกิจการ']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 3 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_2'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 3 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลตำแหน่งงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_3');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_3');
const column1Cells = page.locator(
"//th[normalize-space(text())='ตำแหน่งงาน']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 4 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_3'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 4 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลที่อยู่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_4');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_4');
const column1Cells = page.locator(
"//th[normalize-space(text())='ที่อยู่']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 5 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_4'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 5 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อผู้ติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_5');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_5');
const column1Cells = page.locator(
"//th[normalize-space(text())='ชื่อผู้ติดต่อ']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 6 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 6 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_5'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 6 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 6 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลเบอร์โทรติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_6');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_6');
const column1Cells = page.locator(
"//th[normalize-space(text())='เบอร์โทรติดต่อ']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 7 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 7 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_6'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 7 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 7 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,102 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
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 {
// กำหนดคำที่จะค้นหา
const searchDatas = [
'Yossapat',
'ยศพัฒน์ ธนากานต์',
'AsiaTech Systems Co., Ltd',
'Systems',
'Tanakarn',
];
for (const searchData of searchDatas) {
// พิมพ์คำที่ต้องการค้นหา
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
await page.waitForTimeout(2000);
// ดึงผลลัพฑ์การค้นหาทั้งหมด
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
const resultCount = await searchResults.count();
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
if (resultCount === 0) {
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
continue; // ข้ามคำค้นหาคำถัดไป
}
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
const searchResultTexts = await searchResults.allTextContents();
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
const allResultContainSearchData = searchResultTexts.every((result) =>
result.includes(searchData),
);
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
if (!allResultContainSearchData) {
console.error(
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
);
continue; // ข้ามไปคำค้นหาถัดไป
}
expect(allResultContainSearchData).toBe(true);
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,113 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
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 {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.waitForTimeout(1000);
await page.click('id=select-status');
//รอให้ dropdown เปิด
await page.waitForSelector('id=select-status_1');
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,331 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { writeFileSync } from 'fs';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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.waitForTimeout(2000);
// ส่วนข้อมูลพื้นฐาน
await page.click('id=form-employee-select-employer-branch');
await page.waitForSelector('id=form-employee-select-employer-branch_1');
await page.click('id=form-employee-select-employer-branch_1');
await page.fill('id=form-employee-input-nrc-no', '2822022820220');
// ส่วนข้้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'กิตติศักดิ์',
);
await page.fill('id=form-employee-input-last-name', 'วิจิตรานนท์');
await page.fill('id=form-employee-input-first-name-en', 'Kittisak');
await page.fill('id=form-employee-input-last-name-en', 'Wijitranon');
// วันเดิิอนปีเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1996']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='พ.ค.']");
await page.click("//div[@id='1996-05-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_2');
await page.click('id=form-employee-select-nationality_2');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// -------------------- Tab ข้อมูลหนังสือเดินทาง ------------------------------
await page.waitForSelector(
'id=dialog-tab-customerEmployee.fileType.passport',
{
state: 'visible',
},
);
await page.click('id=dialog-tab-customerEmployee.fileType.passport', {
force: true,
});
await page.fill(
"(//input[@id='drawer-info-employee-input-passport-no'])[2]",
'MM202228',
);
await page.click(
"(//input[@id='drawer-info-employee-select-passport-country'])[2]",
);
await page.waitForSelector(
'id=drawer-info-employee-select-passport-country_1',
);
await page.click('id=drawer-info-employee-select-passport-country_1');
// วันหมดอายุหนังสือเดือนทาง
await page.waitForTimeout(1000);
await page.click(
"(//input[@id='drawer-info-employee-date-picker-passport-expire'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2030']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[@data-test='ส.ค.']");
await page.click("//div[@id='2030-08-10']/div[1]");
await page.waitForSelector("(//button[@type='submit'])[2]");
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
// -------------------- Tab ข้อมูล Visa ------------------------------------
await page.waitForSelector(
'id=dialog-tab-customerEmployee.form.group.visa',
{
state: 'visible',
},
);
await page.click('id=dialog-tab-customerEmployee.form.group.visa', {
force: true,
});
// ใช้ได้ถึงวันที่
await page.click(
"(//input[@id='drawer-info-employee-date-picker-visa-expire'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2030']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ธ.ค.']");
await page.click("//div[@id='2030-12-04']/div[1]");
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const employeeCheck = await page.locator(
"//tr[contains(.,'Kittisak Wijitranon') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
await expect(employeeCheck).toContainText('Kittisak Wijitranon');
await expect(employeeCheck).toContainText(
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด',
);
console.log('ระบบทำการตรวจสอบการจ้างลูกจ้างถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างนรูปแบบใช้ที่อยู่แบบกำหนดเอง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(1000);
await page.click('id=btn-add');
await page.waitForTimeout(2000);
// ส่วนข้อมูลพื้นฐาน
await page.click('id=form-employee-select-employer-branch');
await page.waitForSelector('id=form-employee-select-employer-branch_0');
await page.click('id=form-employee-select-employer-branch_0');
await page.fill('id=form-employee-input-nrc-no', '2822022820222');
// ส่วนข้้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_1');
await page.click('id=form-employee-select-prefix-name_1');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'วรัญญา',
);
await page.fill('id=form-employee-input-last-name', 'สุขเกษม');
await page.fill('id=form-employee-input-first-name-en', 'Waranya');
await page.fill('id=form-employee-input-last-name-en', 'Sukkasem');
// วันเดิิอนปีเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1994']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='เม.ย.']");
await page.click("//div[@id='1994-04-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_4');
await page.click('id=form-employee-select-nationality_4');
// ส่วนที่อยู่
await page.click('id=form-employee-custom');
await page.fill(
'id=form-employee-input-address-no',
'89/15 หมู่บ้านเพชรทวี',
);
await page.fill(
"(//input[@id='form-employee-input-soi'])[1]",
'สุขุมวิท 55 ',
);
await page.fill(
"(//input[@id='form-employee-input-street'])[1]",
'สุขุมวิท',
);
await page.click('id=form-employee-select-district');
(await page.waitForSelector('id=form-employee-select-district_13'))
.scrollIntoViewIfNeeded;
await page.click('id=form-employee-select-district_13');
await page.click('id=form-employee-select-sub-district');
await page.waitForSelector('id=form-employee-select-sub-district_1');
await page.click('id=form-employee-select-sub-district_1');
await page.fill(
'id=form-employee-input-address-en',
'89/15 Phetthawee Village',
);
await page.fill(
"(//input[@id='form-employee-input-soi'])[2]",
'Sukhumvit 55',
);
await page.fill(
"(//input[@id='form-employee-input-street'])[2]",
'Sukhumvit',
);
await page.waitForTimeout(2000);
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
// -------------------- Tab ข้อมูลหนังสือเดินทาง ------------------------------
await page.waitForSelector(
'id=dialog-tab-customerEmployee.fileType.passport',
{
state: 'visible',
},
);
await page.click('id=dialog-tab-customerEmployee.fileType.passport', {
force: true,
});
await page.fill(
"(//input[@id='drawer-info-employee-input-passport-no'])[2]",
'VN220228',
);
await page.click(
"(//input[@id='drawer-info-employee-select-passport-country'])[2]",
);
await page.waitForSelector(
'id=drawer-info-employee-select-passport-country_4',
);
await page.click('id=drawer-info-employee-select-passport-country_4');
// วันหมดอายุหนังสือเดือนทาง
await page.waitForTimeout(1000);
await page.click(
"(//input[@id='drawer-info-employee-date-picker-passport-expire'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2032']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[@data-test='ส.ค.']");
await page.click("//div[@id='2032-08-10']/div[1]");
await page.waitForSelector("(//button[@type='submit'])[2]");
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
// -------------------- Tab ข้อมูล Visa ------------------------------------
await page.waitForSelector(
'id=dialog-tab-customerEmployee.form.group.visa',
{
state: 'visible',
},
);
await page.click('id=dialog-tab-customerEmployee.form.group.visa', {
force: true,
});
// ใช้ได้ถึงวันที่
await page.click(
"(//input[@id='drawer-info-employee-date-picker-visa-expire'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2032']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='ธ.ค.']");
await page.click("//div[@id='2032-12-04']/div[1]");
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const employeeCheck = await page.locator(
"//tr[contains(.,'Waranya Sukkasem') and contains (.,'1524428220420-00')]",
);
await expect(employeeCheck).toContainText('Waranya Sukkasem');
await expect(employeeCheck).toContainText('1524428220420-00');
console.log('ระบบทำการตรวจสอบการจ้างลูกจ้างถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,273 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
await page.waitForTimeout(2000);
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.waitForTimeout(2000);
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
const selectBranchError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const firstNameError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const lastNameError = await page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const firstNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
const lastNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[5]",
);
const brithdateError = await page.locator(
"(//div[@class='q-field__messages col']//div)[6]",
);
const genderError = await page.locator(
"(//div[@class='q-field__messages col']//div)[7]",
);
const nationalityError = await page.locator(
"(//div[@class='q-field__messages col']//div)[8]",
);
const addressError = await page.locator(
"(//div[@class='q-field__messages col']//div)[9]",
);
const provinceError = await page.locator(
"(//div[@class='q-field__messages col']//div)[10]",
);
const districtError = await page.locator(
"(//div[@class='q-field__messages col']//div)[11]",
);
const subdistrictError = await page.locator(
"(//div[@class='q-field__messages col']//div)[12]",
);
const addressEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[13]",
);
await expect(selectBranchError).toHaveText('Please select Branch.');
await expect(firstNameError).toHaveText('This field is required.');
await expect(lastNameError).toHaveText('This field is required.');
await expect(firstNameEngError).toHaveText('This field is required.');
await expect(lastNameEngError).toHaveText('This field is required.');
await expect(brithdateError).toHaveText('Please select Birth Date.');
await expect(genderError).toHaveText('This field is required.');
await expect(nationalityError).toHaveText('This field is required.');
await expect(addressError).toHaveText('This field is required.');
await expect(provinceError).toHaveText('Please select Province.');
await expect(districtError).toHaveText('Please select District.');
await expect(subdistrictError).toHaveText('Please select Sub-district.');
await expect(addressEngError).toHaveText('This field is required.');
console.log('ระบบทำการตรวจสอบการแจ้งเตือนเรียบร้อย');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('เพิ่มลูกจ้างในกรณีที่กรอกเลข N.R.C No. ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.fill('id=form-employee-input-nrc-no', '123');
await page.waitForTimeout(2000);
const numbernrc = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(numbernrc).toHaveText(
'Invalid value. Please enter 13 character',
);
console.log('ระบบทำการตรวจสอบการแจ้งเตือนเรียบร้อย');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
});
test('เพิ่มลูกจ้างในกรณีที่กรอกช่องชื่อนามสกุลภาษาอังกฤษไม่ถูกต้อง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.fill('id=form-employee-input-first-name-en', 'ชื่อ');
await page.fill('id=form-employee-input-last-name-en', 'นามสกุล');
await page.waitForTimeout(2000);
const firstNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const lastNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(firstNameEngError).toHaveText('Only letters are allowed');
await expect(lastNameEngError).toHaveText('Only letters are allowed');
console.log('ระบบทำการตรวจสอบการแจ้งเตือนเรียบร้อย');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างในกรณีที่เพิ่มข้อมูล Tab ข้อมูลหนังสือเดินทาง แต่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
// ส่วนข้อมูลพื้นฐาน
await page.click('id=form-employee-select-employer-branch');
await page.waitForSelector('id=form-employee-select-employer-branch_1');
await page.click('id=form-employee-select-employer-branch_1');
await page.fill('id=form-employee-input-nrc-no', '2822022820220');
// ส่วนข้้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'นราธิป',
);
await page.fill('id=form-employee-input-last-name', 'แสงรุ่ง');
await page.fill('id=form-employee-input-first-name-en', 'Narathip');
await page.fill('id=form-employee-input-last-name-en', 'Saengrung');
// วันเดิิอนปีเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1996']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='May']");
await page.click("//div[@id='1996-05-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_2');
await page.click('id=form-employee-select-nationality_2');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// -------------------- Tab ข้อมูลหนังสือเดินทาง ------------------------------
await page.waitForSelector(
'id=dialog-tab-customerEmployee.fileType.passport',
{
state: 'visible',
},
);
await page.click('id=dialog-tab-customerEmployee.fileType.passport', {
force: true,
});
await page.waitForSelector("(//button[@type='submit'])[2]");
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
const numberPassport = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const typeCountryPassport = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const typeLocationCountry = await page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
await expect(numberPassport).toHaveText('This field is required.');
await expect(typeCountryPassport).toHaveText(
'Please select Passport Issuing Country.',
);
await expect(typeLocationCountry).toHaveText('This field is required.');
console.log('ระบบทำการตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,271 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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.waitForTimeout(2000);
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
const selectBranchError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const firstNameError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const lastNameError = await page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const firstNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
const lastNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[5]",
);
const brithdateError = await page.locator(
"(//div[@class='q-field__messages col']//div)[6]",
);
const genderError = await page.locator(
"(//div[@class='q-field__messages col']//div)[7]",
);
const nationalityError = await page.locator(
"(//div[@class='q-field__messages col']//div)[8]",
);
const addressError = await page.locator(
"(//div[@class='q-field__messages col']//div)[9]",
);
const provinceError = await page.locator(
"(//div[@class='q-field__messages col']//div)[10]",
);
const districtError = await page.locator(
"(//div[@class='q-field__messages col']//div)[11]",
);
const subdistrictError = await page.locator(
"(//div[@class='q-field__messages col']//div)[12]",
);
const addressEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[13]",
);
await expect(selectBranchError).toHaveText('โปรดเลือกสาขา');
await expect(firstNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(lastNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(firstNameEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(lastNameEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(brithdateError).toHaveText('โปรดเลือกวันเดือนปีเกิด');
await expect(genderError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nationalityError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(addressError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(provinceError).toHaveText('โปรดเลือกจังหวัด');
await expect(districtError).toHaveText('โปรดเลือกเขต/อำเภอ');
await expect(subdistrictError).toHaveText('โปรดเลือกแขวง/ตำบล');
await expect(addressEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
console.log('ระบบทำการตรวจสอบการแจ้งเตือนเรียบร้อย');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('เพิ่มลูกจ้างในกรณีที่กรอกเลข N.R.C No. ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.fill('id=form-employee-input-nrc-no', '123');
await page.waitForTimeout(2000);
const numbernrc = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(numbernrc).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
console.log('ระบบทำการตรวจสอบการแจ้งเตือนเรียบร้อย');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
});
test('เพิ่มลูกจ้างในกรณีที่กรอกช่องชื่อนามสกุลภาษาอังกฤษไม่ถูกต้อง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.fill('id=form-employee-input-first-name-en', 'ชื่อ');
await page.fill('id=form-employee-input-last-name-en', 'นามสกุล');
await page.waitForTimeout(2000);
const firstNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const lastNameEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(firstNameEngError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
await expect(lastNameEngError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
console.log('ระบบทำการตรวจสอบการแจ้งเตือนเรียบร้อย');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างในกรณีที่เพิ่มข้อมูล Tab ข้อมูลหนังสือเดินทาง แต่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
// ส่วนข้อมูลพื้นฐาน
await page.click('id=form-employee-select-employer-branch');
await page.waitForSelector('id=form-employee-select-employer-branch_1');
await page.click('id=form-employee-select-employer-branch_1');
await page.fill('id=form-employee-input-nrc-no', '2822022820220');
// ส่วนข้้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'นราธิป',
);
await page.fill('id=form-employee-input-last-name', 'แสงรุ่ง');
await page.fill('id=form-employee-input-first-name-en', 'Narathip');
await page.fill('id=form-employee-input-last-name-en', 'Saengrung');
// วันเดิิอนปีเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1996']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='พ.ค.']");
await page.click("//div[@id='1996-05-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_2');
await page.click('id=form-employee-select-nationality_2');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// -------------------- Tab ข้อมูลหนังสือเดินทาง ------------------------------
await page.waitForSelector(
'id=dialog-tab-customerEmployee.fileType.passport',
{
state: 'visible',
},
);
await page.click('id=dialog-tab-customerEmployee.fileType.passport', {
force: true,
});
await page.waitForSelector("(//button[@type='submit'])[2]");
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
const numberPassport = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const typeCountryPassport = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const typeLocationCountry = await page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
await expect(numberPassport).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(typeCountryPassport).toHaveText(
'โปรดเลือกประเทศที่ออกหนังสือเดินทาง',
);
await expect(typeLocationCountry).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
console.log('ระบบทำการตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,105 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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 {
// กำหนดคำที่จะค้นหา
const searchDatas = [
'Kittisak',
'Sukkasem',
'กิตติศักดิ์ วิจิตรานนท์',
'Waranya Sukkasem',
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด',
'1524428220420-00',
];
for (const searchData of searchDatas) {
// พิมพ์คำที่ต้องการค้นหา
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
await page.waitForTimeout(2000);
// ดึงผลลัพฑ์การค้นหาทั้งหมด
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
const resultCount = await searchResults.count();
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
if (resultCount === 0) {
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
continue; // ข้ามคำค้นหาคำถัดไป
}
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
const searchResultTexts = await searchResults.allTextContents();
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
const allResultContainSearchData = searchResultTexts.every((result) =>
result.includes(searchData),
);
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
if (!allResultContainSearchData) {
console.error(
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
);
continue; // ข้ามไปคำค้นหาถัดไป
}
expect(allResultContainSearchData).toBe(true);
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,115 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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 {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.waitForTimeout(1000);
await page.click('id=select-status');
//รอให้ dropdown เปิด
await page.waitForSelector('id=select-status_1');
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,112 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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-eye-กิตติศักดิ์');
const fullNameEmployee = await page.locator(
"//span[text()='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบตรวจสอบรายละเอียดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click("(//button[@id='btn-info-close'])[2]");
await page.waitForTimeout(1000);
});
test('ทดสอบการดูรายละเอียดลูกจ้างโดยการคลิกเมนูย่อย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-กิตติศักดิ์');
await page.waitForSelector('id=btn-kebab-view-detail-กิตติศักดิ์');
await page.click('id=btn-kebab-view-detail-กิตติศักดิ์');
const fullNameEmployee = await page.locator(
"//span[text()='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบตรวจสอบรายละเอียดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click("(//button[@id='btn-info-close'])[2]");
await page.waitForTimeout(1000);
});
test('ทดสอบการดูรายละเอียดลูกจ้างในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const fullNameEmployee = await page.locator(
"//div[normalize-space(text())='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบทำการเปลี่ยนเป็นรูปแบบการ์ดแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(1000);
});

View file

@ -0,0 +1,93 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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-kebab-action-วรัญญา');
await page.waitForSelector('id=btn-kebab-edit-วรัญญา');
await page.click('id=btn-kebab-edit-วรัญญา');
await page.click(
"(//div[contains(@class,'q-field__append q-field__marginal')]//i)[3]",
);
await page.waitForSelector(
'id=drawer-info-employee-select-employer-branch_1',
);
await page.click('id=drawer-info-employee-select-employer-branch_1');
await page.fill(
"(//input[@id='drawer-info-employee-input-first-name'])[1]",
'พิชญา',
);
await page.fill('id=drawer-info-employee-input-last-name', 'วัฒนธนากุล');
await page.fill('id=drawer-info-employee-input-first-name-en', 'Pichaya');
await page.fill(
'id=drawer-info-employee-input-last-name-en',
'Watthanathanakul',
);
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(1000);
await page.click("(//button[@id='btn-info-close'])[2]");
const rowItemName = await page.locator(
"//tr[contains(.,'Pichaya Watthanathanakul') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
await expect(rowItemName).toContainText('Pichaya Watthanathanakul');
await expect(rowItemName).toContainText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
console.log('ระบบทำการแก้ไขลูกจ้างแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,125 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { it } from 'node: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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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.waitForTimeout(2000);
// ส่วนข้อมูลพื้นฐาน
await page.click('id=form-employee-select-employer-branch');
await page.waitForSelector('id=form-employee-select-employer-branch_1');
await page.click('id=form-employee-select-employer-branch_1');
await page.fill('id=form-employee-input-nrc-no', '2822022820228');
// ส่วนข้้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'ธนกร',
);
await page.fill('id=form-employee-input-last-name', 'ศรีสวัสดิ์');
await page.fill('id=form-employee-input-first-name-en', 'Thanakorn');
await page.fill('id=form-employee-input-last-name-en', 'Srisawat');
// วันเดิิอนปีเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1992']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='พ.ค.']");
await page.click("//div[@id='1992-05-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_2');
await page.click('id=form-employee-select-nationality_2');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('ทดสอบการลบลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
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 itemLocator = await page.locator(
"//tr[contains(.,'Thanakorn Srisawat') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
await expect(itemLocator).toBeHidden();
console.log('ระบบทำการลบลูกจ้างแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,124 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
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-kebab-action-กิตติศักดิ์');
await page.click('id=btn-kebab-status-กิตติศักดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'Kittisak Wijitranon') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-กิตติศักดิ์');
await page.click('id=btn-kebab-status-กิตติศักดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'Kittisak Wijitranon') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,612 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { sign } from 'crypto';
import { escape } from 'querystring';
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) {
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');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงลำดับที่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_0');
const column1Cells = page.locator("//th[contains(.,'ลำดับที่')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 1 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_0'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 1 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_1');
const column1Cells = page.locator("//th[contains(.,'ชื่อ')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 1 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_1'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 2 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 2 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลอายุ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_2');
const column1Cells = page.locator("//th[contains(.,'อายุ')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 3 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(false);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_2'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 3 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลสัญชาติ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_3');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_3');
const column1Cells = page.locator("//th[contains(.,'สัญชาติ')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 4 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_3'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 4 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลหมายเลขหนังสือเดินทาง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_4');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_4');
const column1Cells = page.locator(
"//th[contains(.,'หมายเลขหนังสือเดินทาง')]",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 5 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_4'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 5 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลวันหมดอายุหนังสือเดินทาง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_5');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_5');
const column1Cells = page.locator(
"//th[contains(.,'วันหมดอายุหนังสือเดินทาง')]",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 6 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 6 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_5'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 6 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 6 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลวันหมดอายุ visa', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_6');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_6');
const column1Cells = page.locator("//th[contains(.,'วันหมดอายุ visa')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 7 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 7 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_6'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 7 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 7 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลจะครบกำหนดในอีก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_7');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_7');
const column1Cells = page.locator("//th[contains(.,'จะครบกำหนดในอีก')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 8 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 8 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_7'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 8 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 8 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลสาขา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_8');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_8');
const column1Cells = page.locator("//th[contains(.,'สาขา')]");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 9 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 9 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//div[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_8'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 9 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 9 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,454 @@
import { test, expect, Page, errors } from '@playwright/test';
import { strictEqual } from 'assert';
import { writeFileSync } from 'fs';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
await page.click('id=row-table-cm372yq4r0043u3phfvz5l2dq');
await page.click('id=btn-add');
await page.waitForTimeout(2000);
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=dialog-select-prefix-name');
await page.waitForSelector('id=dialog-select-prefix-name_0');
await page.click('id=dialog-select-prefix-name_0');
await page.fill('id=dialog-input-first-name', 'ก้องภพ');
await page.fill('id=dialog-input-last-name', 'ทิพย์สุวรรณ');
await page.fill('id=dialog-input-first-name-en', 'Kongpop');
await page.fill('id=dialog-input-last-name-en', 'Tipsuwan');
await page.fill("(//input[@id='dialog-input-telephone'])[1]", '0886242202');
// วันเกิด
await page.click('id=dialog-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='2000']");
await page.click("//div[text()='2000']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='ก.พ.']");
await page.click("//div[text()='ก.พ.']");
await page.waitForSelector("//div[@id='2000-02-04']/div[1]");
await page.click("//div[@id='2000-02-04']/div[1]");
// ส่วนข้อมูลธุรกิจ
await page.click('id=employer-branch-select-business-type');
await page.waitForSelector('id=employer-branch-select-business-type_0');
await page.click('id=employer-branch-select-business-type_0');
await page.click('id=employer-branch-select-job-position');
await page.waitForSelector('id=employer-branch-select-job-position_0');
await page.click('id=employer-branch-select-job-position_0');
await page.fill(
'id=employer-branch-input-job-description',
'รายละเอียดงาน',
);
await page.fill(
"(//input[@id='employer-branch-input-pay-rate'])[1]",
'วันจ่ายเงินเดือน',
);
await page.fill(
"(//input[@id='employer-branch-input-pay-rate'])[2]",
'Pay day',
);
await page.fill(
"(//input[@id='employer-branch-input-pay-rate'])[3]",
'500',
);
// ส่วนผู้มีอำนาจลงนาม
await page.fill(
"(//input[@id='employer-branch-input-contact-name'])[1]",
'ก้องภพ ทิพย์สุวรรณ',
);
await page.fill(
"(//input[@id='employer-branch-input-contact-name'])[2]",
'Kongpop Tipsuwan',
);
// ส่วนที่อยู่นายจ้าง
await page.fill(
"(//input[@id='employer-branch-input-address'])[1]",
'22292282202',
);
await page.fill(
'id=employer-branch-input-address-no',
'45/9 หมู่บ้านสิริสุข',
);
await page.fill(
"(//input[@id='employer-branch-input-soi'])[1]",
'วิภาวดี 16',
);
await page.fill(
"(//input[@id='employer-branch-input-street'])[1]",
'วิภาวดีรังสิต ',
);
await page.click('id=employer-branch-select-province');
await page.waitForSelector('id=employer-branch-select-province_0');
await page.click('id=employer-branch-select-province_0');
// คลิก dropdown เพื่อเปิด
await page.click('id=employer-branch-select-district');
// กำหนดตัวเลือกที่ต้องการ
const targetOptionId = 'id=employer-branch-select-district_42'; // id ของตัวเลือกที่ต้องการ
let isVisible = false;
const maxScrollAttempts = 10; // จำนวนครั้งสูงสุดในการเลื่อน
let attempt = 0;
while (!isVisible && attempt < maxScrollAttempts) {
// ตรวจสอบว่า dropdown แสดงหรือไม่
const dropdown = page.locator('#employer-branch-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.click('id=employer-branch-select-sub-district');
await page.waitForSelector('id=employer-branch-select-sub-district_2');
await page.click('id=employer-branch-select-sub-district_2');
await page.fill(
'id=employer-branch-input-address-en',
'45/9 Sirisuk Village',
);
await page.fill(
"(//input[@id='employer-branch-input-soi'])[2]",
'Vibhavadi 16',
);
await page.fill(
"(//input[@id='employer-branch-input-street'])[2]",
'Vibhavadi Rangsit',
);
// ส่วนข้อมูลติดต่อ
await page.fill('id=dialog-input-contact-name', 'ก้องภพ ทิพย์สุวรรณ');
await page.fill('id=dialog-input-mail', 'kongpop@mail.com');
await page.fill("(//input[@id='dialog-input-telephone'])[2]", '0866224228');
await page.fill("(//input[@id='dialog-input-telephone'])[3]", '022014220');
await page.click('id=quotation-branch');
await page.keyboard.press('Escape');
await page.waitForTimeout(1000);
// กำหนดการคลิก dropdown หลายครั้งเพราะคลิกครั้งแรกแล้วไม่เจอ
let dropdownVisible = false;
const maxAttempts = 5; // จำนวนครั้งสูงสุดในการคลิก dropdown
let attemptCount = 0;
while (!dropdownVisible && attemptCount < maxAttempts) {
// คลิกเปิด dropdown
await page.click('id=quotation-branch');
// ตรวจสอบว่าตัวเลือกภายใน dropdown ถูกแสดงแล้วหรือยัง
try {
await page.waitForSelector('id=quotation-branch_1', {
state: 'visible',
timeout: 2000, // รอ 2 วินาทีในแต่ละรอบ
});
dropdownVisible = true; // ถ้าตัวเลือกถูกแสดงแล้ว เปลี่ยนสถานะเป็น true
} catch (error) {
console.warn(
`ไม่เจอ dropdown ในรอบที่ ${attemptCount + 1}, ลองใหม่อีกครั้ง`,
);
}
attemptCount++;
}
if (dropdownVisible) {
// เมื่อ dropdown แสดงผลแล้ว คลิกตัวเลือกที่ต้องการ
await page.click('id=quotation-branch_1');
} else {
console.error('ไม่สามารถแสดง dropdown ได้หลังจากพยายามหลายครั้ง');
}
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-form-close', { state: 'visible' });
await page.click('id=btn-form-close', { force: true });
const fullNameSubBranch = await page.locator(
"//tr[contains(.,'ก้องภพ ทิพย์สุวรรณ') and contains (.,'0')]",
);
await expect(fullNameSubBranch).toContainText('ก้องภพ ทิพย์สุวรรณ');
await expect(fullNameSubBranch).toContainText('0');
console.log('ทดสอบการสร้างสาขาในบุคคลธรรมดาสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างภายในนายจ้างบุคคลธรรมดาในกรณีที่ใช้ที่อยู่ของนายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector(
"(//button[@id='btn-show-employee-ยศพัฒน์ ธนากานต์'])[3]",
);
await page.click("(//button[@id='btn-show-employee-ยศพัฒน์ ธนากานต์'])[3]");
await page.waitForSelector('id=ก้องภพ-btn-add-employee');
await page.click('id=ก้องภพ-btn-add-employee');
// ส่วนข้อมูลพื้นฐาน
await page.fill('id=form-employee-input-nrc-no', '2202282262282');
// ส่วนข้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'ปริญญา',
);
await page.fill('id=form-employee-input-last-name', 'อินทรวิชัย');
await page.fill('id=form-employee-input-first-name-en', 'Parinya');
await page.fill('id=form-employee-input-last-name-en', 'Intaravichai');
//วันเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='1994']");
await page.click("//div[text()='1994']");
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='พ.ค.']");
await page.click("//div[text()='พ.ค.']");
await page.waitForSelector("//div[@id='1994-05-06']/div[1]");
await page.click("//div[@id='1994-05-06']/div[1]");
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_2');
await page.click('id=form-employee-select-nationality_2');
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const employeeCheck = await page.locator(
"(//tr[@id='row-table-Parinya'])[2]",
);
console.log('แสดงข้อความ :', employeeCheck);
await expect(employeeCheck).toHaveText(
'1Parinya Intaravichai ปริญญา อินทรวิชัย30 ปี 6 เดือน 18 วัน ลาว---- ',
);
console.log('ระบบสามารถสร้างลูกจ้างได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างภายในนายจ้างบุคคลธรรมดาในกรณีที่ใช้ที่อยู่แบบกำหนดเอง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=ก้องภพ-btn-add-employee');
await page.click('id=ก้องภพ-btn-add-employee');
// ส่วนข้อมูลพื้นฐาน
await page.fill('id=form-employee-input-nrc-no', '2202282262284');
// ส่วนข้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_1');
await page.click('id=form-employee-select-prefix-name_1');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'จิราพร',
);
await page.fill('id=form-employee-input-last-name', 'นนทรี');
await page.fill('id=form-employee-input-first-name-en', 'Jiraporn');
await page.fill('id=form-employee-input-last-name-en', 'Nontree');
//วันเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='1992']");
await page.click("//div[text()='1992']");
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='พ.ค.']");
await page.click("//div[text()='พ.ค.']");
await page.waitForSelector("//div[@id='1992-05-06']/div[1]");
await page.click("//div[@id='1992-05-06']/div[1]");
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_4');
await page.click('id=form-employee-select-nationality_4');
// ส่วนข้อมูลที่อยู่
await page.waitForSelector('id=form-employee-custom');
await page.click('id=form-employee-custom');
await page.fill(
'id=form-employee-input-address-no',
'90/12 หมู่บ้านภูพิมาน',
);
await page.fill("(//input[@id='form-employee-input-moo'])[1]", '4');
await page.fill("(//input[@id='form-employee-input-soi'])[1]", 'ศรีตรัง');
await page.fill(
"(//input[@id='form-employee-input-street'])[1]",
'นครศรี-ทุ่งสง',
);
await page.click('id=form-employee-select-province');
// กำหนดตัวเลือกที่ต้องการ
const targetOptionId = 'id=form-employee-select-province_38'; // id ของตัวเลือกที่ต้องการ
let isVisible = false;
const maxScrollAttempts = 10; // จำนวนครั้งสูงสุดในการเลื่อน
let attempt = 0;
while (!isVisible && attempt < maxScrollAttempts) {
// ตรวจสอบว่า dropdown แสดงหรือไม่
const dropdown = page.locator('#form-employee-select-province_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.click('id=form-employee-select-district');
await page.waitForSelector('id=form-employee-select-district_0');
await page.click('id=form-employee-select-district_0');
await page.click('id=form-employee-select-sub-district');
await page.waitForSelector('id=form-employee-select-sub-district_0');
await page.click('id=form-employee-select-sub-district_0');
await page.fill(
'id=form-employee-input-address-en',
'90/12 Phupiman Village',
);
await page.fill("(//input[@id='form-employee-input-moo'])[2]", '4');
await page.fill("(//input[@id='form-employee-input-soi'])[2]", 'Sri Trang');
await page.fill(
"(//input[@id='form-employee-input-street'])[2]",
'Nakhon Si-Thung Song',
);
// บันทึกการสร้างลูกจ้าง
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const employeeCheck = await page.locator(
"(//tr[@id='row-table-Jiraporn'])[2]",
);
console.log('แสดงข้อความ :', employeeCheck);
await expect(employeeCheck).toHaveText(
'2Jiraporn Nontree จิราพร นนทรี32 ปี 6 เดือน 18 วัน เวียดนาม---- ',
);
console.log('ระบบสามารถสร้างลูกจ้างได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,292 @@
import { test, expect, Page, errors } from '@playwright/test';
import { strictEqual } from 'assert';
import { error } from 'console';
import { writeFileSync } from 'fs';
import { errorMonitor } from 'stream';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
//สร้าง Function สำหรับ Login
async function login(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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
await page.click('id=row-table-cm372yq4r0043u3phfvz5l2dq');
// ถ้าขั้นตอนทั้งหมดสำเร็จ
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('ข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มสาขาในนายจ้างบุคคลธรรมดาในกรณีที่ไม่กรอกข้อมูล', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
//ตรวจสอบข้อผิดพลาดที่ต้องแสดง
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: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[10]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[11]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[12]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[13]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[14]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[15]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[16]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[17]",
message: 'โปรดเลือกแขวง/ตำบล',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนเรียบร้อยแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// ถ้าล้มเหลวให้ทเครื่องหมายว่าล้มเหลว
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มสาขาในนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนเกี่ยวกับ', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.fill('id=dialog-input-first-name', 'ชื่อ');
await page.fill('id=dialog-input-last-name', 'นามสกุล');
await page.fill('id=dialog-input-first-name-en', 'Name');
await page.fill('id=dialog-input-last-name-en', 'surname');
// วันเดือนปีเกิด
await page.click('id=dialog-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='2006']");
await page.click("//div[text()='2006']");
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='มิ.ย.']");
await page.click("//div[text()='มิ.ย.']");
await page.waitForSelector("//div[@id='2006-06-24']/div[1]");
await page.click("//div[@id='2006-06-24']/div[1]");
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
//ตรวจสอบข้อผิดพลาดที่ต้องแสดง
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: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[10]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[11]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[12]",
message: 'โปรดเลือกแขวง/ตำบล',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนเรียบร้อยแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// ถ้าล้มเหลว
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มสาขาในนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลชื่อและนามสกุลภาษาอังกฤษไม่ตรงรูปแบบ', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
await page.fill('id=dialog-input-first-name-en', 'ชื่อ');
await page.fill('id=dialog-input-last-name-en', 'นามสกุล');
await page.waitForTimeout(2000);
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
// ถ้าล้มเหลว
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,470 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
await page.click('id=row-table-cm38dee6s000dip2c6vye04bw');
await page.click('id=btn-add');
await page.waitForTimeout(2000);
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.fill(
'id=input-register-name',
'บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด',
);
await page.fill(
'id=input-register-name-en',
'Peak World Consulting Co., Ltd.',
);
await page.fill('id=input-legal-person-no', 'ธนกฤต ศรีประเสริฐ');
await page.fill('id=input-legal-person-code', '2202264280648');
//จดทะเบียนเมื่อ
await page.click('id=dialog-input-register-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='2020']");
await page.click("//div[text()='2020']");
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='ส.ค.']");
await page.click("//div[text()='ส.ค.']");
await page.waitForSelector("//div[@id='2020-08-06']/div[1]");
await page.click("//div[@id='2020-08-06']/div[1]");
await page.fill('id=input-authorized-capital', '10000000');
await page.fill('id=input-telephone-no', '022066060');
// ส่วนข้อมูลธุรกิจ
await page.click('id=employer-branch-select-business-type');
await page.waitForSelector('id=employer-branch-select-business-type_3');
await page.click('id=employer-branch-select-business-type_3');
await page.click('id=employer-branch-select-job-position');
await page.waitForSelector('id=employer-branch-select-job-position_0');
await page.click('id=employer-branch-select-job-position_0');
await page.fill(
'id=employer-branch-input-job-description',
'รายละเอียดงาน',
);
await page.fill(
"(//input[@id='employer-branch-input-pay-rate'])[1]",
'วันที่จ่ายเงินเดือน',
);
await page.fill(
"(//input[@id='employer-branch-input-pay-rate'])[2]",
'Pay day',
);
await page.fill(
"(//input[@id='employer-branch-input-pay-rate'])[3]",
'550',
);
// ส่วนผู้มีอำนาจลงนาม
await page.fill(
"(//input[@id='employer-branch-input-contact-name'])[1]",
'ธนกฤต ศรีประเสริฐ',
);
await page.fill(
"(//input[@id='employer-branch-input-contact-name'])[2]",
'Thanakrit Sriprasert',
);
// ส่วนที่อยู่นายจ้าง
await page.fill(
"(//input[@id='employer-branch-input-address'])[1]",
'20264282028',
);
await page.fill(
'id=employer-branch-input-address-no',
'99/12 อาคารซัมเมอร์ฮับ ชั้น 8',
);
await page.fill(
"(//input[@id='employer-branch-input-soi'])[1]",
'สุขุมวิท 23',
);
await page.fill(
"(//input[@id='employer-branch-input-street'])[1]",
'สุขุมวิท',
);
await page.click('id=employer-branch-select-province');
await page.waitForSelector('id=employer-branch-select-province_0');
await page.click('id=employer-branch-select-province_0');
// คลิก dropdown เพื่อเปิด
await page.click('id=employer-branch-select-district');
// กำหนดตัวเลือกที่ต้องการ
const targetOptionId = 'id=employer-branch-select-district_13'; // id ของตัวเลือกที่ต้องการ
let isVisible = false;
const maxScrollAttempts = 10; // จำนวนครั้งสูงสุดในการเลื่อน
let attempt = 0;
while (!isVisible && attempt < maxScrollAttempts) {
// ตรวจสอบว่า dropdown แสดงหรือไม่
const dropdown = page.locator('#employer-branch-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.click('id=employer-branch-select-sub-district');
await page.waitForSelector('id=employer-branch-select-sub-district_0');
await page.click('id=employer-branch-select-sub-district_0');
await page.fill(
'id=employer-branch-input-address-en',
'99/12 Summer Hub Building, 8th Floor',
);
await page.fill(
"(//input[@id='employer-branch-input-soi'])[2]",
'Sukhumvit 23',
);
await page.fill(
"(//input[@id='employer-branch-input-street'])[2]",
'Sukhumvit',
);
// ส่วนข้อมูลติดต่อ
await page.fill('id=dialog-input-contact-name', 'ธนกฤต ศรีประเสริฐ');
await page.fill('id=dialog-input-mail', 'peakworld@support.com');
await page.fill("(//input[@id='dialog-input-telephone'])[1]", '0864462828');
await page.fill("(//input[@id='dialog-input-telephone'])[2]", '022066060');
// การเลือก Dropdown โดยการวนลูป เพราะว่าหลังจากคลิก Dropdown ครั้งแรกแล้วข้อมูลที่ให้เลือกใน Dropdown ไม่แสดง
// กำหนดการคลิก dropdown หลายครั้งเพราะคลิกครั้งแรกแล้วไม่เจอ
let dropdownVisible = false;
const maxAttempts = 5; // จำนวนครั้งสูงสุดในการคลิก dropdown
let attemptCount = 0;
while (!dropdownVisible && attemptCount < maxAttempts) {
// คลิกเปิด dropdown
await page.click('id=quotation-branch');
// ตรวจสอบว่าตัวเลือกภายใน dropdown ถูกแสดงแล้วหรือยัง
try {
await page.waitForSelector('id=quotation-branch_0', {
state: 'visible',
timeout: 1000, // รอ 1 วินาทีในแต่ละรอบ
});
dropdownVisible = true; // ถ้าตัวเลือกถูกแสดงแล้ว เปลี่ยนสถานะเป็น true
} catch (error) {
console.warn(
`ไม่เจอ dropdown ในรอบที่ ${attemptCount + 1}, ลองใหม่อีกครั้ง`,
);
}
attemptCount++;
}
if (dropdownVisible) {
// เมื่อ dropdown แสดงผลแล้ว คลิกตัวเลือกที่ต้องการ
await page.click('id=quotation-branch_0');
} else {
console.error('ไม่สามารถแสดง dropdown ได้หลังจากพยายามหลายครั้ง');
}
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const subBranchCheck = await page.locator(
"//tr[contains(.,'บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด') and contains (.,'0')]",
);
await expect(subBranchCheck).toContainText(
'บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด',
);
await expect(subBranchCheck).toContainText('0');
console.log('ระบบทำการสร้างสาขาในนายจ้างนิติบุคคลแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างภายในนายจ้างนิติบุคคลในกรณีที่ใช้ที่อยู่ของนายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector(
"(//button[@id='btn-show-employee-บริษัท เอเชียเทค ซิสเต็มส์ จำกัด '])[2]",
);
await page.click(
"(//button[@id='btn-show-employee-บริษัท เอเชียเทค ซิสเต็มส์ จำกัด '])[2]",
);
await page.waitForSelector(
'id=บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด-btn-add-employee',
);
await page.click('id=บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด-btn-add-employee');
// ส่วนข้อมูลพื้นฐาน
await page.fill('id=form-employee-input-nrc-no', '2202282262260');
// ส่วนข้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'ณัฐวุฒิ',
);
await page.fill('id=form-employee-input-last-name', 'วงศ์เจริญ');
await page.fill('id=form-employee-input-first-name-en', 'Nattawut');
await page.fill('id=form-employee-input-last-name-en', 'Wongcharoen');
//วันเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='1990']");
await page.click("//div[text()='1990']");
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='พ.ค.']");
await page.click("//div[text()='พ.ค.']");
await page.waitForSelector("//div[@id='1990-05-10']/div[1]");
await page.click("//div[@id='1990-05-10']/div[1]");
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_4');
await page.click('id=form-employee-select-nationality_4');
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const employeeCheck = await page.locator(
"(//tr[@id='row-table-Nattawut'])[2]",
);
console.log('แสดงข้อความ :', employeeCheck);
await expect(employeeCheck).toHaveText(
'1Nattawut Wongcharoen ณัฐวุฒิ วงศ์เจริญ34 ปี 6 เดือน 15 วัน เวียดนาม---- ',
);
console.log('ระบบสามารถสร้างลูกจ้างได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการสร้างลูกจ้างภายในนายจ้างนิติบุคคลในกรณีที่ใช้ที่อยู่แบบกำหนดเอง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector(
'id=บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด-btn-add-employee',
);
await page.click('id=บริษัท พีคเวิลด์ คอนซัลติ้ง จำกัด-btn-add-employee');
// ส่วนข้อมูลพื้นฐาน
await page.fill('id=form-employee-input-nrc-no', '2202282262262');
// ส่วนข้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_1');
await page.click('id=form-employee-select-prefix-name_1');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'พิชชา',
);
await page.fill('id=form-employee-input-last-name', 'สุวรรณภา');
await page.fill('id=form-employee-input-first-name-en', 'Pitcha');
await page.fill('id=form-employee-input-last-name-en', 'Suwannapha');
//วันเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.waitForSelector("//div[text()='1999']");
await page.click("//div[text()='1999']");
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[1]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.waitForSelector("//div[text()='ธ.ค.']");
await page.click("//div[text()='ธ.ค.']");
await page.waitForSelector("//div[@id='1999-12-06']/div[1]");
await page.click("//div[@id='1999-12-06']/div[1]");
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_6');
await page.click('id=form-employee-select-nationality_6');
// ส่วนข้อมูลที่อยู่
await page.waitForSelector('id=form-employee-custom');
await page.click('id=form-employee-custom');
await page.fill(
'id=form-employee-input-address-no',
'88/14 หมู่บ้านลักขณา',
);
await page.fill("(//input[@id='form-employee-input-moo'])[1]", '7');
await page.fill("(//input[@id='form-employee-input-soi'])[1]", 'เจริญสุข');
await page.fill(
"(//input[@id='form-employee-input-street'])[1]",
'ร้อยเอ็ด-กาฬสินธุ์',
);
await page.click('id=form-employee-select-province');
// กำหนดตัวเลือกที่ต้องการ
const targetOptionId = 'id=form-employee-select-province_23'; // id ของตัวเลือกที่ต้องการ
let isVisible = false;
const maxScrollAttempts = 10; // จำนวนครั้งสูงสุดในการเลื่อน
let attempt = 0;
while (!isVisible && attempt < maxScrollAttempts) {
// ตรวจสอบว่า dropdown แสดงหรือไม่
const dropdown = page.locator('#form-employee-select-province_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.click('id=form-employee-select-district');
await page.waitForSelector('id=form-employee-select-district_9');
await page.click('id=form-employee-select-district_9');
await page.click('id=form-employee-select-sub-district');
await page.waitForSelector('id=form-employee-select-sub-district_11');
await page.click('id=form-employee-select-sub-district_11');
await page.fill(
'id=form-employee-input-address-en',
'88/14 Lakkana Village',
);
await page.fill("(//input[@id='form-employee-input-moo'])[2]", '7');
await page.fill(
"(//input[@id='form-employee-input-soi'])[2]",
'Charoen Suk',
);
await page.fill(
"(//input[@id='form-employee-input-street'])[2]",
'Roi Et-Kalasin',
);
// บันทึกการสร้างลูกจ้าง
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-form-close');
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
const employeeCheck = await page.locator(
"(//tr[@id='row-table-Pitcha'])[2]",
);
console.log('แสดงข้อความ :', employeeCheck);
await expect(employeeCheck).toHaveText(
'2Pitcha Suwannapha พิชชา สุวรรณภา24 ปี 11 เดือน 18 วัน จีน---- ',
);
console.log('ระบบสามารถสร้างลูกจ้างได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,94 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
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("(//i[@aria-hidden='false'])[2]");
// await page.click("(//input[@id='input-source-nationality'])[2]");
// await page.click(
// "//span[normalize-space(text())='บริษัท คาโมมายด์ จำกัด']",
// );
await page.fill("(//input[@id='input-name'])[2]", 'ประกัน');
await page.fill("(//textarea[@id='input-detail'])[2]", 'รายละเอียดประกัน');
await page.fill("(//textarea[@id='input-remark'])[2]", 'หมายเหตุประกัน');
// บันทึกการสร้างกลุ่มสินค้นและบริการ
await page.click('id=btn-info-basic-save');
// ตรวจสอบหลังทำการสร้างกลุ่มสินค้าและบริการ
const newProductAndServiceLocator = page.locator(
"//div[normalize-space(text())='ประกัน']",
);
await newProductAndServiceLocator.waitFor({ state: 'visible' });
// ดึงข้อความให้ตรงจาก XPath
const newProductAndServiceName =
await newProductAndServiceLocator.textContent();
// ตรวจสอบความถูกต้องหลังทำการสร้างกลุ่มสินค้าและบริการ
if (newProductAndServiceName !== null) {
const trimmedName = newProductAndServiceName.trim();
expect(trimmedName).toBe('ประกัน');
console.log('การตรวจสอบสำเร็จ : ถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึก');
}
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,75 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
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.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
const nameProductGroupandService = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(nameProductGroupandService).toHaveText(
'This field is required.',
);
console.log('ระบบทำการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,69 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
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.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
const nameProductGroupandService = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(nameProductGroupandService).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
console.log('ระบบทำการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,96 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
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.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-สินค้าและบริการ-ประกัน');
await page.click('id=btn-add');
// ส่วนข้อมูลพื้นฐาน
await page.click("(//input[@id='select-br-id'])[1]");
await page.waitForSelector('id=select-br-id_0');
await page.click('id=select-br-id_0');
await page.fill(
"(//input[@id='input-name'])[2]",
'ชื่อกลุ่มสินค้าและบริการ',
);
await page.click("(//input[@id='select-br-id'])[2]");
await page.waitForSelector('id=select-br-id_0');
await page.click('id=select-br-id_0');
// ส่วนข้อมูลราคา
await page.click("(//div[@role='listitem'])[2]");
await page.fill('id=input-price', '2000');
await page.fill('id=input-agent-price', '2000');
await page.fill('id=input-service-charge', '2000');
// ส่วนข้อมูลเอกสาร
await page.click('id=btn-info-basic-save');
const productCheck = await page.locator(
"//tr[contains(.,'ชื่อกลุ่มสินค้าและบริการ') and contains (.,'฿2,000.00')]",
);
await expect(productCheck).toContainText('ชื่อกลุ่มสินค้าและบริการ');
await expect(productCheck).toContainText('฿2,000.00');
console.log('ระบบทำการสร้างสินค้าถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,87 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
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.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
await page.waitForSelector('id=tree-enter-Products and Services-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-Products and Services-ประกัน');
await page.click('id=btn-add');
await page.click('id=btn-info-basic-save');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const ProduceandSeviceCodeError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameProduceandSeviceError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(ProduceandSeviceCodeError).toHaveText(
'This field is required.',
);
await expect(nameProduceandSeviceError).toHaveText(
'This field is required.',
);
console.log('ระบบแสดงการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,82 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
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.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-สินค้าและบริการ-ประกัน');
await page.click('id=btn-add');
await page.click('id=btn-info-basic-save');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const ProduceandSeviceCodeError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameProduceandSeviceError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(ProduceandSeviceCodeError).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
await expect(nameProduceandSeviceError).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
console.log('ระบบแสดงการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,108 @@
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) {
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');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
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.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-แพ็คเกจ-ประกัน');
await page.click('id=btn-add');
// ส่วนข้อมูลแพ็คเกจ
await page.fill('id=input-service-code', 'MOU');
await page.fill('id=input-service-name', 'ประกันภัยแบบกลุ่ม');
await page.fill('id=input-service-description', 'รายละเอียดประภัยแบบกลุ่ม');
// ส่วนข้อมูลงาน
await page.click("(//div[@role='listitem']//div)[2]");
await page.waitForSelector("(//button[@id='btn-add-work'])[1]");
await page.click("(//button[@id='btn-add-work'])[1]");
// เพิ่มชื่องาน
await page.click("//div[@for='select-work-name-1']");
await page.waitForSelector("//button[contains(.,'จัดการ')]");
await page.click("//button[contains(.,'จัดการ')]");
await page.waitForSelector("//span[normalize-space(text())='เพิ่มงาน']");
await page.click("//span[normalize-space(text())='เพิ่มงาน']");
await page.fill('id=input-work-name-2', 'อักคคีภัย');
await page.waitForSelector('id=btn-save-work-name');
await page.click('id=btn-save-work-name');
await page.click("(//button[@id='btn-form-close'])[2]");
await page.waitForSelector("//div[@for='select-work-name-1']");
await page.click("//div[@for='select-work-name-1']");
await page.waitForSelector("//div[normalize-space(text())='อัคคีภัย']");
await page.click("//div[normalize-space(text())='อัคคีภัย']");
// เพิ่มสินค้า
await page.click("(//button[@id='btn-add-work-product'])[2]");
await page.waitForSelector("//div[text()='ชื่อกลุ่มสินค้าและบริการ']");
await page.click("//div[text()='ชื่อกลุ่มสินค้าและบริการ']");
await page.click('id=btn-form-submit');
// ขั้นตอนการทำงาน
await page.click("(//button[@id='btn-add-work-product']//span)[2]");
await page.click('id=select-workflow');
const propertiesServiceRecordName = page.locator(
"//span[normalize-space(text())='บันทึกบริการ_Name']",
);
expect(propertiesServiceRecordName).toHaveText('บันทึกบริการ_Name');
console.log(propertiesServiceRecordName, 'เลือกdropdown แล้ว');
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,77 @@
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) {
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');
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);
});

View file

@ -0,0 +1,194 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual, throws } from 'assert';
import { error, log } from 'console';
import { date, is } from 'quasar';
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) {
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');
await page.click('id=menu-icon-product-service');
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-eye-ประกัน');
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
const detailTitle = page.locator("//span[text()='ประกัน']");
// ตรวจสอบความถูกต้องของชื่อกลุ่มสินค้าและบริการ
await expect(detailTitle).toHaveText('ประกัน');
console.log('ตรวจสอบข้อมูลกลุ่มสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('ดูรายละเอียดกลุ่มสินค้าและบริการ ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประกัน');
await page.click('id=btn-kebab-view-detail-ประกัน');
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
const detailTitle = page.locator("//span[text()='ประกัน']");
// ตรวจสอบความถูกต้องของชื่อกลุ่มสินค้าและบริการ
await expect(detailTitle).toHaveText('ประกัน');
console.log('ตรวจสอบข้อมูลกลุ่มสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('ดูรายละเอียดประเภทของสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-ประเภท-ประกัน');
await page.click('id=btn-eye-ประกันภัยแบบกลุ่ม');
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
const detailTitleType = page.locator(
"//span[normalize-space(text())='ประกันภัยแบบกลุ่ม']",
);
// ตรวจสอบความถูกต้องของชื่อประเภทสินค้าและบริการ
await expect(detailTitleType).toHaveText('ประกันภัยแบบกลุ่ม');
console.log('ตรวจสอบข้อมูลประเภทของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ดูรายละเอียดประเภทของสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-ประเภท-ประกัน');
await page.click('id=btn-kebab-action-ประกันภัยแบบกลุ่ม');
await page.click('id=btn-kebab-view-detail-ประกันภัยแบบกลุ่ม');
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
const detailTitleType = page.locator(
"//span[normalize-space(text())='ประกันภัยแบบกลุ่ม']",
);
// ตรวจสอบความถูกต้องของชื่อประเภทสินค้าและบริการ
await expect(detailTitleType).toHaveText('ประกันภัยแบบกลุ่ม');
console.log('ตรวจสอบข้อมูลประเภทของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ดูรายละเอียดสินค้าและบริการของสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
await page.click('id=btn-eye-ประเภทกลุ่ม');
// กำหนดค่าเพื่อตรวจสอบความถูกต้อง
const detailTitleType = page.locator(
"//span[normalize-space(text())='ประเภทกลุ่ม']",
);
// ตรวจสอบความถูกต้องของชื่อสินค้าและบริการ
await expect(detailTitleType).toHaveText('ประเภทกลุ่ม');
console.log('ตรวจสอบข้อมูลสินค้าและบริการของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ดูรายละเอียดสินค้าและบริการของสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
await page.click('id=btn-kebab-action-ประเภทกลุ่ม');
await page.click('id=btn-kebab-view-detail-ประเภทกลุ่ม');
// กำหนดค่าเพื่อตรวจสอบความถูกต้อง
const detailTitleType = page.locator(
"//span[normalize-space(text())='ประเภทกลุ่ม']",
);
// ตรวจสอบความถูกต้องของชื่อสินค้าและบริการ
await expect(detailTitleType).toHaveText('ประเภทกลุ่ม');
console.log('ตรวจสอบข้อมูลสินค้าและบริการของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});

View file

@ -0,0 +1,136 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual, throws } from 'assert';
import { error, log } from 'console';
import { date, is } from 'quasar';
import { Card } from 'react-bootstrap';
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) {
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');
await page.click('id=menu-icon-product-service');
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-kebab-action-ประกัน');
await page.click('id=btn-kebab-edit-ประกัน');
await page.fill('id=input-name', 'ประกันทั้งหมด');
await page.click('id=btn-info-basic-save');
const detailTitleProductName = await page.locator(
"//div[normalize-space(text())='ประกันทั้งหมด']",
);
expect(detailTitleProductName).toHaveText('ประกันทั้งหมด');
console.log(
'การตรวจสอบการแก้ไขชื่อกลุ่มสินค้าและบริการถูกต้อง',
detailTitleProductName,
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการแก้ไขประเภทสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
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-ประเภท-ประกันทั้งหมด');
await page.click('id=btn-kebab-action-ประกันภัยแบบกลุ่ม');
await page.click('id=btn-kebab-edit-ประกันภัยแบบกลุ่ม');
await page.waitForSelector('id=input-service-name');
await page.fill('id=input-service-name', 'ประกันชีวิต');
await page.click("(//button[@id='btn-info-basic-save'])[2]");
// กำหนดค่าเพื่อตรวจสอบความถูกต้องของชื่อ
const detailTitleTypeProduct = await page.locator(
"//div[normalize-space(text())='ประกันชีวิต']",
);
// ตรวจสอบความถูกต้องของชื่อ
expect(detailTitleTypeProduct).toHaveText('ประกันชีวิต');
console.log('การตรวจสอบการแก้ไขชื่อประเภทสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการแก้ไขสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-สินค้าและบริการ-ประกันทั้งหมด', {
state: 'visible',
});
await page.click('id=tree-enter-สินค้าและบริการ-ประกันทั้งหมด');
await page.click('id=btn-kebab-action-ประเภทกลุ่ม');
await page.click('id=btn-kebab-edit-ประเภทกลุ่ม');
await page.waitForSelector("(//input[@id='input-name'])[2]");
await page.fill("(//input[@id='input-name'])[2]", 'ประเภทบุคคล');
await page.click("(//button[@id='btn-info-basic-save'])[2]");
await page.waitForSelector("//div[normalize-space(text())='ประเภทบุคคล']");
const detailNameProduct = await page.locator(
"//div[normalize-space(text())='ประเภทบุคคล']",
);
expect(detailNameProduct).toHaveText('ประเภทบุคคล');
console.log('การตรวจสอบการแก้ไขชื่อสินค้าและบริการถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,112 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual, throws } from 'assert';
import { error, log } from 'console';
import { date, is } from 'quasar';
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) {
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');
// คลิกเมนูเพื่อเข้าสู่หน้าสินค้าและบริการ
await page.click('id=menu-icon-product-service');
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 {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,358 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { watchFile } from 'fs';
import { waitForDebugger } from 'inspector';
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) {
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');
// คลิกเมนูเพื่อเข้าสู่หน้าสินค้าและบริการ
await page.click('id=menu-icon-product-service');
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 {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 1
await page.click('id=select-field_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_0');
const column1Cells = page.locator("//th[normalize-space(text())='ลำดับ']");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 1 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 1
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_0'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 1 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 1 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 2
await page.click('id=select-field_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_1');
const column1Cells = page.locator("//th[normalize-space(text())='ชื่อ']");
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 2 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 2 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 2
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_1'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 2 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 2 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลรายละเอียด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 3
await page.click('id=select-field_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_2');
const column1Cells = page.locator(
"//th[normalize-space(text())='รายละเอียด']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 3 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 3
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_2'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 3 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 3 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลหมายเหตุ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 4
await page.click('id=select-field_3');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_3');
const column1Cells = page.locator(
"//th[normalize-space(text())='หมายเหตุ']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 4 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 4
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_3'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 4 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 4 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลสร้างเมื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อปิดคอลัมน์ที่ 5
await page.click('id=select-field_4');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์ถูกซ่อน
const column1 = page.locator('id=select-field_4');
const column1Cells = page.locator(
"//th[normalize-space(text())='สร้างเมื่อ']",
);
const isColumn1Hidden = await column1.evaluate(
(el) => window.getComputedStyle(el).display === 'none',
);
console.log('คอลัมน์ที่ 5 ซ่อนอยู่:', isColumn1Hidden); // เช็ค
const areCellsHidden = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display === 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 ซ่อนอยู่:', areCellsHidden); // เช็ค
expect(isColumn1Hidden).toBe(false);
expect(areCellsHidden).toBe(true);
// คลิกอีกครั้งเพื่อเปิดคอลัมน์ที่ 5
await page.keyboard.press('Escape');
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
await page.click('id=select-field_4'); // คลิกเพื่อเปิดคอลัมน์
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าคอลัมน์แสดงอยู่
const isColumn1Visible = await column1.evaluate(
(el) => window.getComputedStyle(el).display !== 'none',
);
console.log('คอลัมน์ที่ 5 แสดงอยู่:', isColumn1Visible); // เช็ค
const areCellsVisible = await column1Cells.evaluateAll((cells) =>
cells.every((cell) => window.getComputedStyle(cell).display !== 'none'),
);
console.log('เซลล์ในคอลัมน์ที่ 5 แสดงอยู่:', areCellsVisible); // เช็ค
expect(isColumn1Visible).toBe(true);
expect(areCellsVisible).toBe(true);
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,282 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
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) {
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');
await page.click('id=menu-icon-product-service');
await page.click('id=tree-enter-ประกันทั้งหมด');
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-kebab-action-ประเภทบุคคล');
await page.click('id=btn-kebab-status-ประเภทบุคคล', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='ประเภทบุคคล']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะการใช้งานสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประเภทบุคคล');
await page.click('id=btn-kebab-status-ประเภทบุคคล', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='ประเภทบุคคล']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ปิดสถานะการใช้งานประเภทสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประเภท-ประกันทั้งหมด');
await page.click('id=btn-kebab-action-ประกันชีวิต');
await page.click('id=btn-kebab-status-ประกันชีวิต', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='ประกันชีวิต']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะการใช้งานประเภทสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประกันชีวิต');
await page.click('id=btn-kebab-status-ประกันชีวิต', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='ประกันชีวิต']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ปิดสถานะการใช้งานกลุ่มสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกันทั้งหมด');
await page.click("(//button[@id='btn-kebab-action-ประกันทั้งหมด'])[2]");
await page.click('id=btn-kebab-status-ประกันทั้งหมด', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='ประกันทั้งหมด']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะการใช้งานกลุ่มสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//button[@id='btn-kebab-action-ประกันทั้งหมด'])[2]");
await page.click('id=btn-kebab-status-ประกันทั้งหมด', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// await page.reload();
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//div[normalize-space(text())='ประกันทั้งหมด']",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,231 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { it } from 'node: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) {
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', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('จำลองการสร้างสินค้าและบริการเพิื่อทำการทดสอบลบ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
//-----------------------------------------สร้างกลุ่มสินค้าและบริการ------------------------------//
await page.click('id=menu-icon-product-service');
await page.click('id=btn-add');
await page.click('id=btn-add-product-group');
// กรอกข้อมูลกลุ่มสินค้าและบริการ
await page.fill("(//input[@id='input-name'])[2]", 'กลุ่มสินค้าและบริการ');
await page.fill(
"(//textarea[@id='input-detail'])[2]",
'รายละเอียดกลุ่มสินค้าและบริการ',
);
await page.fill(
"(//textarea[@id='input-remark'])[2]",
'หมายเหตุกลุ่มสินค้าและบริการ',
);
// บันทึกการสร้างกลุ่มสินค้นและบริการ
await page.click('id=btn-form-submit');
//-----------------------------------------สร้างสินค้าและบริการ------------------------------//
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-สินค้าและบริการ-กลุ่มสินค้าและบริการ');
await page.click('id=btn-add');
await page.click('id=btn-add-product');
// รหัสสินค้าและบริการ
await page.waitForSelector("(//input[@id='select-br-id'])[1]", {
state: 'visible',
});
await page.click("(//input[@id='select-br-id'])[1]");
await page.click('id=select-br-id_0');
await page.fill("(//input[@id='input-name'])[2]", 'สินค้าและบริการ');
// ระยะเวลาดำเนินการ
await page.fill('id=input-process', '2');
// ประเภทค่าใช้จ่าย
await page.waitForSelector("(//input[@id='select-br-id'])[2]", {
state: 'visible',
});
await page.click("(//input[@id='select-br-id'])[2]");
await page.click('id=select-br-id_0');
// กรอกรายละเอียด
await page.fill("//div[@contenteditable='true']", 'รายละเอียด');
// กรอกสาเหตุ
await page.fill("(//textarea[@id='input-remark'])[2]", 'หมายเหตุ');
// ส่วนข้อมูลราคา
await page.click("//span[normalize-space(text())='ข้อมูลราคา']");
await page.fill('id=input-price', '2000');
await page.fill('id=input-agent-price', '1800');
await page.fill('id=input-service-charge', '1000');
await page.click('id=btn-form-submit');
//-----------------------------------------สร้างประเภทสินค้าและบริการ------------------------------//
// เข้าสู่หน้าประเภท
await page.waitForSelector('id=tree-enter-ประเภท-กลุ่มสินค้าและบริการ', {
state: 'visible',
});
await page.click('id=tree-enter-ประเภท-กลุ่มสินค้าและบริการ');
// เพิ่มประเภท
await page.click('id=btn-add');
await page.click('id=btn-add-service');
// กรอกข้อมูลประเภทส่วน "ข้อมูลประเภท"
await page.fill('id=input-service-code', 'MOU');
await page.fill('id=input-service-name', 'ประเภทสินค้าและบริการ');
await page.fill('id=input-service-description', 'รายละเอียดประภัยแบบกลุ่ม');
// เพิ่มคุณสมบัติส่วน "คุณสมบัติของประเภท"
await page.click('id=btn-capitalize');
await page.click('id=btn-dropdow-properties');
await page.click('id=list-serviceRecordName');
await page.keyboard.press('Escape');
const propertiesServiceRecordName = page.locator(
"//span[normalize-space(text())='บันทึกบริการ_Name']",
);
expect(propertiesServiceRecordName).toHaveText('บันทึกบริการ_Name');
console.log(propertiesServiceRecordName, 'เลือกdropdown แล้ว');
// บันทึกการเพิ่มคุณสมบัติ
await page.click("(//button[@id='btn-form-submit'])[2]");
// เพิ่มส่วนข้อมูลงาน
await page.click("//span[normalize-space(text())='ข้อมูลงาน']");
await page.click('id=btn-add-work');
await page.click("//div[@for='select-work-name-1']");
await page.waitForTimeout(2000);
await page.click("//span[normalize-space(text())='จัดการ']");
await page.click("//span[normalize-space(text())='เพิ่มงาน']");
await page.fill('id=input-work-name-1', 'ทดสอบงาน');
await page.click('id=btn-save-work-name');
await page.click("(//button[@id='btn-form-close'])[2]");
await page.waitForTimeout(2000);
await page.click("//div[normalize-space(text())='ทดสอบงาน']");
await page.waitForTimeout(2000);
await page.keyboard.press('Escape');
// เพิ่มคุณสมบัติ
await page.click("(//button[@id='btn-add-work-product'])[1]");
await page.click('id=btn-dropdow-properties');
await page.click('id=list-refNo');
await page.keyboard.press('Escape');
const propertiesRefNo = page.locator("//span[text()='Ref No:']");
expect(propertiesRefNo).toHaveText('Ref No:');
console.log(propertiesRefNo, 'เลือกdropdown แล้ว');
await page.click("(//button[@id='btn-form-submit'])[2]");
// เพิ่มสินค้าและบริการ
await page.click("(//button[@id='btn-add-work-product'])[2]");
await page.click("//div[contains(@class,'column bordered')]");
await page.click("(//button[@id='btn-form-submit'])[2]");
// บันทึกการสร้างประเภท
await page.click('id=btn-form-submit');
console.log('จำลองการสร้างสินค้าและบริการสำเร็จ');
await page.waitForTimeout(2000);
});
test('ทดสอบการลบประเภทสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประเภทสินค้าและบริการ');
await page.click('id=btn-kebab-delete-ประเภทสินค้าและบริการ');
await page.click('id=btn-ok-dialog');
// ตรวจสอบการลบประเภทสินค้าและบริการ
const itemLocator = await page.locator(
"//td[contains(.,'สินค้าและบริการ DOE004')]",
);
expect(itemLocator).toBeHidden();
console.log('ตรวจสอบการลบประเภทสินค้าและบริการสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('ทดสอบการลบสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-สินค้าและบริการ-กลุ่มสินค้าและบริการ');
await page.click('id=btn-kebab-action-สินค้าและบริการ');
await page.click('id=btn-kebab-delete-สินค้าและบริการ');
await page.click('id=btn-ok-dialog');
// ตรวจสอบการลบสินค้าและบริการ
const itemLocator = await page.locator(
"//td[contains(.,'สินค้าและบริการ DOE004')]",
);
expect(itemLocator).toBeHidden();
console.log('ตรวจสอบการลบสินค้าและบริการสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,39 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// 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');
});
test('ทดสอบการเพิ่มขั้นตอนการทำงาน', async () => {
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-workflow');
await page.click('id=sub-menu-workflow');
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-Add');
await page.click('id=btn-Add');
// ส่วนชื่อแม่แบบ
});