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

@ -1,146 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Create Branch Management - ไม่มีการกรอกข้อมูล', async () => {
await page.click('id=menu-icon-branch-management');
await page.click('id=hq-add-btn');
await page.click('id=btn-form-submit');
const abbreviationError = page.locator(
"(//div[@class='q-field__messages col'])[1]",
);
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const nameError = page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const nameEnError = page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
const LicenseNumberError = page.locator(
"(//div[@class='q-field__messages col']//div)[5]",
);
const addressError = page.locator(
"(//div[@class='q-field__messages col']//div)[6]",
);
const provinceError = page.locator(
"(//div[@class='q-field__messages col']//div)[7]",
);
const districtError = page.locator(
"(//div[@class='q-field__messages col']//div)[8]",
);
const subDistrictError = page.locator(
"(//div[@class='q-field__messages col']//div)[9]",
);
const addressEnError = page.locator(
"(//div[@class='q-field__messages col']//div)[10]",
);
await expect(abbreviationError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้', {
timeout: 2000,
});
await expect(taxNoError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(LicenseNumberError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(addressError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(provinceError).toHaveText('โปรดเลือกจังหวัด');
await expect(districtError).toHaveText('โปรดเลือกอำเภอ');
await expect(subDistrictError).toHaveText('โปรดเลือกตำบล');
await expect(addressEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Branch Managenment - กรณีที่กรอกชื่อย่อที่ไม่ใช่ภาษาอังกฤษ', async () => {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'ภาษาไทย');
const invalidDataabbreviationError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[contains(@class,'q-field__bottom row')])[1]",
);
await expect(invalidDataabbreviationError).toHaveText(
'ข้อมูลไม่ถูกต้อง โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่ไม่ใช่ภาษาอังกฤษถูกต้อง',
);
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
});
test('Create Branch Management - กรอกเลขนิติบุคคลในกรณีที่กรอกไม่ครบจำนวน 13 หลัก', async () => {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
const taxNoError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก',
);
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
});
test('Create Branch Management - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-email'])[2]", '123');
const emailError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง', {
timeout: 2000,
});
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ',
);
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
});

View file

@ -1,116 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Create Sub-Branch Managenment - ในกรณีที่ไม่กรอกข้อมูล', async () => {
await page.click('id=menu-icon-branch-management');
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.click('id=btn-form-submit');
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const nameEnError = page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const lincenseNumberError = page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
const addressError = page.locator(
"(//div[@class='q-field__messages col']//div)[5]",
);
const provinceError = page.locator(
"(//div[@class='q-field__messages col']//div)[6]",
);
const districtError = page.locator(
"(//div[@class='q-field__messages col']//div)[7]",
);
const subDistrictError = page.locator(
"(//div[@class='q-field__messages col']//div)[8]",
);
const addressEnError = page.locator(
"(//div[@class='q-field__messages col']//div)[9]",
);
await expect(taxNoError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(lincenseNumberError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(addressError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(provinceError).toHaveText('โปรดเลือกจังหวัด');
await expect(districtError).toHaveText('โปรดเลือกอำเภอ');
await expect(subDistrictError).toHaveText('โปรดเลือกตำบล');
await expect(addressEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Sub-Branch Managenment - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
});
test('Create Sub-Branch Managenment - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
});

View file

@ -1,112 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Create Service Point - ในกรณีที่ไม่กรอกข้อมูล', async () => {
await page.click('id=menu-icon-branch-management');
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.click('id=btn-form-submit');
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const nameEnError = page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const addressError = page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
const provinceError = page.locator(
"(//div[@class='q-field__messages col']//div)[5]",
);
const districtError = page.locator(
"(//div[@class='q-field__messages col']//div)[6]",
);
const subDistrictError = page.locator(
"(//div[@class='q-field__messages col']//div)[7]",
);
const addressEnError = page.locator(
"(//div[@class='q-field__messages col']//div)[8]",
);
await expect(taxNoError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(addressError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(provinceError).toHaveText('โปรดเลือกจังหวัด');
await expect(districtError).toHaveText('โปรดเลือกอำเภอ');
await expect(subDistrictError).toHaveText('โปรดเลือกตำบล');
await expect(addressEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Service Point - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
});
test('Create Service Point - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
await page.waitForTimeout(4000);
await page.click('id=btn-form-cancel');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
});

View file

@ -1,91 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('View Detail Headquter Branch', async () => {
try {
await page.click('id=menu-icon-branch-management');
await page.click('id=btn-kebab-action-บริษัท โคโม่ จำกัด');
await page.click('id=btn-kebab-view-detail-บริษัท โคโม่ จำกัด');
const detailTitle = page.locator(
"//span[text()='บริษัท โคโม่ จำกัด ']/following-sibling::span",
);
await expect(detailTitle).toHaveText('CMO00000'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('View Detail Sub Branch', async () => {
try {
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
await page.click('id=btn-kebab-action-สีลม1');
await page.click('id=btn-kebab-view-detail-สีลม1');
const detailTitle = page.locator("//span[text()='สีลม1 ']");
await detailTitle.waitFor({ state: 'visible' });
await expect(detailTitle).toHaveText('สีลม1'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('View Detail Service Point', async () => {
try {
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
await page.click('id=btn-kebab-action-บางรัก1');
await page.click('id=btn-kebab-view-detail-บางรัก1');
const detailTitle = page.locator("//span[text()='บางรัก1 ']");
await detailTitle.waitFor({ state: 'visible' });
await expect(detailTitle).toHaveText('บางรัก1'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});

View file

@ -1,219 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import exp from 'constants';
import { it } from 'node:test';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ทดสอบการลบจัดการสาขา', async () => {
await page.click('id=menu-icon-branch-management');
// จำลองการสร้างสำนักงานใหญ่
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'TES');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท จำลอง จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'JOMLONG');
await page.fill("(//input[@id='input-email'])[2]", 'JOM@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022010100');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
await page.fill("(//input[@id='input-line-id'])[2]", 'como20');
await page.fill("(//input[@id='default-input-address'])[2]", '40/04');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(1000);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '40/04');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_4');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2022822624262');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'ลำพูน');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-form-submit');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
// จำลองการสร้างสาขา
await page.click('id=create-sub-branch-btn-บริษัท จำลอง จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220281');
await page.fill("(//input[@id='input-name'])[3]", 'สาขาจำลอง');
await page.fill("(//input[@id='input-name-en'])[2]", 'SAKAJOMLONG');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
await page.fill("(//input[@id='input-email'])[2]", 'test@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '0822262228');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2282020021');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
// จำลองการสร้างสาขาเสมือน
await page.click('id=create-sub-branch-btn-บริษัท จำลอง จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '2022826282642');
await page.fill("(//input[@id='input-name'])[2]", 'สาขาเสมือน');
await page.fill("(//input[@id='input-name-en'])[2]", 'VISUALBRANCH');
await page.fill("(//input[@id='input-email'])[2]", 'visual@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอุล');
await page.fill("(//input[@id='input-contact'])[2]", '0822622862');
await page.fill("(//input[@id='input-line-id'])[2]", 'cmmsupport');
await page.fill("(//input[@id='default-input-address'])[2]", '40/04');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '40/04');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_2');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2822642201');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'ลำพูน');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
// ลบสาขาและตรวจสอบการลบสาขา
try {
await page.click('id=btn-kebab-action-สาขาจำลอง');
await page.click('id=btn-kebab-delete-สาขาจำลอง');
// ยืนยันการลบ
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(1000);
// ตรวจสอบการลบสาขา
const itemLocator = page.locator(
"//tr[contains(.,'1 สาขาจำลองTES0000112608462202810822262228คุณอาท20/02')]",
);
// ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
await expect(itemLocator).toBeHidden();
console.log('ตรวจสอบข้อมูลการลบสาขาสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการลบสาขา', error);
throw error;
}
// ลบสาขาเสมือนและตรวจสอบการลบสาขาเสมือน
try {
await page.click('id=btn-kebab-action-สาขาเสมือน');
await page.click('id=btn-kebab-delete-สาขาเสมือน');
// ยืนยันการลบ
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(1000);
// ตรวจสอบการลบสาขาเสมือน
const itemLocator = page.locator(
"//tr[contains(.,'2 สาขาเสมือนTES0000220228262826420822622862คุณอุล40/04')]",
);
// ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
await expect(itemLocator).toBeHidden();
console.log('ตรวจสอบข้อมูลการลบสาขาเสมือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการลบสาขาเสมือน', error);
throw error;
}
// // ลบสำนักงานใหญ่และตรวจสอบการลบสำนักงานใหญ่
// await page.click("//div[@id='tree-enter-บริษัท จำลอง จำกัด']/div[1]");
// try {
// await page.click('id=btn-kebab-action-บริษัท จำลอง จำกัด');
// await page.click('id=btn-kebab-delete-บริษัท จำลอง จำกัด');
// // ยืนยันการลบ
// await page.click('id=btn-ok-dialog');
// await page.waitForTimeout(1000);
// // ตรวจสอบการลบสำนักงานใหญ่
// const itemLocator = page.locator(
// "//tr[contains(.,'9 บริษัท จำลอง จำกัดTES0000012608462202840866224228คุณอาท40/04')]",
// );
// // ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
// await expect(itemLocator).toBeHidden();
// console.log('ตรวจสอบข้อมูลการลบสำนักงานใหญ่สำเร็จ');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการลบสำนักงานใหญ่', error);
// throw error;
// }
await page.waitForTimeout(2000);
});

View file

@ -3,6 +3,7 @@ import path from 'path';
import { off } from 'process';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -13,21 +14,46 @@ test.afterAll(async () => {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// ถ้าทั้งหมดสำเร็จ
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('Create Branch Managenment', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=menu-icon-branch-management');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// await page.click('id=hq-add-btn');
await page.click('id=btn-Add');
// await page.click("(//div[@class='q-avatar relative-position'])[2]");
@ -51,7 +77,7 @@ test('Create Branch Managenment', async () => {
// ส่วนข้อมูลพื้นฐาน
await page.fill("(//input[@id='input-abbreviation'])[2]", 'CMM');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[3]", 'บริษัท คาโมมายด์ จำกัด');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท คาโมมายด์ จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'CHAMOMIND');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
@ -113,6 +139,7 @@ test('Create Branch Managenment', async () => {
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -120,12 +147,17 @@ test('Create Branch Managenment', async () => {
});
test('Create Branch Managenment Second', async () => {
// ถ้ายังไม่ได้ Login ให้ทำการ Login
if (!isLoginSuccessful) {
await login(page);
}
try {
// ส่วนข้อมูลพื้นฐาน
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'CMO');
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
await page.fill("(//input[@id='input-name'])[3]", 'บริษัท โคโม่ จำกัด');
await page.fill("(//input[@id='input-name'])[2]", 'บริษัท โคโม่ จำกัด');
await page.fill("(//input[@id='input-name-en'])[2]", 'COMO');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
@ -187,6 +219,7 @@ test('Create Branch Managenment Second', async () => {
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}

View file

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

View file

@ -0,0 +1,210 @@
import { test, expect, Page, errors } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import exp from 'constants';
import { errorMonitor } from 'stream';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
// ถ้าขั้นตอนสำเร็จ
isLoginSuccessful = true;
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Branch Management - ไม่มีการกรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.click('id=hq-add-btn');
await page.click('id=btn-info-basic-save');
const exceptError = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[10]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of exceptError) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('ระบบตรวจสอบการแจ้งเตือนแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Branch Managenment - กรณีที่กรอกชื่อย่อที่ไม่ใช่ภาษาอังกฤษ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-abbreviation'])[2]", 'ภาษาไทย');
const invalidDataabbreviationError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[contains(@class,'q-field__bottom row')])[1]",
);
await expect(invalidDataabbreviationError).toHaveText(
'ข้อมูลไม่ถูกต้อง โปรดใช้เฉพาะ _ ตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่ไม่ใช่ภาษาอังกฤษถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Branch Management - กรอกเลขนิติบุคคลในกรณีที่กรอกไม่ครบจำนวน 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
const taxNoError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนชื่อย่อในกรณีที่ไม่ใช้ภาษาอังกฤษ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
{
timeout: 2000,
},
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Branch Management - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=hq-add-btn');
await page.fill("(//input[@id='input-email'])[2]", '123');
const emailError = page.locator(
// ตรวจสอบการแสดง Validation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง', {
timeout: 2000,
});
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ถูกรูปแบบ',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -2,6 +2,7 @@ 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();
@ -12,21 +13,39 @@ test.afterAll(async () => {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
}
test('Login', async () => {
// 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 login(page);
});
test('Create Sub Branch Managenment', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=menu-icon-branch-management');
for (let i = 0; i < 5; i++) {
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
@ -36,7 +55,7 @@ test('Create Sub Branch Managenment', async () => {
"(//input[@id='input-tax-no'])[2]",
`126084622028${i + 1}`,
);
await page.fill("(//input[@id='input-name'])[3]", `สีลม${i + 1}`);
await page.fill("(//input[@id='input-name'])[2]", `สีลม${i + 1}`);
await page.fill("(//input[@id='input-name-en'])[2]", `Silom${i + 1}`);
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
@ -106,6 +125,7 @@ test('Create Sub Branch Managenment', async () => {
console.log('การตรวจสอบสำเร็จ : ข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}

View file

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

View file

@ -0,0 +1,194 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Sub-Branch Managenment - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบ Validation ถูกต้อง');
});
test('Create Sub-Branch Managenment - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Sub-Branch Managenment - กรอกชื่อสาขาในกรณีที่ไม่ใช่ภาษาอังกฤษ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท โคโม่ จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-name-en'])[2]", 'ทดสอบ');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -2,6 +2,7 @@ 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();
@ -12,21 +13,39 @@ test.afterAll(async () => {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('Create Service Point Managenment', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=menu-icon-branch-management');
for (let i = 0; i < 5; i++) {
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
@ -36,7 +55,7 @@ test('Create Service Point Managenment', async () => {
"(//input[@id='input-tax-no'])[2]",
`202282628264${i + 1}`,
);
await page.fill("(//input[@id='input-name'])[3]", `บางรัก${i + 1}`);
await page.fill("(//input[@id='input-name'])[2]", `บางรัก${i + 1}`);
await page.fill("(//input[@id='input-name-en'])[2]", `Bangrak${i + 1}`);
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
@ -112,6 +131,7 @@ test('Create Service Point Managenment', async () => {
console.log('การตรวจสอบสำเร็จ : ข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}

View file

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

View file

@ -0,0 +1,167 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Create Service Point - ในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.click('id=btn-info-basic-save');
const expectedErrors = [
{
locator: "(//div[@class='q-field__messages col']//div)[1]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[2]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[3]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[4]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[5]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
{
locator: "(//div[@class='q-field__messages col']//div)[6]",
message: 'โปรดเลือกจังหวัด',
},
{
locator: "(//div[@class='q-field__messages col']//div)[7]",
message: 'โปรดเลือกเขต/อำเภอ',
},
{
locator: "(//div[@class='q-field__messages col']//div)[8]",
message: 'โปรดเลือกแขวง/ตำบล',
},
{
locator: "(//div[@class='q-field__messages col']//div)[9]",
message: 'จำเป็นต้องกรอกข้อมูลนี้',
},
];
for (const error of expectedErrors) {
const locator = page.locator(error.locator);
await expect(locator).toHaveText(error.message);
}
console.log('การตรวจสอบ Validation ถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Service Point - ในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลัก', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '123');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const taxNoError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
await expect(taxNoError).toHaveText(
'ข้อมูลไม่ถูกต้อง กรุณากรอกให้ครบ 13 หลัก',
);
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกทะเบียนนิติบุคคลเลขที่ไม่ครบ 13 หลักถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});
test('Create Service Point - กรอกอีเมลในกรณีที่ไม่ตรงรูปแบบอีเมล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=create-sub-branch-btn-บริษัท คาโมมายด์ จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-email'])[2]", 'email');
// ตรวจสอบการแจ้งเตือนของทะเบียนนิติบุคคลเลขที่ในกรณีที่กรอกข้อมูลไม่ครบ 13 หลัก
const emailError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(emailError).toHaveText('ข้อมูลไม่ถูกต้อง');
console.log(
'ตรวจสอบการแสดง Vidation แจ้งเตือนในกรณีที่กรอกอีเมลไม่ตรงรูปแบบถูกต้อง',
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-form-close');
});

View file

@ -1,9 +1,12 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { sign } from 'crypto';
import { watchFile } from 'fs';
import { waitForDebugger } from 'inspector';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,23 +17,39 @@ test.afterAll(async () => {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับที่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเมนูเพื่อจัดการสาขา
await page.click('id=menu-icon-branch-management');
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
@ -82,6 +101,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -89,6 +109,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -142,6 +165,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -149,6 +173,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลทะเบียนนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -202,6 +229,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -209,6 +237,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลเบอร์โทรสำนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -262,6 +293,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -269,6 +301,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -320,6 +355,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -327,6 +363,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลที่อยู่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -380,6 +419,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}

View file

@ -0,0 +1,235 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการดูรายละเอียดสำนักงานใหญ่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-บริษัท โคโม่ จำกัด');
await page.click('id=btn-kebab-view-detail-บริษัท โคโม่ จำกัด');
const detailTitle = page.locator(
"//span[text()='บริษัท โคโม่ จำกัด ']/following-sibling::span",
);
await expect(detailTitle).toHaveText('CMO00000'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('ทดสอบการดูรายละเอียดสาขา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
await page.click('id=btn-kebab-action-สีลม1');
await page.click('id=btn-kebab-view-detail-สีลม1');
const detailTitle = page.locator("//span[text()='สีลม1 ']");
await detailTitle.waitFor({ state: 'visible' });
await expect(detailTitle).toHaveText('สีลม1'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('ทดสอบการดูรายละเอียดจุดรับบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
await page.click('id=btn-kebab-action-บางรัก1');
await page.click('id=btn-kebab-view-detail-บางรัก1');
const detailTitle = page.locator("//span[text()='บางรัก1 ']");
await detailTitle.waitFor({ state: 'visible' });
await expect(detailTitle).toHaveText('บางรัก1'); // เลขรหัสสำนักงานใหญ่
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
await page.click('id=btn-info-close');
});
test('ทดสอบการดูรายละเอียดสำนักงานใหญ่ในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
await page.reload();
await page.click("//button[@aria-pressed='false']");
await page.waitForTimeout(2000);
try {
const nameBrnach = page.locator(
"//b[normalize-space(text())='บริษัท คาโมมายด์ จำกัด']",
);
const legalPerson = page.locator(
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
);
const cellPhone = page.locator(
"(//div[text()='เบอร์โทรสำนักงาน']/following-sibling::div)[1]",
);
const contactName = page.locator("//div[normalize-space(text())='คุณต่อ']");
const address = page.locator(
"//div[normalize-space(text())='20/02 หมู่ 1, พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
);
await expect(nameBrnach).toHaveText('บริษัท คาโมมายด์ จำกัด');
await expect(legalPerson).toHaveText('1260846220284');
await expect(cellPhone).toHaveText('0866224228');
await expect(contactName).toHaveText('คุณต่อ');
await expect(address).toHaveText(
'20/02 หมู่ 1, พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
);
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
});
test('ทดสอบการดูรายละเอียดสาขาในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
await page.waitForTimeout(2000);
const legalPerson = page.locator(
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
);
const contactName = page.locator(
"(//div[text()='ติดต่อ']/following-sibling::div)[1]",
);
const address = page.locator(
"//div[normalize-space(text())='40/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
);
await expect(legalPerson).toHaveText('2022826282641');
await expect(contactName).toHaveText('คุณอุล');
await expect(address).toHaveText(
'40/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
);
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
});
test('ทดสอบการดูรายละเอียดจุดรับบริการในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
await page.waitForTimeout(2000);
const legalPerson = page.locator(
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
);
const contactName = page.locator(
"(//div[text()='ติดต่อ']/following-sibling::div)[1]",
);
const address = page.locator(
"//div[normalize-space(text())='20/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
);
await expect(legalPerson).toHaveText('1260846220281');
await expect(contactName).toHaveText('คุณอาท');
await expect(address).toHaveText(
'20/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
);
console.log('ตรวจสอบข้อมูลถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
});

View file

@ -1,8 +1,10 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
import { sign } from 'crypto';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,21 +16,41 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('Edit Headquter Branch', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แก้ไขสำนักงานใหญ่
await page.click('id=menu-icon-branch-management');
await page.click('id=btn-kebab-action-บริษัท โคโม่ จำกัด');
await page.click('id=btn-kebab-edit-บริษัท โคโม่ จำกัด');
await page.fill('id=input-name', 'บริษัท โคโมโดะ จำกัด');
@ -53,6 +75,7 @@ test('Edit Headquter Branch', async () => {
console.log('ตรวจสอบการแก้ไขข้อมูลสำนักงานใหญ่ถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
@ -61,6 +84,9 @@ test('Edit Headquter Branch', async () => {
});
test('Edit Sub Branch', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แก้ไขสำนักงานใหญ่
await page.click("//div[@id='tree-enter-บริษัท โคโมโดะ จำกัด']/div[1]");
@ -90,6 +116,7 @@ test('Edit Sub Branch', async () => {
console.log('ตรวจสอบการแก้ไขข้อมูลสาขาถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
@ -98,6 +125,9 @@ test('Edit Sub Branch', async () => {
});
test('Edit Visual Branch', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แก้ไขสำนักงานใหญ่
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
@ -121,6 +151,7 @@ test('Edit Visual Branch', async () => {
console.log('ตรวจสอบการแก้ไขข้อมูลสาขาเสมือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}

View file

@ -2,6 +2,7 @@ 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();
@ -13,22 +14,40 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login');
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ตรวจสอบการแสดงผลสถานะการใช้งาน เปิด/ปิด สำนักงานใหญ่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเมนูเพื่อจัดการสาขา
await page.click('id=menu-icon-branch-management');
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=field-select-status');
@ -86,6 +105,7 @@ test('ตรวจสอบการแสดงผลสถานะการ
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}

View file

@ -3,6 +3,7 @@ import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,20 +15,39 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// Login
await page.goto('http://192.168.1.90: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');
await login(page);
});
test('Search Data Branch Management', async () => {
await page.click('id=menu-icon-branch-management');
if (!isLoginSuccessful) {
await login(page);
}
try {
// กำหนดคำที่จะค้นหา
const searchDatas = [
@ -79,6 +99,7 @@ test('Search Data Branch Management', async () => {
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);

View file

@ -3,6 +3,7 @@ import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,20 +15,41 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ปิดการใช้งานสำนักงานใหญ่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=menu-icon-branch-management');
await page.click('id=btn-kebab-action-บริษัท คาโมมายด์ จำกัด');
await page.click('id=btn-kebab-status-บริษัท คาโมมายด์ จำกัด', {
@ -57,12 +79,17 @@ test('ปิดการใช้งานสำนักงานใหญ่',
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-บริษัท คาโมมายด์ จำกัด');
@ -93,6 +120,7 @@ test('เปิดการใช้งานสำนักงานใหญ
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);

View file

@ -0,0 +1,247 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { Console, error, log } from 'console';
import exp from 'constants';
import { it } from 'node:test';
import { prependOnceListener } from 'process';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสาขา
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-branch');
await page.click('id=sub-menu-branch');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการลบจัดการสาขา', async () => {
// จำลองการสร้างสำนักงานใหญ่
// await page.click('id=hq-add-btn');
// await page.fill("(//input[@id='input-abbreviation'])[2]", 'TES');
// await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220284');
// await page.fill("(//input[@id='input-name'])[2]", 'บริษัท จำลอง จำกัด');
// await page.fill("(//input[@id='input-name-en'])[2]", 'JOMLONG');
// await page.fill("(//input[@id='input-license-number'])[2]", '2938227328292');
// await page.fill("(//input[@id='input-email'])[2]", 'JOM@support.com');
// await page.fill("(//input[@id='input-telephone-no'])[2]", '022010100');
// await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
// await page.fill("(//input[@id='input-contact'])[2]", '0866224228');
// await page.fill("(//input[@id='input-line-id'])[2]", 'como20');
// await page.fill("(//input[@id='default-input-address-no'])[2]", '40/04');
// await page.click("(//input[@id='default-select-province'])[2]");
// await page.click("//div[@role='option']");
// await page.click("(//input[@id='default-select-district'])[2]");
// await page.waitForTimeout(1000);
// await page.click("//div[@role='option']");
// await page.click("(//input[@id='default-select-sub-district'])[2]");
// await page.waitForTimeout(1000);
// await page.click("//div[@role='option']");
// await page.fill("(//input[@id='default-input-address-en'])[2]", '40/04');
// await page.click("(//input[@id='select-bankbook'])[3]");
// await page.click('id=select-bankbook_4');
// await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2022822624262');
// await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'ลำพูน');
// await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
// await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
// await page.waitForTimeout(2000);
// await page.click('id=select-bankbook_0');
// await page.click('id=btn-info-basic-save');
// await page.waitForSelector('id=btn-ok-dialog');
// await page.click('id=btn-ok-dialog');
// await page.click('id=btn-form-close');
if (!isLoginSuccessful) {
await login(page);
}
// จำลองการสร้างสาขา
try {
await page.click('id=create-sub-branch-btn-บริษัท จำลอง จำกัด');
await page.click("(//button[@type='submit'])[1]");
await page.fill("(//input[@id='input-tax-no'])[2]", '1260846220281');
await page.fill("(//input[@id='input-name'])[2]", 'สาขาจำลอง');
await page.fill("(//input[@id='input-name-en'])[2]", 'SAKAJOMLONG');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
await page.fill("(//input[@id='input-email'])[2]", 'test@support.com');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอาท');
await page.fill("(//input[@id='input-contact'])[2]", '0822262228');
await page.fill("(//input[@id='input-line-id'])[2]", 'company');
await page.fill("(//input[@id='default-input-address-no'])[2]", '20/02');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '20/02');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_1');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2282020021');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'เชียงใหม่');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
// จำลองการสร้างสาขาเสมือน
await page.click('id=create-sub-branch-btn-บริษัท จำลอง จำกัด');
await page.click("(//button[@type='submit'])[2]");
await page.fill("(//input[@id='input-tax-no'])[2]", '2022826282642');
await page.fill("(//input[@id='input-name'])[2]", 'สาขาเสมือน');
await page.fill("(//input[@id='input-name-en'])[2]", 'VISUALBRANCH');
await page.fill(
"(//input[@aria-label='เลขที่ใบอนุญาต'])[2]",
'1228222822822',
);
await page.fill("(//input[@id='input-email'])[2]", 'visual@local.co.th');
await page.fill("(//input[@id='input-telephone-no'])[2]", '022222002');
await page.fill("(//input[@id='input-contact-name'])[2]", 'คุณอุล');
await page.fill("(//input[@id='input-contact'])[2]", '0822622862');
await page.fill("(//input[@id='input-line-id'])[2]", 'cmmsupport');
await page.fill("(//input[@id='default-input-address-no'])[2]", '40/04');
await page.click("(//input[@id='default-select-province'])[2]");
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.click("(//input[@id='default-select-sub-district'])[2]");
await page.waitForTimeout(400);
await page.click("//div[@role='option']");
await page.fill("(//input[@id='default-input-address-en'])[2]", '40/04');
await page.click("(//input[@id='select-bankbook'])[3]");
await page.click('id=select-bankbook_2');
await page.fill("(//input[@aria-label='เลขบัญชี'])[2]", '2822642201');
await page.fill("(//input[@aria-label='สาขาธนาคาร'])[2]", 'ลำพูน');
await page.fill("(//input[@aria-label='ชื่อบัญชี'])[2]", 'Pongpon Kuntana');
await page.click("(//input[@aria-label='ประเภทบัญชี'])[2]");
await page.waitForTimeout(2000);
await page.click('id=select-bankbook_0');
await page.click('id=btn-info-basic-save');
await page.click('id=btn-form-close');
await page.waitForTimeout(1000);
// ลบสาขาและตรวจสอบการลบสาขา
await page.click('id=btn-kebab-action-สาขาจำลอง');
await page.click('id=btn-kebab-delete-สาขาจำลอง');
// ยืนยันการลบ
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(1000);
// ตรวจสอบการลบสาขา
const itemLocator = page.locator(
"//tr[contains(.,'1 สาขาจำลองTES0000112608462202810822262228คุณอาท20/02')]",
);
// ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
await expect(itemLocator).toBeHidden();
console.log('ตรวจสอบข้อมูลการลบสาขาสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการลบสาขา', error);
throw error;
}
// ลบสาขาเสมือนและตรวจสอบการลบสาขาเสมือน
try {
await page.click('id=btn-kebab-action-สาขาเสมือน');
await page.click('id=btn-kebab-delete-สาขาเสมือน');
// ยืนยันการลบ
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(1000);
// ตรวจสอบการลบสาขาเสมือน
const itemLocator = page.locator(
"//tr[contains(.,'2 สาขาเสมือนTES0000220228262826420822622862คุณอุล40/04')]",
);
// ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
await expect(itemLocator).toBeHidden();
console.log('ตรวจสอบข้อมูลการลบสาขาเสมือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการลบสาขาเสมือน', error);
isLoginSuccessful = false;
throw error;
}
// // ลบสำนักงานใหญ่และตรวจสอบการลบสำนักงานใหญ่
// await page.click("//div[@id='tree-enter-บริษัท จำลอง จำกัด']/div[1]");
// try {
// await page.click('id=btn-kebab-action-บริษัท จำลอง จำกัด');
// await page.click('id=btn-kebab-delete-บริษัท จำลอง จำกัด');
// // ยืนยันการลบ
// await page.click('id=btn-ok-dialog');
// await page.waitForTimeout(1000);
// // ตรวจสอบการลบสำนักงานใหญ่
// const itemLocator = page.locator(
// "//tr[contains(.,'9 บริษัท จำลอง จำกัดTES0000012608462202840866224228คุณอาท40/04')]",
// );
// // ตรวจสอบว่าถูกลบออกจากระบบหรือไม่
// await expect(itemLocator).toBeHidden();
// console.log('ตรวจสอบข้อมูลการลบสำนักงานใหญ่สำเร็จ');
// } catch (error) {
// console.error('เกิดข้อผิดพลาดในการลบสำนักงานใหญ่', error);
// throw error;
// }
await page.waitForTimeout(2000);
});

View file

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

View file

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

View file

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

View file

@ -0,0 +1,248 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { exec } from 'child_process';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ดูรายละเอียดพนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[2]");
try {
await page.waitForSelector('id=btn-kebab-action-employeem', {
state: 'visible',
});
await page.click('id=btn-kebab-action-employeem');
await page.click('id=btn-kebab-view-detail-employeem');
const detailTitle = page.locator("//span[text()='ธรรมรงด์ ดำรงธรรม']");
await expect(detailTitle).toHaveText('ธรรมรงด์ ดำรงธรรม');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('ดูรายละเอียดพนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-kebab-action-courierw');
await page.click('id=btn-kebab-view-detail-courierw');
const detailTitle = page.locator("//span[text()='มาตา ลดา']");
await expect(detailTitle).toHaveText('มาตา ลดา');
console.log('ตรวจสอบรายละเอียดพนักงานส่งเอกสารถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('ดูรายละเอียดตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[4]");
await page.click('id=btn-kebab-action-delegatem');
await page.click('id=btn-kebab-view-detail-delegatem');
const detailTitle = page.locator("//span[text()='อาคม พลัง']");
await expect(detailTitle).toHaveText('อาคม พลัง');
console.log('ตรวจสอบรายละเอียดตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('ดูรายละเอียดเอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[5]");
await page.click('id=btn-kebab-action-agencyw');
await page.waitForSelector('id=btn-kebab-view-detail-agencyw', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-agencyw');
const detailTitle = await page.locator("//span[text()='ธิดา งามตา']");
await expect(detailTitle).toHaveText('ธิดา งามตา');
console.log('ตรวจสอบรายละเอียดเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
// ---------------------------------- รูปแบบการ์ด ----------------------------//
test('ดูรายละเอียดพนักงานในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click("//button[@aria-pressed='false']");
await page.click("(//div[@role='tab'])[2]");
const namePersonal = page.locator(
"//div[normalize-space(text())='ธรรมรงด์ ดำรงธรรม']",
);
await expect(namePersonal).toHaveText('ธรรมรงด์ ดำรงธรรม');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ดูรายละเอียดพนักงานส่งเอกสารในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[3]");
const namePersonal = page.locator(
"//div[normalize-space(text())='มาตา ลดา']",
);
await expect(namePersonal).toHaveText('มาตา ลดา');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ดูรายละเอียดตัวแทนในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[4]");
const namePersonal = page.locator(
"//div[normalize-space(text())='อาคม พลัง']",
);
await expect(namePersonal).toHaveText('อาคม พลัง');
console.log('ตรวจสอบรายละเอียดตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ดูรายละเอียดเอเจนซี่ในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//div[@role='tab'])[5]");
const namePersonal = page.locator(
"//div[normalize-space(text())='ธิดา งามตา']",
);
await expect(namePersonal).toHaveText('ธิดา งามตา');
console.log('ตรวจสอบรายละเอียดเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -5,6 +5,7 @@ import { log } from 'console';
import { writeFileSync } from 'fs';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -16,19 +17,38 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('ระบบทำการ Login');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('Edit Personnel - พนักงาน', async () => {
await page.click('id=menu-icon-personnel-management');
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
@ -83,6 +103,7 @@ test('Edit Personnel - พนักงาน', async () => {
console.log('ตรวจสอบการแก้ไขข้อมูลพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
@ -90,10 +111,15 @@ test('Edit Personnel - พนักงาน', async () => {
});
test('Edit Personnel - พนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-kebab-action-courierw');
await page.waitForSelector('id=btn-kebab-edit-courierw');
await page.click('id=btn-kebab-edit-courierw');
// แก้ไขข้อมูล
@ -131,6 +157,7 @@ test('Edit Personnel - พนักงานส่งเอกสาร', async
console.log('ตรวจสอบการแก้ไขข้อมูลพนักงานส่งเอกสารถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
@ -138,10 +165,16 @@ test('Edit Personnel - พนักงานส่งเอกสาร', async
});
test('Edit Personnel - ตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[4]");
await page.waitForTimeout(1000);
await page.click('id=btn-kebab-action-delegatem');
await page.waitForSelector('id=btn-kebab-edit-delegatem');
await page.click('id=btn-kebab-edit-delegatem');
// แก้ไขข้อมูล
@ -184,6 +217,7 @@ test('Edit Personnel - ตัวแทน', async () => {
console.log('ตรวจสอบการแก้ไขข้อมูลตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);
@ -191,6 +225,10 @@ test('Edit Personnel - ตัวแทน', async () => {
});
test('Edit Personnel - เอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// เข้าสู่หน้าแก้ไขพนักงาน
await page.click("(//div[@role='tab'])[5]");
@ -199,6 +237,7 @@ test('Edit Personnel - เอเจนซี่', async () => {
state: 'visible',
});
await page.click('id=btn-kebab-action-agencyw');
await page.waitForSelector('id=btn-kebab-edit-agencyw');
await page.click('id=btn-kebab-edit-agencyw');
// แก้ไขข้อมูล
@ -236,6 +275,7 @@ test('Edit Personnel - เอเจนซี่', async () => {
console.log('ตรวจสอบการแก้ไขข้อมูลเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบแก้ไขบุคลากร');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(4000);

View file

@ -1,7 +1,9 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -13,19 +15,38 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ปิดสถานะการใช้งานบุคลากร', async () => {
await page.click('id=menu-icon-personnel-management');
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-employeem');
@ -56,12 +77,16 @@ test('ปิดสถานะการใช้งานบุคลากร',
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะการใช้งานบุคลากร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-employeem');
@ -92,6 +117,7 @@ test('เปิดสถานะการใช้งานบุคลาก
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);

View file

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

View file

@ -2,6 +2,7 @@ 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();
@ -13,26 +14,45 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด บุคลากรทั้งหมด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเมนูจัดการบุคลากร
await page.click('id=menu-icon-personnel-management');
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.waitForTimeout(1000);
await page.click('id=field-select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
//รอให้ dropdown เปิด
await page.waitForSelector('id=field-select-status_1');
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=field-select-status_1');
@ -86,11 +106,15 @@ test('ตรวจสอบการแสดงสถานะใช้งา
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด พนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงาน
await page.click("(//div[@role='tab'])[2]");
@ -152,11 +176,15 @@ test('ตรวจสอบการแสดงสถานะใช้งา
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด พนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงานส่งเอกสาร
await page.click("(//div[@role='tab'])[3]");
@ -218,11 +246,15 @@ test('ตรวจสอบการแสดงสถานะใช้งา
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด ตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab ตัวแทน
await page.click("(//div[@role='tab'])[4]");
@ -284,11 +316,15 @@ test('ตรวจสอบการแสดงสถานะใช้งา
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด เอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab เอเจนซี่
await page.click("(//div[@role='tab'])[5]");
@ -350,6 +386,7 @@ test('ตรวจสอบการแสดงสถานะใช้งา
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -2,6 +2,7 @@ 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();
@ -12,24 +13,42 @@ test.afterAll(async () => {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่หน้าบุคลากร
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-personnel');
await page.click('id=sub-menu-personnel');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
//---------------------------------Tab ทั้งหมด----------------------------------------
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเมนูเพื่อเข้าหน้าจัดการบุคลากร
await page.click('id=menu-icon-personnel-management');
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
@ -81,12 +100,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -139,12 +162,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -197,12 +224,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -255,12 +286,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -313,12 +348,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -371,12 +410,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -429,6 +472,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
@ -438,6 +482,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
//---------------------------------Tab พนักงาน----------------------------------------
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ - พนักงาน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงาน
await page.click("(//div[@role='tab'])[2]");
@ -493,12 +540,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -551,12 +602,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -609,12 +665,16 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -667,12 +727,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -725,12 +790,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -783,12 +853,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -841,6 +916,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
@ -850,6 +926,10 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
//---------------------------------Tab พนักงานส่งเอกสาร----------------------------------------
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ - พนักงานส่งเอกสาร', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงาน
await page.click("(//div[@role='tab'])[3]");
@ -905,12 +985,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -963,12 +1048,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1021,12 +1111,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1079,12 +1174,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1137,12 +1237,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1195,12 +1300,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1253,6 +1363,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
@ -1262,6 +1373,10 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
//---------------------------------Tab ตัวแทน----------------------------------------
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ - ตัวแทน', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงาน
await page.click("(//div[@role='tab'])[4]");
@ -1317,12 +1432,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1375,12 +1495,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1433,12 +1558,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1491,12 +1621,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1549,12 +1684,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1607,12 +1747,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1665,6 +1810,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');
@ -1674,6 +1820,10 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
//---------------------------------Tab เอเจนซี่----------------------------------------
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ - เอเจนซี่', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิก Tab พนักงาน
await page.click("(//div[@role='tab'])[5]");
@ -1729,12 +1879,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1787,12 +1942,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1845,12 +2005,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1903,12 +2068,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -1961,12 +2131,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -2019,12 +2194,17 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
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]");
@ -2077,6 +2257,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
await page.keyboard.press('Escape');

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

@ -2,6 +2,7 @@ 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();
@ -13,32 +14,53 @@ test.afterAll(async () => {
}
});
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 () => {
// 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 login(page);
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดา', async () => {
await page.click('id=menu-icon-customer-management');
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-Add');
await page.click("(//button[@type='submit'])[2]");
await page.waitForTimeout(2000);
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
// ส่วนเกี่ยวกับ
await page.fill('id=input-legal-person-no', '1524428220420');
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("(//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]", 'Yossapat');
await page.fill("(//input[@id='form-input-last-name'])[2]", 'Tanakarn');
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');
@ -46,8 +68,10 @@ test('ทดสอบการสร้างนายจ้างบุคค
"(//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()='2542']");
await page.click("//div[@id='1999-09-02']/div[1]");
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]");
@ -77,45 +101,50 @@ test('ทดสอบการสร้างนายจ้างบุคค
await page.click('id=btn-form-close');
// กำหนดค่าเพื่อตรวจสอบความถูกต้องหลังสร้าง
const nameTitleNatrualPerson = await page.locator(
"//div[normalize-space(text())='ยศพัฒน์ ธนากานต์']",
"//tr[contains(.,'นาย ยศพัฒน์ ธนากานต์') and contains (.,'--')]",
);
expect(nameTitleNatrualPerson).toHaveText('ยศพัฒน์ ธนากานต์');
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-legal-person-no', '1886222422008');
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("(//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]", 'Surawat');
await page.fill(
"(//input[@id='form-input-last-name'])[2]",
'Jantarasombat',
);
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.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()='2542']");
await page.click("//div[@id='1999-09-02']/div[1]");
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]");
@ -129,32 +158,33 @@ test('ทดสอบการสร้างนายจ้างบุคค
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@aria-selected='false'])[3]");
await page.fill("(//input[@id='form-input-address'])[1]", '22282206402');
await page.fill('id=form-input-address-no', '400');
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', '400');
await page.fill('id=form-input-address-en', '200');
await page.click("//button[@type='submit']");
await page.click('id=btn-form-close');
await page.waitForSelector(
"//div[normalize-space(text())='สุรวัฒน์ จันทรสมบัติ']",
);
// กำหนดค่าเพื่อตรวจสอบความถูกต้องหลังสร้าง
const nameTitleNatrualPerson = await page.locator(
"//div[normalize-space(text())='สุรวัฒน์ จันทรสมบัติ']",
"//tr[contains(.,'นาย สุรวัฒน์ จันทรสมบัติ') and contains (.,'--')]",
);
expect(nameTitleNatrualPerson).toHaveText('สุรวัฒน์ จันทรสมบัติ');
expect(nameTitleNatrualPerson).toContainText('สุรวัฒน์ จันทรสมบัติ');
expect(nameTitleNatrualPerson).toContainText('--');
console.log('ระบบสามารถสร้างนายจ้างบุคคลธรรมดาได้');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);

View file

@ -6,6 +6,7 @@ import { ToastHeader } from 'react-bootstrap';
import { toHandlerKey } from 'vue';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -17,55 +18,87 @@ test.afterAll(async () => {
}
});
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 () => {
// 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 login(page);
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่ไม่กรอกช้อมูล', async () => {
await page.click('id=menu-icon-customer-management');
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']");
// กำหนดค่าเพื่อตรวจสอบหลังเกิดการ Validation
const citizenNoError = await page.locator(
"(//div[@class='q-field__messages col'])[1]",
);
const firstNameThError = await page.locator(
"(//div[@class='q-field__messages col'])[2]",
);
const lastNameThError = await page.locator(
"(//div[@class='q-field__messages col'])[3]",
);
const firstNameEngError = await page.locator(
"(//div[@class='q-field__messages col'])[4]",
);
const lastNameEngError = await page.locator(
"(//div[@class='q-field__messages col'])[5]",
);
const brithDateError = await page.locator(
"(//div[@class='q-field__messages col'])[6]",
);
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.',
},
];
// ตรวจสอบการเกิด Validation
expect(citizenNoError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(firstNameThError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(lastNameThError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(firstNameEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(lastNameEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(brithDateError).toHaveText('โปรดเลือกวันเดือนปีเกิด');
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);
@ -73,6 +106,10 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนเกี่ยวกับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
@ -85,19 +122,31 @@ test('ทดสอบการสร้างนายจ้างบุคค
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.waitForSelector("//div[@id='2024-09-18']/div[1]");
await page.click("//div[@id='2024-09-18']/div[1]");
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())='กรอกข้อมูลไม่ครบ']",
"//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',
);
await expect(textPopupError).toHaveText('กรอกข้อมูลไม่ครบ');
console.log('ตรวจสอบการแจ้งเตือน Pop-up สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-ok-dialog');
@ -108,40 +157,54 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
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 businessTypeError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const businessTypeEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const jobPositionError = await page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const jobPositionEnError = await page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
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);
}
// ตรวจสอบการแจ้งเตือน
expect(businessTypeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(businessTypeEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(jobPositionError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(jobPositionEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
console.log('ตรวจสอบการแจ้งเตือนสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลธุรกิจ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
@ -156,18 +219,26 @@ test('ทดสอบการสร้างนายจ้างบุคค
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.fill("//input[@aria-label='Pay Rate (Text)']", '2000');
await page.click("//button[@type='submit']");
// กำหนดค่าการแจ้งเตือน
const titleError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// รอการเกิด 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']",
);
expect(titleError).toHaveText('กรอกข้อมูลไม่ครบ');
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');
@ -177,43 +248,78 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
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 addressIdentificationError = await page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const addressNoError = await page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
const provinceError = await page.locator(
"(//div[@class='q-field__messages col']//div)[3]",
);
const districtError = await page.locator(
"(//div[@class='q-field__messages col']//div)[4]",
);
const subdistrictError = await page.locator(
"(//div[@class='q-field__messages col']//div)[5]",
);
const addressNoEngError = await page.locator(
"(//div[@class='q-field__messages col']//div)[6]",
);
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.',
},
];
// ตรวจสอบการแจ้งเตือน
expect(addressIdentificationError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(addressNoError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
expect(provinceError).toHaveText('โปรดเลือกจังหวัด');
expect(districtError).toHaveText('โปรดเลือกอำเภอ');
expect(subdistrictError).toHaveText('โปรดเลือกตำบล');
expect(addressNoEngError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
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);
@ -221,7 +327,12 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
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]");
@ -239,16 +350,22 @@ test('ทดสอบการสร้างนายจ้างบุคค
await page.fill('id=form-input-address-en', '800');
await page.click("//button[@type='submit']");
// กำหนดค่าการแจ้งเตือน
const popupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// รอการเกิด 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']",
);
// ตรวจสอบการแจ้งเตือน
expect(popupError).toHaveText('กรอกข้อมูลไม่ครบ');
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');
@ -259,21 +376,32 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
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']");
// กำหนดค่าการแจ้งเตือน
const popupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// รอการเกิด 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']",
);
// ตรวจสอบการแจ้งเตือน
expect(popupError).toHaveText('กรอกข้อมูลไม่ครบ');
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');
@ -284,6 +412,10 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
test('ทดสอบการสร้างนายจ้างบุคคลธรรมดาในกรณีที่กรอกข้อมูลเฉพาะส่วนข้อมูลติดต่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.click('id=add-customer-natural-person');
@ -293,16 +425,22 @@ test('ทดสอบการสร้างนายจ้างบุคค
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']");
// กำหนดค่าการแจ้งเตือน
const popupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// รอการเกิด 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']",
);
// ตรวจสอบการแจ้งเตือน
expect(popupError).toHaveText('กรอกข้อมูลไม่ครบ');
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');
@ -313,22 +451,27 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
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())='ข้อมูลไม่ถูกต้อง']",
// รอการเกิด Dialog
const emailError = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
// ตรวจสอบการแจ้งเตือน
expect(emailFomatError).toHaveText('ข้อมูลไม่ถูกต้อง');
await expect(emailError).toHaveText('Invalid value.');
console.log('ตรวจสอบการแจ้งเตือนรูปแบบอีเมลไม่ถูกต้อง : Success ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
@ -336,22 +479,31 @@ test('ทดสอบการสร้างนายจ้างบุคค
});
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']");
// กำหนดค่าแจ้งเตือน
const popupError = await page.locator(
"//span[normalize-space(text())='กรอกข้อมูลไม่ครบ']",
// รอการเกิด 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']",
);
// ตรวจสอบการแจ้งเตือน
expect(popupError).toHaveText('กรอกข้อมูลไม่ครบ');
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');

View file

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

View file

@ -0,0 +1,118 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบดูรายละเอียดบุคคลธรรมดาโดยการคลิกไอคอนดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//button[@id='btn-eye-ยศพัฒน์'])[2]");
await page.waitForTimeout(2000);
const fullName = page.locator("//span[text()='ยศพัฒน์ ธนากานต์']");
await expect(fullName).toHaveText('ยศพัฒน์ ธนากานต์');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
});
test('ตรวจสอบดูรายละเอียดบุคคลธรรมดาผ่านเมนูย่อยจุดสามจุด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ยศพัฒน์');
await page.waitForSelector('id=btn-kebab-view-detail-ยศพัฒน์');
await page.click('id=btn-kebab-view-detail-ยศพัฒน์');
await page.waitForTimeout(2000);
const fullName = page.locator("//span[text()='ยศพัฒน์ ธนากานต์']");
await expect(fullName).toHaveText('ยศพัฒน์ ธนากานต์');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
});
test('ตรวจสอบดูรายละเอียดบุคคลธรรมดาในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const fullName = await page.locator(
"//b[normalize-space(text())='ยศพัฒน์ ธนากานต์']",
);
const citizenId = await page.locator(
"//span[normalize-space(text())='1524428220420']",
);
const typeBussiness = await page.locator(
"(//span[text()='ประเภทกิจการ']/following-sibling::span)[1]",
);
await expect(fullName).toHaveText('ยศพัฒน์ ธนากานต์');
await expect(citizenId).toHaveText('1524428220420');
await expect(typeBussiness).toHaveText('กรรมกร');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

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

View file

@ -0,0 +1,72 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { it } from 'node:test';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Delete Naturalperson', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ธนพล');
await page.waitForSelector('id=btn-kebab-delete-ธนพล');
await page.click('id=btn-kebab-delete-ธนพล');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
const itemLocator = await page.locator(
"//tr[contains(.,'นาย สุรวัฒน์ รุ่งเรือง') and contains (.,'--')]",
);
await expect(itemLocator).toBeHidden();
console.log('ระบบทำการลบนายจ้างบุคคลธรรมดาแล้ว ');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,125 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ปิดสถานะนายจ้างบุคคลธรรมดา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ยศพัฒน์');
await page.click('id=btn-kebab-status-ยศพัฒน์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'นาย ยศพัฒน์ ธนากานต์')and contains (.,'--')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะนายจ้างบุคคลธรรมดา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ยศพัฒน์');
await page.click('id=btn-kebab-status-ยศพัฒน์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'นาย ยศพัฒน์ ธนากานต์')and contains (.,'--')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgba(0, 0, 0, 0)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

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

View file

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

View file

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

View file

@ -0,0 +1,120 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
import { LOADIPHLPAPI } from 'dns';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการดูรายละเอียดนิติบุคคลโดยการคลิกไอคอนดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//button[@id='btn-eye-อนุชา ศรีสวัสดิ์'])[2]");
await page.waitForTimeout(2000);
const fullNamelegal = await page.locator(
"//div[@class='col column']//span[1]",
);
await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการดูรายละเอียดนิติบุคคลโดยการคลิกเมนูย่อย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-อนุชา ศรีสวัสดิ์');
await page.waitForSelector('id=btn-kebab-view-detail-อนุชา ศรีสวัสดิ์');
await page.click('id=btn-kebab-view-detail-อนุชา ศรีสวัสดิ์');
await page.waitForTimeout(2000);
const fullNamelegal = await page.locator(
"//div[@class='col column']//span[1]",
);
await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
await page.waitForTimeout(2000);
});
test('ทดสอบการดูรายละเอียดนิติบุคคลในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const isCardView = await page
.locator("(//div[@id='branch-card-undefined'])[2]")
.isVisible();
const fullNamelegal = await page.locator(
"//b[normalize-space(text())='บริษัท เอเชียเทค ซิสเต็มส์ จำกัด']",
);
await expect(isCardView).toBe(true);
await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
console.log('ระบบทำการเปลี่ยนรูปแบบเป็นการ์ดแล้ว');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,113 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการแก้ไขนายจ้างนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=btn-kebab-action-ณัฐวุฒิ เกียรติกุล');
await page.click('id=btn-kebab-action-ณัฐวุฒิ เกียรติกุล');
await page.waitForSelector('id=btn-kebab-edit-ณัฐวุฒิ เกียรติกุล');
await page.click('id=btn-kebab-edit-ณัฐวุฒิ เกียรติกุล');
// ส่วนเกี่ยวกับ
await page.fill(
'id=input-register-name',
'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด',
);
await page.fill(
'id=input-register-name-en',
'Siam Energy Solutions Co., Ltd.',
);
await page.fill('id=input-legal-person-no', 'ภาคิน วงศ์ศรีสุข');
await page.fill('id=input-authorized-capital', '15000000');
// ส่วนที่อยู่นายจ้าง
await page.click("(//div[@class='q-tab__label'])[4]");
await page.fill(
'id=info-input-address-no',
'123/45 อาคารเพิร์ล ทาวเวอร์ ชั้น 10',
);
await page.fill("(//input[@id='info-input-street'])[1]", 'พหลโยธิน');
await page.click('id=info-select-province');
await page.waitForSelector('id=info-select-province_0');
await page.click('id=info-select-province_0');
await page.click('id=info-select-district');
await page.waitForSelector('id=info-select-district_26');
await page.click('id=info-select-district_26');
await page.click('id=info-select-sub-district');
await page.waitForSelector('id=info-select-sub-district_1');
await page.click('id=info-select-sub-district_1');
await page.fill(
'id=info-input-address-en',
'123/45 Pearl Tower, 10th Floor',
);
await page.fill("(//input[@id='info-input-street'])[2]", 'Phahonyothin');
await page.waitForSelector("//button[@type='submit']");
await page.click("//button[@type='submit']");
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-info-close');
await page.click('id=btn-info-close');
await page.waitForTimeout(2000);
const legalAfterEdit = await page.locator(
"//tr[contains(.,'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด') and contains (.,'022022000')]",
);
await expect(legalAfterEdit).toContainText(
'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด',
);
await expect(legalAfterEdit).toContainText('022022000');
console.log('ระบบทดสอบการแก้ไขสำเร็จ');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,72 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { it } from 'node:test';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('Delete Legalentitly', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ภาคิน วงศ์ศรีสุข');
await page.waitForSelector('id=btn-kebab-delete-ภาคิน วงศ์ศรีสุข');
await page.click('id=btn-kebab-delete-ภาคิน วงศ์ศรีสุข');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
const itemLocator = await page.locator(
"//tr[contains(.,'บริษัท สยาม เอ็นเนอร์จี โซลูชั่น จำกัด') and contains (.,'022022000')]",
);
await expect(itemLocator).toBeHidden();
console.log('ระบบทำการลบนายจ้างนิติบุคคลแล้ว');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,122 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ปิดสถานะนายจ้างนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-อนุชา ศรีสวัสดิ์');
await page.click('id=btn-kebab-status-อนุชา ศรีสวัสดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด') and contains (.,'022022002')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะนายจ้างนิติบุคคล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-อนุชา ศรีสวัสดิ์');
await page.click('id=btn-kebab-status-อนุชา ศรีสวัสดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด') and contains (.,'022022002')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

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

View file

@ -0,0 +1,102 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการค้นหาข้อมูลเมนูลูกค้า', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// กำหนดคำที่จะค้นหา
const searchDatas = [
'Yossapat',
'ยศพัฒน์ ธนากานต์',
'AsiaTech Systems Co., Ltd',
'Systems',
'Tanakarn',
];
for (const searchData of searchDatas) {
// พิมพ์คำที่ต้องการค้นหา
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
await page.waitForTimeout(2000);
// ดึงผลลัพฑ์การค้นหาทั้งหมด
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
const resultCount = await searchResults.count();
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
if (resultCount === 0) {
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
continue; // ข้ามคำค้นหาคำถัดไป
}
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
const searchResultTexts = await searchResults.allTextContents();
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
const allResultContainSearchData = searchResultTexts.every((result) =>
result.includes(searchData),
);
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
if (!allResultContainSearchData) {
console.error(
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
);
continue; // ข้ามไปคำค้นหาถัดไป
}
expect(allResultContainSearchData).toBe(true);
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,113 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกค้า
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด นายจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.waitForTimeout(1000);
await page.click('id=select-status');
//รอให้ dropdown เปิด
await page.waitForSelector('id=select-status_1');
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});

View file

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

View file

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

View file

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

View file

@ -0,0 +1,105 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการค้นหาข้อมูลเมนูลูกค้า', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// กำหนดคำที่จะค้นหา
const searchDatas = [
'Kittisak',
'Sukkasem',
'กิตติศักดิ์ วิจิตรานนท์',
'Waranya Sukkasem',
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด',
'1524428220420-00',
];
for (const searchData of searchDatas) {
// พิมพ์คำที่ต้องการค้นหา
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
await page.waitForTimeout(2000);
// ดึงผลลัพฑ์การค้นหาทั้งหมด
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
const resultCount = await searchResults.count();
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
if (resultCount === 0) {
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
continue; // ข้ามคำค้นหาคำถัดไป
}
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
const searchResultTexts = await searchResults.allTextContents();
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
const allResultContainSearchData = searchResultTexts.every((result) =>
result.includes(searchData),
);
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
if (!allResultContainSearchData) {
console.error(
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
);
continue; // ข้ามไปคำค้นหาถัดไป
}
expect(allResultContainSearchData).toBe(true);
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
}
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,115 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงสถานะใช้งาน เปิด/ปิด ลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.waitForTimeout(1000);
await page.click('id=select-status');
//รอให้ dropdown เปิด
await page.waitForSelector('id=select-status_1');
// คลิกเพื่อแสดงสถานะกำลังใช้งานอยู่
await page.click('id=select-status_1');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะใช้งานหรือไม่
const statusActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะกำลังใช้งานเท่านั้น');
// แสดงสถานะที่ไม่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะกำลังไม่ใช้งาน
await page.click('id=select-status_2');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่ามีแต่สถานะไม่ใช้งานหรือไม่
const statusInActive = await page.isVisible('id=select-status_1');
console.log('มีเพียงสถานะการใช้งานเท่านั้น', statusInActive); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะการใช้งานมีแต่สถานะที่ไม่ใช้งาน');
// แสดงสถานะทั้งหมด
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
await page.click('id=select-status');
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
// คลิกเพื่อแสดงสถานะทั้งหมด
await page.click('id=select-status_0');
await page.waitForTimeout(1000); // รอให้ UI อัปเดต
// ตรวจสอบว่าแสดงทุกสถานะหรือไม่
const statusAll = await page.isVisible('id=select-status_1');
console.log('สถานะทั้งหมด', statusAll); // เช็ค
expect(statusActive).toBe(false);
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -0,0 +1,112 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการดูรายละเอียดลูกจ้างโดยการคลิกไอคอนดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-eye-กิตติศักดิ์');
const fullNameEmployee = await page.locator(
"//span[text()='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบตรวจสอบรายละเอียดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click("(//button[@id='btn-info-close'])[2]");
await page.waitForTimeout(1000);
});
test('ทดสอบการดูรายละเอียดลูกจ้างโดยการคลิกเมนูย่อย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-กิตติศักดิ์');
await page.waitForSelector('id=btn-kebab-view-detail-กิตติศักดิ์');
await page.click('id=btn-kebab-view-detail-กิตติศักดิ์');
const fullNameEmployee = await page.locator(
"//span[text()='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบตรวจสอบรายละเอียดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click("(//button[@id='btn-info-close'])[2]");
await page.waitForTimeout(1000);
});
test('ทดสอบการดูรายละเอียดลูกจ้างในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const fullNameEmployee = await page.locator(
"//div[normalize-space(text())='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบทำการเปลี่ยนเป็นรูปแบบการ์ดแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(1000);
});

View file

@ -0,0 +1,93 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการแก้ไขลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-วรัญญา');
await page.waitForSelector('id=btn-kebab-edit-วรัญญา');
await page.click('id=btn-kebab-edit-วรัญญา');
await page.click(
"(//div[contains(@class,'q-field__append q-field__marginal')]//i)[3]",
);
await page.waitForSelector(
'id=drawer-info-employee-select-employer-branch_1',
);
await page.click('id=drawer-info-employee-select-employer-branch_1');
await page.fill(
"(//input[@id='drawer-info-employee-input-first-name'])[1]",
'พิชญา',
);
await page.fill('id=drawer-info-employee-input-last-name', 'วัฒนธนากุล');
await page.fill('id=drawer-info-employee-input-first-name-en', 'Pichaya');
await page.fill(
'id=drawer-info-employee-input-last-name-en',
'Watthanathanakul',
);
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(1000);
await page.click("(//button[@id='btn-info-close'])[2]");
const rowItemName = await page.locator(
"//tr[contains(.,'Pichaya Watthanathanakul') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
await expect(rowItemName).toContainText('Pichaya Watthanathanakul');
await expect(rowItemName).toContainText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด');
console.log('ระบบทำการแก้ไขลูกจ้างแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,125 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { it } from 'node:test';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกืดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('จำลองการสร้างลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForTimeout(2000);
// ส่วนข้อมูลพื้นฐาน
await page.click('id=form-employee-select-employer-branch');
await page.waitForSelector('id=form-employee-select-employer-branch_1');
await page.click('id=form-employee-select-employer-branch_1');
await page.fill('id=form-employee-input-nrc-no', '2822022820228');
// ส่วนข้้อมูลส่วนตัว
await page.click('id=form-employee-select-prefix-name');
await page.waitForSelector('id=form-employee-select-prefix-name_0');
await page.click('id=form-employee-select-prefix-name_0');
await page.fill(
"(//input[@id='form-employee-input-first-name'])[1]",
'ธนกร',
);
await page.fill('id=form-employee-input-last-name', 'ศรีสวัสดิ์');
await page.fill('id=form-employee-input-first-name-en', 'Thanakorn');
await page.fill('id=form-employee-input-last-name-en', 'Srisawat');
// วันเดิิอนปีเกิด
await page.click('id=form-employee-input-birth-date');
await page.waitForSelector(
"(//button[@class='dp__btn dp__month_year_select'])[2]",
);
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='1992']");
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
await page.click("//div[text()='พ.ค.']");
await page.click("//div[@id='1992-05-02']/div[1]");
// สัญชาติ
await page.click('id=form-employee-select-nationality');
await page.waitForSelector('id=form-employee-select-nationality_2');
await page.click('id=form-employee-select-nationality_2');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
await page.waitForTimeout(2000);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('ทดสอบการลบลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ธนกร');
await page.waitForSelector('id=btn-kebab-delete-ธนกร');
await page.click('id=btn-kebab-delete-ธนกร');
await page.waitForSelector('id=btn-ok-dialog');
await page.click('id=btn-ok-dialog');
const itemLocator = await page.locator(
"//tr[contains(.,'Thanakorn Srisawat') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
await expect(itemLocator).toBeHidden();
console.log('ระบบทำการลบลูกจ้างแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,124 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูลูกจ้าง
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-customer');
await page.click('id=sub-menu-customer');
await page.waitForSelector('id=tab-employee');
await page.click('id=tab-employee');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ปิดสถานะลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-กิตติศักดิ์');
await page.click('id=btn-kebab-status-กิตติศักดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'Kittisak Wijitranon') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะลูกจ้าง', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-กิตติศักดิ์');
await page.click('id=btn-kebab-status-กิตติศักดิ์', {
force: true,
});
await page.click('id=btn-ok-dialog');
console.log('เปลี่ยนสถานะสำเร็จ');
// รอ Update
await page.waitForTimeout(2000);
console.log('สถานะถูกเปลี่ยนแล้ว');
// ตรวจสอบสีของแถวหลังจากทำการเปลี่ยนสถานะ
const rowLocator = page.locator(
"//tr[contains(.,'Kittisak Wijitranon') and contains (.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด')]",
);
const backgroundColor = await rowLocator.evaluate(
(el) => window.getComputedStyle(el).backgroundColor,
);
// กำหนดสีหลัเปลี่ยนสถานะการใช้งาน
const expectedColor = 'rgb(249, 250, 252)';
// ตรวจสอบสีที่เปลี่ยนไป
expect(backgroundColor.trim()).toBe(expectedColor);
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

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

View file

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

View file

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

View file

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

View file

@ -3,6 +3,7 @@ import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,24 +15,42 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกืดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ทดสอบการเพิ่มกลุ่มสินค้าและบริการ', async () => {
await page.click('id=menu-icon-product-service');
if (!isLoginSuccessful) {
await login(page);
}
try {
// เพิ่มกลุ่มสินค้าและบริการ
await page.click('id=btn-add');
await page.click('id=btn-add-product-group');
// กรอกข้อมูลกลุ่มสินค้าและบริการ
// await page.click("(//i[@aria-hidden='false'])[2]");
@ -44,7 +63,7 @@ test('ทดสอบการเพิ่มกลุ่มสินค้า
await page.fill("(//textarea[@id='input-remark'])[2]", 'หมายเหตุประกัน');
// บันทึกการสร้างกลุ่มสินค้นและบริการ
await page.click('id=btn-form-submit');
await page.click('id=btn-info-basic-save');
// ตรวจสอบหลังทำการสร้างกลุ่มสินค้าและบริการ
const newProductAndServiceLocator = page.locator(
@ -67,6 +86,7 @@ test('ทดสอบการเพิ่มกลุ่มสินค้า
}
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
isLoginSuccessful = false;
throw error;
}

View file

@ -0,0 +1,75 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกืดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มกลุ่มสินค้าและบริการในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
const nameProductGroupandService = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(nameProductGroupandService).toHaveText(
'This field is required.',
);
console.log('ระบบทำการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,69 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มกลุ่มสินค้าและบริการในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-add');
await page.waitForSelector('id=btn-info-basic-save');
await page.click('id=btn-info-basic-save');
const nameProductGroupandService = await page.locator(
"//div[@class='q-field__messages col']//div[1]",
);
await expect(nameProductGroupandService).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
console.log('ระบบทำการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,96 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มสินค้า', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
await page.waitForSelector('id=tree-enter-สินค้าและบริการ-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
await page.click('id=btn-add');
// ส่วนข้อมูลพื้นฐาน
await page.click("(//input[@id='select-br-id'])[1]");
await page.waitForSelector('id=select-br-id_0');
await page.click('id=select-br-id_0');
await page.fill(
"(//input[@id='input-name'])[2]",
'ชื่อกลุ่มสินค้าและบริการ',
);
await page.click("(//input[@id='select-br-id'])[2]");
await page.waitForSelector('id=select-br-id_0');
await page.click('id=select-br-id_0');
// ส่วนข้อมูลราคา
await page.click("(//div[@role='listitem'])[2]");
await page.fill('id=input-price', '2000');
await page.fill('id=input-agent-price', '2000');
await page.fill('id=input-service-charge', '2000');
// ส่วนข้อมูลเอกสาร
await page.click('id=btn-info-basic-save');
const productCheck = await page.locator(
"//tr[contains(.,'ชื่อกลุ่มสินค้าและบริการ') and contains (.,'฿2,000.00')]",
);
await expect(productCheck).toContainText('ชื่อกลุ่มสินค้าและบริการ');
await expect(productCheck).toContainText('฿2,000.00');
console.log('ระบบทำการสร้างสินค้าถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,87 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
// เปลี่ยนภาษา
await page.click('id=btn-change-language');
await page.waitForSelector('id=btn-change-language-eng');
await page.click('id=btn-change-language-eng');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มสินค้าในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
await page.waitForSelector('id=tree-enter-Products and Services-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-Products and Services-ประกัน');
await page.click('id=btn-add');
await page.click('id=btn-info-basic-save');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const ProduceandSeviceCodeError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameProduceandSeviceError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(ProduceandSeviceCodeError).toHaveText(
'This field is required.',
);
await expect(nameProduceandSeviceError).toHaveText(
'This field is required.',
);
console.log('ระบบแสดงการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,82 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มสินค้าในกรณีที่ไม่กรอกข้อมูล', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
await page.waitForSelector('id=tree-enter-สินค้าและบริการ-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
await page.click('id=btn-add');
await page.click('id=btn-info-basic-save');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const ProduceandSeviceCodeError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameProduceandSeviceError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(ProduceandSeviceCodeError).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
await expect(nameProduceandSeviceError).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
console.log('ระบบแสดงการแจ้งเตือนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,108 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-productService');
await page.click('id=sub-menu-productService');
await page.waitForTimeout(2000);
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ทดสอบการเพิ่มประเภท', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
// เข้าสู่หน้าประเภท
await page.waitForSelector('id=tree-enter-แพ็คเกจ-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-แพ็คเกจ-ประกัน');
await page.click('id=btn-add');
// ส่วนข้อมูลแพ็คเกจ
await page.fill('id=input-service-code', 'MOU');
await page.fill('id=input-service-name', 'ประกันภัยแบบกลุ่ม');
await page.fill('id=input-service-description', 'รายละเอียดประภัยแบบกลุ่ม');
// ส่วนข้อมูลงาน
await page.click("(//div[@role='listitem']//div)[2]");
await page.waitForSelector("(//button[@id='btn-add-work'])[1]");
await page.click("(//button[@id='btn-add-work'])[1]");
// เพิ่มชื่องาน
await page.click("//div[@for='select-work-name-1']");
await page.waitForSelector("//button[contains(.,'จัดการ')]");
await page.click("//button[contains(.,'จัดการ')]");
await page.waitForSelector("//span[normalize-space(text())='เพิ่มงาน']");
await page.click("//span[normalize-space(text())='เพิ่มงาน']");
await page.fill('id=input-work-name-2', 'อักคคีภัย');
await page.waitForSelector('id=btn-save-work-name');
await page.click('id=btn-save-work-name');
await page.click("(//button[@id='btn-form-close'])[2]");
await page.waitForSelector("//div[@for='select-work-name-1']");
await page.click("//div[@for='select-work-name-1']");
await page.waitForSelector("//div[normalize-space(text())='อัคคีภัย']");
await page.click("//div[normalize-space(text())='อัคคีภัย']");
// เพิ่มสินค้า
await page.click("(//button[@id='btn-add-work-product'])[2]");
await page.waitForSelector("//div[text()='ชื่อกลุ่มสินค้าและบริการ']");
await page.click("//div[text()='ชื่อกลุ่มสินค้าและบริการ']");
await page.click('id=btn-form-submit');
// ขั้นตอนการทำงาน
await page.click("(//button[@id='btn-add-work-product']//span)[2]");
await page.click('id=select-workflow');
const propertiesServiceRecordName = page.locator(
"//span[normalize-space(text())='บันทึกบริการ_Name']",
);
expect(propertiesServiceRecordName).toHaveText('บันทึกบริการ_Name');
console.log(propertiesServiceRecordName, 'เลือกdropdown แล้ว');
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -3,6 +3,7 @@ import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,27 +15,42 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
await page.click('id=menu-icon-product-service');
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
// เข้าสู่หน้าประเภท
await page.waitForSelector('id=tree-enter-ประเภท-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-ประเภท-ประกัน');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ทดสอบการเพิ่มประเภท', async () => {
await page.click('id=menu-icon-product-service');
await page.waitForSelector('id=tree-enter-ประกัน', { state: 'visible' });
await page.click('id=tree-enter-ประกัน');
// เข้าสู่หน้าประเภท
await page.waitForSelector('id=tree-enter-ประเภท-ประกัน', {
state: 'visible',
});
await page.click('id=tree-enter-ประเภท-ประกัน');
if (!isLoginSuccessful) {
await login(page);
}
try {
// เพิ่มประเภท
await page.click('id=btn-add');
@ -53,6 +69,7 @@ test('ทดสอบการเพิ่มประเภท', async () => {
await expect(nameTypeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
isLoginSuccessful = false;
throw error;
}

View file

@ -1,9 +1,10 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual, throws } from 'assert';
import { error, log } from 'console';
import { date } from 'quasar';
import { date, is } from 'quasar';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -15,20 +16,36 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
await page.click('id=menu-icon-product-service');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกืดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ดูรายละเอียดกลุ่มสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=menu-icon-product-service');
await page.click('id=btn-eye-ประกัน');
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
@ -39,6 +56,7 @@ test('ดูรายละเอียดกลุ่มสินค้าแ
console.log('ตรวจสอบข้อมูลกลุ่มสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
@ -46,6 +64,9 @@ test('ดูรายละเอียดกลุ่มสินค้าแ
});
test('ดูรายละเอียดกลุ่มสินค้าและบริการ ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประกัน');
await page.click('id=btn-kebab-view-detail-ประกัน');
@ -58,6 +79,7 @@ test('ดูรายละเอียดกลุ่มสินค้าแ
console.log('ตรวจสอบข้อมูลกลุ่มสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
@ -65,6 +87,9 @@ test('ดูรายละเอียดกลุ่มสินค้าแ
});
test('ดูรายละเอียดประเภทของสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.reload();
await page.click('id=tree-enter-ประกัน');
@ -81,6 +106,7 @@ test('ดูรายละเอียดประเภทของสิน
console.log('ตรวจสอบข้อมูลประเภทของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
@ -88,6 +114,9 @@ test('ดูรายละเอียดประเภทของสิน
});
test('ดูรายละเอียดประเภทของสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-ประเภท-ประกัน');
@ -104,6 +133,7 @@ test('ดูรายละเอียดประเภทของสิน
console.log('ตรวจสอบข้อมูลประเภทของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
@ -111,6 +141,9 @@ test('ดูรายละเอียดประเภทของสิน
});
test('ดูรายละเอียดสินค้าและบริการของสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
@ -126,6 +159,7 @@ test('ดูรายละเอียดสินค้าและบริ
console.log('ตรวจสอบข้อมูลสินค้าและบริการของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
@ -133,6 +167,9 @@ test('ดูรายละเอียดสินค้าและบริ
});
test('ดูรายละเอียดสินค้าและบริการของสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกัน');
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
@ -149,6 +186,7 @@ test('ดูรายละเอียดสินค้าและบริ
console.log('ตรวจสอบข้อมูลสินค้าและบริการของสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);

View file

@ -1,10 +1,11 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual, throws } from 'assert';
import { error, log } from 'console';
import { date } from 'quasar';
import { date, is } from 'quasar';
import { Card } from 'react-bootstrap';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -16,19 +17,35 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
await page.click('id=menu-icon-product-service');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ทดสอบการแก้ไขกลุ่มสินค้าและบริการ', async () => {
await page.click('id=menu-icon-product-service');
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประกัน');
await page.click('id=btn-kebab-edit-ประกัน');
@ -46,12 +63,16 @@ test('ทดสอบการแก้ไขกลุ่มสินค้า
);
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการแก้ไขประเภทสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-ประกันทั้งหมด', {
state: 'visible',
@ -79,12 +100,16 @@ test('ทดสอบการแก้ไขประเภทสินค้
console.log('การตรวจสอบการแก้ไขชื่อประเภทสินค้าและบริการถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ทดสอบการแก้ไขสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector('id=tree-enter-สินค้าและบริการ-ประกันทั้งหมด', {
state: 'visible',
@ -105,6 +130,7 @@ test('ทดสอบการแก้ไขสินค้าและบร
console.log('การตรวจสอบการแก้ไขชื่อสินค้าและบริการถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -1,9 +1,10 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual, throws } from 'assert';
import { error, log } from 'console';
import { date } from 'quasar';
import { date, is } from 'quasar';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -15,22 +16,37 @@ test.afterAll(async () => {
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ตรวจสอบการแสดงผลสถานะการใช้งาน เปิด/ปิด สินค้าและบริการ', async () => {
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// คลิกเมนูเพื่อเข้าสู่หน้าสินค้าและบริการ
await page.click('id=menu-icon-product-service');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงผลสถานะการใช้งาน เปิด/ปิด สินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// แสดงสถานะที่ใช้งาน
// คลิกเพื่อเปิด dropdown
await page.click('id=select-status');
@ -88,6 +104,7 @@ test('ตรวจสอบการแสดงผลสถานะการ
console.log('ตรวจสอบสถานะทั้งหมด');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}

View file

@ -4,6 +4,7 @@ import { watchFile } from 'fs';
import { waitForDebugger } from 'inspector';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -15,22 +16,37 @@ test.afterAll(async () => {
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ', async () => {
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
// คลิกเมนูเพื่อเข้าสู่หน้าสินค้าและบริการ
await page.click('id=menu-icon-product-service');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
await login(page);
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลลำดับ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.click("(//input[@id='select-field'])[1]");
await page.waitForTimeout(1000); // รอให้ dropdown เปิด
@ -80,6 +96,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -87,6 +104,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลชื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -138,6 +158,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -145,6 +166,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลรายละเอียด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -198,6 +222,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -205,6 +230,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลหมายเหตุ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -258,6 +286,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}
@ -265,6 +294,9 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
});
test('ตรวจสอบการแสดงผลฟิลด์แสดงผลสร้างเมื่อ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
// คลิกเพื่อเปิด dropdown
await page.keyboard.press('Escape');
@ -318,6 +350,7 @@ test('ตรวจสอบการแสดงผลฟิลด์แสด
console.log('ตรวจสอบการเปิด/ซ่อนคอลัมน์ในตารางสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ:', error);
isLoginSuccessful = false;
throw error;
}

View file

@ -2,6 +2,7 @@ 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();
@ -13,21 +14,37 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
await page.click('id=menu-icon-product-service');
await page.click('id=tree-enter-ประกันทั้งหมด');
await page.click('id=tree-enter-สินค้าและบริการ-ประกันทั้งหมด');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('ปิดสถานะการใช้งานสินค้าและบริการ', async () => {
await page.click('id=menu-icon-product-service');
await page.click('id=tree-enter-ประกันทั้งหมด');
await page.click('id=tree-enter-สินค้าและบริการ-ประกันทั้งหมด');
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประเภทบุคคล');
@ -58,12 +75,16 @@ test('ปิดสถานะการใช้งานสินค้าแ
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-ประเภทบุคคล');
@ -94,14 +115,18 @@ test('เปิดสถานะการใช้งานสินค้า
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ปิดสถานะการใช้งานประเภทสินค้าและบริการ', async () => {
await page.click('id=tree-enter-ประเภท-ประกันทั้งหมด');
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประเภท-ประกันทั้งหมด');
await page.click('id=btn-kebab-action-ประกันชีวิต');
await page.click('id=btn-kebab-status-ประกันชีวิต', {
@ -131,12 +156,16 @@ test('ปิดสถานะการใช้งานประเภทส
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-ประกันชีวิต', {
@ -166,14 +195,18 @@ test('เปิดสถานะการใช้งานประเภท
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('ปิดสถานะการใช้งานกลุ่มสินค้าและบริการ', async () => {
await page.click('id=tree-enter-ประกันทั้งหมด');
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-ประกันทั้งหมด');
await page.click("(//button[@id='btn-kebab-action-ประกันทั้งหมด'])[2]");
await page.click('id=btn-kebab-status-ประกันทั้งหมด', {
@ -203,12 +236,16 @@ test('ปิดสถานะการใช้งานกลุ่มสิ
console.log('สีของแถวถูกเปลี่ยนเป็นสีเทาอ่อน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);
});
test('เปิดสถานะการใช้งานกลุ่มสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click("(//button[@id='btn-kebab-action-ประกันทั้งหมด'])[2]");
await page.click('id=btn-kebab-status-ประกันทั้งหมด', {
@ -238,6 +275,7 @@ test('เปิดสถานะการใช้งานกลุ่มส
console.log('สีของแถวถูกเปลี่ยนเป็นของสถานะการใช้งาน');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ');
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(2000);

View file

@ -3,6 +3,7 @@ import { strictEqual } from 'assert';
import { it } from 'node:test';
let page: Page;
let isLoginSuccessful = false;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@ -14,18 +15,33 @@ test.afterAll(async () => {
}
});
async function login(page) {
try {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
isLoginSuccessful = true;
console.log('Login สำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการ Login', error);
isLoginSuccessful = false;
}
}
test('Login', async () => {
// 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 login(page);
});
test('จำลองการสร้างสินค้าและบริการเพิื่อทำการทดสอบลบ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
//-----------------------------------------สร้างกลุ่มสินค้าและบริการ------------------------------//
await page.click('id=menu-icon-product-service');
@ -168,6 +184,9 @@ test('จำลองการสร้างสินค้าและบร
});
test('ทดสอบการลบประเภทสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-ประเภทสินค้าและบริการ');
await page.click('id=btn-kebab-delete-ประเภทสินค้าและบริการ');
@ -182,11 +201,15 @@ test('ทดสอบการลบประเภทสินค้าแล
console.log('ตรวจสอบการลบประเภทสินค้าและบริการสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});
test('ทดสอบการลบสินค้าและบริการ', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=tree-enter-สินค้าและบริการ-กลุ่มสินค้าและบริการ');
await page.click('id=btn-kebab-action-สินค้าและบริการ');
@ -202,6 +225,7 @@ test('ทดสอบการลบสินค้าและบริกา
console.log('ตรวจสอบการลบสินค้าและบริการสำเร็จ');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
});

View file

@ -1,5 +1,6 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
@ -24,10 +25,15 @@ test('Login', async () => {
// await page.click('id=acceptBtn');
});
test('View Detail Legalentitly', async () => {
await page.click('id=menu-icon-customer-management');
await page.click("//button[@id='btn-dots-CORP000002']");
await page.click('id=view-detail-btn-undefined-view');
test('ทดสอบการเพิ่มขั้นตอนการทำงาน', async () => {
// เข้าสู่เมนูสินค้าและบริการ
await page.click('id=menu.manage');
await page.waitForSelector('id=sub-menu-workflow');
await page.click('id=sub-menu-workflow');
await page.waitForTimeout(2000);
await page.waitForSelector('id=btn-Add');
await page.click('id=btn-Add');
// ส่วนชื่อแม่แบบ
});

View file

@ -1,793 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Create Personnel พนักงาน ชาย', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'employeem');
await page.click('id=select-user-type');
await page.click('id=select-user-type_0');
await page.click('id=select-user-role');
await page.click('id=select-user-role_2');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธรรมรงด์');
await page.fill('id=form-dialog-personnel-input-last-name', 'ดำรงธรรม');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thamrong');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Dumrongtum');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeem@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-17']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
await page.waitForSelector;
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธรรมรงด์ ดำรงธรรม']",
);
const displayName = (await displayNameLocator.textContent())?.trim() || '';
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธรรมรงด์ ดำรงธรรม');
console.log(displayName);
console.log('ตรวจสอบการสร้างพนักงานชายถูกต้อง');
});
test('Create Personnel พนักงาน หญิง', async () => {
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'employeew');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'อารยา');
await page.fill('id=form-dialog-personnel-input-last-name', 'มาลา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Araya');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Mala');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-16']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='อารยา มาลา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('อารยา มาลา');
console.log('ตรวจสอบการสร้างพนักงานหญิงถูกต้อง');
});
test('Create Personnel พนักงานส่งเอกสาร หญิง', async () => {
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'courierw');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'มาตา');
await page.fill('id=form-dialog-personnel-input-last-name', 'ลดา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Mata');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Lada');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-15']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='มาตา ลดา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('มาตา ลดา');
console.log('ตรวจสอบการสร้างพนักงานส่งเอกสารหญิงถูกต้อง');
});
test('Create Personnel พนักงานส่งเอกสาร ชาย', async () => {
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'courierm');
await page.click('id=select-user-role');
await page.click('id=select-user-role_6');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธันวา');
await page.fill('id=form-dialog-personnel-input-last-name', 'มานา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thanwa');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Mana');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-14']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-regis-no', '2822282222421');
await page.click('id=input-start-date');
await page.click("//div[text()='11']");
await page.click('id=input-retire-date');
await page.click("//div[text()='21']");
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธันวา มานา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธันวา มานา');
console.log('ตรวจสอบการสร้างพนักงานส่งเอกสารชายถูกต้อง');
});
test('Create Personnel ตัวแทน ชาย', async () => {
await page.click("(//div[@role='tab'])[4]");
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'delegatem');
await page.click('id=select-user-role');
await page.click('id=select-user-role_8');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'อาคม');
await page.fill('id=form-dialog-personnel-input-last-name', 'พลัง');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Akom');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Palang');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-13']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-discount-condition', 'ทดสอบข้อมูลการทำงาน');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='อาคม พลัง']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('อาคม พลัง');
console.log('ตรวจสอบการสร้างตัวแทนชายถูกต้อง');
});
test('Create Personnel ตัวแทน หญิง', async () => {
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'delegatew');
await page.click('id=select-user-role');
await page.click('id=select-user-role_10');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'สโรชา');
await page.fill('id=form-dialog-personnel-input-last-name', 'มีนา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Sarocha');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Mena');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-12']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.fill('id=input-discount-condition', 'ทดสอบข้อมูลการทำงาน');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='สโรชา มีนา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('สโรชา มีนา');
console.log('ตรวจสอบการสร้างตัวแทนหญิงถูกต้อง');
});
test('Create Personnel เอเจนซี่ หญิง', async () => {
await page.click("(//div[@role='tab'])[5]");
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'agencyw');
await page.click('id=select-user-role');
await page.click('id=select-user-role_2');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'ธิดา');
await page.fill('id=form-dialog-personnel-input-last-name', 'งามตา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Thida');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Yamta');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='หญิง']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-11']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.click('id=input-source-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=input-import-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=select-trainig-place');
await page.click("//span[text()='สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก']");
await page.fill('id=input-checkpoint', 'แม่สอด');
await page.fill('id=input-checkpoint-en', 'Maesod');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='ธิดา งามตา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('ธิดา งามตา');
console.log('ตรวจสอบการสร้างเอเจนซี่หญิงถูกต้อง');
});
test('Create Personnel เอเจนซี่ ชาย', async () => {
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกข้อมูลพื้นฐานของบุคคลากร
await page.click("//i[@aria-hidden='false']");
await page.waitForSelector('id=select-hq-id', {
state: 'visible',
});
await page.click('id=select-hq-id');
await page.click("//span[normalize-space(text())='CMO00000']");
await page.waitForSelector('id=select-br-id', { state: 'visible' });
await page.click('id=select-br-id');
await page.click('id=select-br-id_4');
await page.fill('id=input-username', 'agencym');
await page.click('id=select-user-role');
await page.click('id=select-user-role_8');
// await page.click("//div[@role='option']");
// กรอกชื่อข้อมูลพื้นฐาน
await page.fill('id=input-citizen-id', '1282262422820');
await page.click("//label[@for='form-dialog-personnel-select-prefix-name']");
await page.click('id=form-dialog-personnel-select-prefix-name_0');
await page.fill('id=form-dialog-personnel-input-first-name', 'อันดา');
await page.fill('id=form-dialog-personnel-input-last-name', 'ธรรมา');
await page.fill('id=form-dialog-personnel-input-first-name-en', 'Aunda');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'Thamma');
await page.fill('id=form-dialog-personnel-input-telephone', '08422622282');
await page.fill('id=form-dialog-personnel-input-email', 'employeew@mail.com');
// เลือกเพศ
await page.click('id=form-dialog-personnel-select-gender');
await page.click("//span[text()='ชาย']");
// เลือกวันเกิด
await page.click('id=form-dialog-personnel-input-birth-date');
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
await page.click("//div[text()='2561']");
await page.click("//div[text()='8']");
// วันออกบัตร วันที่หมออายุ
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-issue'])[1]",
);
await page.click("//div[@id='2024-09-02']");
await page.click(
"(//input[@id='form-dialog-personnel-input-citizen-expire'])[1]",
);
await page.click("//div[@id='2024-09-10']/div[1]");
// กรอกที่อยู่
await page.fill('id=drawer-info-personnel-input-address-no', '20/1');
await page.click('id=drawer-info-personnel-select-province');
await page.waitForSelector('id=drawer-info-personnel-select-province_6', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-province_6');
await page.click('id=drawer-info-personnel-select-district');
await page.waitForSelector('id=drawer-info-personnel-select-district_2', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-district_2');
await page.click('id=drawer-info-personnel-select-sub-district');
await page.waitForSelector('id=drawer-info-personnel-select-sub-district_1', {
state: 'visible',
});
await page.click('id=drawer-info-personnel-select-sub-district_1');
// กรอกที่อยู่ภาษาอังกฤษ
await page.fill('id=drawer-info-personnel-input-address-en', '20/01');
// กรอกข้อมูลการทำงาน
await page.click('id=input-source-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=input-import-nationality');
await page.click("(//div[@role='option'])[1]");
await page.click('id=select-trainig-place');
await page.click("//span[text()='สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก']");
await page.fill('id=input-checkpoint', 'แม่สอด');
await page.fill('id=input-checkpoint-en', 'Maesod');
// กดปุ่มเพื่อสร้างบุคคลากร
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
// ดึงข้อมูลจาก Locator และนำ .textContent() เพื่อดึงมาแต่ข้อความจริง ๆ
const displayNameLocator = page.locator(
"//div[normalize-space(text())='อันดา ธรรมา']",
);
const displayName = (await displayNameLocator.textContent())?.trim();
// ตรวจสอบข้อมูลที่ดึงออกมา
expect(displayName).toBe('อันดา ธรรมา');
console.log('ตรวจสอบการสร้างเอเจนซี่ชายถูกต้อง');
});

View file

@ -1,128 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import exp from 'constants';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Create Personnel - ในกรณีที่ไม่กรอกข้อมูล', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
await page.click('id=btn-info-basic-save');
await page.waitForTimeout(2000);
const usernameError = page.locator("(//div[@role='alert'])[1]");
const userTypeError = page.locator("(//div[@role='alert'])[2]");
const userPermisionError = page.locator("(//div[@role='alert'])[3]");
const citizenIdError = page.locator("(//div[@role='alert'])[4]");
const firstNameError = page.locator("(//div[@role='alert'])[5]");
const lastNameError = page.locator("(//div[@role='alert'])[6]");
const firstNameEnError = page.locator("(//div[@role='alert'])[7]");
const lastNameEnError = page.locator("(//div[@role='alert'])[8]");
const brithDateError = page.locator("(//div[@role='alert'])[9]");
const citizenIdInError = page.locator("(//div[@role='alert'])[10]");
const addressError = page.locator("(//div[@role='alert'])[11]");
const provinceError = page.locator("(//div[@role='alert'])[12]");
const districtError = page.locator("(//div[@role='alert'])[13]");
const subDistrictErrorError = page.locator("(//div[@role='alert'])[14]");
const addressEnErrorError = page.locator("(//div[@role='alert'])[15]");
await expect(usernameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(userTypeError).toHaveText('โปรดเลือกประเภทผู้ใช้งาน');
await expect(userPermisionError).toHaveText('โปรดเลือกสิทธิ์ผู้ใช้งาน');
await expect(citizenIdError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(firstNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(lastNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(firstNameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(lastNameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(brithDateError).toHaveText('โปรดเลือกวันเดือนปีเกิด');
await expect(citizenIdInError).toHaveText('โปรดเลือกวันที่ออกบัตร');
await expect(addressError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(provinceError).toHaveText('โปรดเลือกจังหวัด');
await expect(districtError).toHaveText('โปรดเลือกอำเภอ');
await expect(subDistrictErrorError).toHaveText('โปรดเลือกตำบล');
await expect(addressEnErrorError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
});
test('Create Personnel - ในกรณีที่กรอกชื่อผู้ใช้งานที่ไม่ตรงกับตัวอักษรที่กำหนด', async () => {
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=input-username', 'ทดสอบ');
const usernameError = page.locator("(//div[@role='alert'])[1]");
await expect(usernameError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
);
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
});
test('Create Personnel - ในกรณีที่กรอกชื่อและนามสกุลภาษาอังกฤษไม่ตรงตามรูปแบบ', async () => {
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=form-dialog-personnel-input-first-name-en', 'ทดสอบ');
await page.fill('id=form-dialog-personnel-input-last-name-en', 'ทดสอบ');
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
const lastNameEnError = page.locator("(//div[@role='alert'])[2]");
await expect(firstNameEnError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
await expect(lastNameEnError).toHaveText(
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
);
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
});
test('Create Personnel - ในกรณีที่กรอกอีเมลไม่ตรงรูปแบบ', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click('id=btn-add');
await page.click('id=btn-add-personne');
// กรอกชื่อผู้ใช้งาน
await page.fill('id=form-dialog-personnel-input-email', 'ทดสอบ');
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
await expect(firstNameEnError).toHaveText('ข้อมูลไม่ถูกต้อง');
await page.waitForTimeout(2000);
await page.click('id=btn-form-close');
console.log('การตรวจสอบการทำงานถูกต้อง');
});

View file

@ -1,109 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('View Deatil Personnel Employee', async () => {
await page.click('id=menu-icon-personnel-management');
await page.click("(//div[@role='tab'])[2]");
try {
await page.waitForSelector('id=btn-kebab-action-employeem', {
state: 'visible',
});
await page.click('id=btn-kebab-action-employeem');
await page.click('id=btn-kebab-view-detail-employeem');
const detailTitle = page.locator("//span[text()='ธรรมรงด์ ดำรงธรรม']");
await expect(detailTitle).toHaveText('ธรรมรงด์ ดำรงธรรม');
console.log('ตรวจสอบรายละเอียดพนักงานถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('View Deatil Personnel Courier', async () => {
try {
await page.click("(//div[@role='tab'])[3]");
await page.click('id=btn-kebab-action-courierw');
await page.click('id=btn-kebab-view-detail-courierw');
const detailTitle = page.locator("//span[text()='มาตา ลดา']");
await expect(detailTitle).toHaveText('มาตา ลดา');
console.log('ตรวจสอบรายละเอียดพนักงานส่งเอกสารถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('View Deatil Personnel Delegate', async () => {
try {
await page.click("(//div[@role='tab'])[4]");
await page.click('id=btn-kebab-action-delegatem');
await page.click('id=btn-kebab-view-detail-delegatem');
const detailTitle = page.locator("//span[text()='อาคม พลัง']");
await expect(detailTitle).toHaveText('อาคม พลัง');
console.log('ตรวจสอบรายละเอียดตัวแทนถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});
test('View Deatil Personnel Agency', async () => {
try {
await page.click("(//div[@role='tab'])[5]");
await page.click('id=btn-kebab-action-agencyw');
await page.waitForSelector('id=btn-kebab-view-detail-agencyw', {
state: 'visible',
});
await page.click('id=btn-kebab-view-detail-agencyw');
const detailTitle = await page.locator("//span[text()='ธิดา งามตา']");
await expect(detailTitle).toHaveText('ธิดา งามตา');
console.log('ตรวจสอบรายละเอียดเอเจนซี่ถูกต้อง');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
await page.click('id=btn-info-close');
});

View file

@ -1,41 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Search Personnel', async () => {
await page.click('id=menu-icon-personnel-management');
await page.fill('id=input-search', 'ทดสอบ');
await page.waitForTimeout(2000);
await page.fill('id=input-search', 'ทด');
await page.waitForTimeout(2000);
await page.fill('id=input-search', '1');
await page.waitForTimeout(2000);
await page.fill('id=input-search', 'พนักงาน');
await page.waitForTimeout(2000);
await page.fill('id=input-search', 'พนัก ');
await page.waitForTimeout(2000);
await page.fill('id=input-search', '1000006');
await page.waitForTimeout(2000);
});

View file

@ -1,34 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ตรวจสอบดูรายละเอียดบุคคลธรรมดาโดยการคลิกไอคอนดวงตา', async () => {
await page.click('id=menu-icon-customer-management');
try {
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
throw error;
}
});

View file

@ -1,41 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Edit Naturalperson', async () => {
// รออัพเดท PATH
await page.click('id=menu-icon-customer-management');
await page.click("//button[@id='btn-dots-PERS000001']");
await page.click('id=view-detail-btn-undefined-edit');
await page.click(
"//div[contains(@class,'q-field__append q-field__marginal')]/following-sibling::div[1]",
);
await page.click("//span[text()='บางรัก']");
await page.fill("(//input[@id='input-employer-id'])[1]", 'หลินปิง');
await page.fill("(//input[@id='input-customerName'])[1]", 'บางรัก');
await page.fill("(//input[@id='input-customerEnglishName'])[1]", 'Bangrak');
await page.click('id=submitBtn');
await page.waitForTimeout(2000);
});

View file

@ -1,34 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Delete Naturalperson', async () => {
// รออัพเดท PATH
await page.click('id=menu-icon-customer-management');
await page.click("//button[@id='btn-dots-PERS000002']");
await page.click('id=view-detail-btn-undefined-delete');
await page.click('id=btn-ok-dialog');
await page.waitForTimeout(2000);
});

View file

@ -1,38 +0,0 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('Status On Natural Person', async () => {
await page.click('id=menu-icon-customer-management');
await page.click("//button[@id='btn-dots-PERS000002']");
await page.click('id=view-detail-btn-undefined-status');
await page.waitForTimeout(2000);
});
test('Status Off Natural Person', async () => {
await page.click('id=btn-dots-โคโม่');
await page.click('id=view-detail-btn-undefined-status');
await page.waitForTimeout(2000);
});

Some files were not shown because too many files have changed in this diff Show more