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,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);
});