test : Update Script

This commit is contained in:
Linpiing 2024-09-26 11:05:54 +07:00
parent 9254c0183e
commit 297ff8c675
73 changed files with 2055 additions and 398 deletions

View file

@ -1,5 +1,6 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
@ -15,7 +16,7 @@ test.afterAll(async () => {
test('Login', async () => {
// Login
await page.goto('http://192.168.1.90:20001/');
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');
@ -33,6 +34,11 @@ test('ทดสอบการเพิ่มกลุ่มสินค้า
await page.click('id=btn-add-product-group');
// กรอกข้อมูลกลุ่มสินค้าและบริการ
// await page.click("(//i[@aria-hidden='false'])[2]");
// await page.click("(//input[@id='input-source-nationality'])[2]");
// await page.click(
// "//span[normalize-space(text())='บริษัท คาโมมายด์ จำกัด']",
// );
await page.fill("(//input[@id='input-name'])[2]", 'ประกัน');
await page.fill("(//textarea[@id='input-detail'])[2]", 'รายละเอียดประกัน');
await page.fill("(//textarea[@id='input-remark'])[2]", 'หมายเหตุประกัน');
@ -66,50 +72,3 @@ test('ทดสอบการเพิ่มกลุ่มสินค้า
await page.waitForTimeout(2000);
});
test('ทดสอบการเพิ่มประเภท', async () => {
// เข้าสู่หน้าหลุ่มสินค้าและบริการ
await page.click("(//div[@id='tree-enter-ประกัน']//div)[1]");
try {
// เพิ่มกลุ่มสินค้าและบริการ
await page.click('id=btn-add');
await page.click('id=btn-add-service');
// กรอกข้อมูลประเภทส่วน "ข้อมูลประเภท"
await page.fill('id=input-service-code', 'MOU');
await page.fill('id=input-service-name', 'ประกันภัยแบบกลุ่ม');
await page.fill('id=input-service-description', 'รายละเอียดประภัยแบบกลุ่ม');
// เพิ่มคุณสมบัติส่วน "คุณสมบัติของประเภท"
await page.click('id=btn-capitalize');
// บันทึกการสร้างกลุ่มสินค้นและบริการ
await page.click('id=btn-form-submit');
// ตรวจสอบหลังทำการสร้างกลุ่มสินค้าและบริการ
const newProductAndServiceLocator = page.locator(
"//div[normalize-space(text())='ประกัน']",
);
await newProductAndServiceLocator.waitFor({ state: 'visible' });
// ดึงข้อความให้ตรงจาก XPath
const newProductAndServiceName =
await newProductAndServiceLocator.textContent();
// ตรวจสอบความถูกต้องหลังทำการสร้างกลุ่มสินค้าและบริการ
if (newProductAndServiceName !== null) {
const trimmedName = newProductAndServiceName.trim();
expect(trimmedName).toBe('ประกัน');
console.log('การตรวจสอบสำเร็จ : ถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึก');
}
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,53 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ทดสอบการเพิ่มกลุ่มสินค้าและบริการในกรณีที่ไม่กรอกข้อมูล', async () => {
await page.click('id=menu-icon-product-service');
try {
// เพิ่มกลุ่มสินค้าและบริการ
await page.click('id=btn-add');
await page.click('id=btn-add-product-group');
// บันทึกการสร้างกลุ่มสินค้นและบริการ
await page.click('id=btn-form-submit');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const nameProduceandSeviceGropError = page.locator(
"//div[normalize-space(text())='จำเป็นต้องกรอกข้อมูลนี้']",
);
await expect(nameProduceandSeviceGropError).toHaveText(
'จำเป็นต้องกรอกข้อมูลนี้',
);
console.log(nameProduceandSeviceGropError, 'ตรวจสอบการแจ้งเตือนถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,75 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
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-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-สินค้าและบริการ-ประกัน');
try {
await page.click('id=btn-add');
await page.click('id=btn-add-product');
// รหัสสินค้าและบริการ
await page.waitForSelector("(//input[@id='select-br-id'])[1]", {
state: 'visible',
});
await page.click("(//input[@id='select-br-id'])[1]");
await page.click('id=select-br-id_0');
await page.fill("(//input[@id='input-name'])[2]", 'ประเภทกลุ่ม');
// ระยะเวลาดำเนินการ
await page.fill('id=input-process', '2');
// ประเภทค่าใช้จ่าย
await page.waitForSelector("(//input[@id='select-br-id'])[2]", {
state: 'visible',
});
await page.click("(//input[@id='select-br-id'])[2]");
await page.click('id=select-br-id_0');
// กรอกรายละเอียด
await page.fill("//div[@contenteditable='true']", 'รายละเอียด');
// กรอกสาเหตุ
await page.fill("(//textarea[@id='input-remark'])[2]", 'หมายเหตุ');
// ส่วนข้อมูลราคา
await page.click("//span[normalize-space(text())='ข้อมูลราคา']");
await page.fill('id=input-price', '2000');
await page.fill('id=input-agent-price', '1800');
await page.fill('id=input-service-charge', '1000');
await page.click('id=btn-form-submit');
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,59 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ทดสอบการเพิ่มสินค้า', async () => {
await page.click('id=menu-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-สินค้าและบริการ-ประกัน');
try {
await page.click('id=btn-add');
await page.click('id=btn-add-product');
await page.click('id=btn-form-submit');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
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(
'จำเป็นต้องกรอกข้อมูลนี้',
);
} catch (error) {
console.log('เกิดข้อผิดพลาดในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,124 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ทดสอบการเพิ่มประเภท', async () => {
await page.click('id=menu-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-ประเภท-ประกัน');
try {
// เพิ่มประเภท
await page.click('id=btn-add');
await page.click('id=btn-add-service');
// กรอกข้อมูลประเภทส่วน "ข้อมูลประเภท"
await page.fill('id=input-service-code', 'MOU');
await page.fill('id=input-service-name', 'ประกันภัยแบบกลุ่ม');
await page.fill('id=input-service-description', 'รายละเอียดประภัยแบบกลุ่ม');
// เพิ่มคุณสมบัติส่วน "คุณสมบัติของประเภท"
await page.click('id=btn-capitalize');
await page.click('id=btn-dropdow-properties');
await page.click('id=list-serviceRecordName');
await page.keyboard.press('Escape');
const propertiesServiceRecordName = page.locator(
"//span[normalize-space(text())='บันทึกบริการ_Name']",
);
expect(propertiesServiceRecordName).toHaveText('บันทึกบริการ_Name');
console.log(propertiesServiceRecordName, 'เลือกdropdown แล้ว');
// บันทึกการเพิ่มคุณสมบัติ
await page.click("(//button[@id='btn-form-submit'])[2]");
// เพิ่มส่วนข้อมูลงาน
await page.click("//span[normalize-space(text())='ข้อมูลงาน']");
await page.click('id=btn-add-work');
await page.click("//div[@for='select-work-name-1']");
await page.waitForTimeout(2000);
await page.click("//span[normalize-space(text())='จัดการ']");
await page.click("//span[normalize-space(text())='เพิ่มงาน']");
await page.fill('id=input-work-name-0', 'อัคคีภัย');
await page.click('id=btn-save-work-name');
await page.click("(//button[@id='btn-form-close'])[2]");
await page.waitForTimeout(2000);
await page.click("//div[normalize-space(text())='อัคคีภัย']");
await page.waitForTimeout(2000);
await page.keyboard.press('Escape');
// เพิ่มคุณสมบัติ
await page.click("(//button[@id='btn-add-work-product'])[1]");
await page.click('id=btn-dropdow-properties');
await page.click('id=list-refNo');
await page.keyboard.press('Escape');
const propertiesRefNo = page.locator("//span[text()='Ref No:']");
expect(propertiesRefNo).toHaveText('Ref No:');
console.log(propertiesRefNo, 'เลือกdropdown แล้ว');
await page.click("(//button[@id='btn-form-submit'])[2]");
// เพิ่มสินค้าและบริการ
await page.click("(//button[@id='btn-add-work-product'])[2]");
await page.click("//div[contains(@class,'column bordered')]");
await page.click("(//button[@id='btn-form-submit'])[2]");
// บันทึกการสร้างประเภท
await page.click('id=btn-form-submit');
// ตรวจสอบหลังทำการประเภท
const newTypeLocator = page.locator(
"//div[normalize-space(text())='ประกันภัยแบบกลุ่ม']",
);
await newTypeLocator.waitFor({ state: 'visible' });
// ดึงข้อความให้ตรงจาก XPath
const newTypeName = await newTypeLocator.textContent();
// ตรวจสอบความถูกต้องหลังทำการสร้างประเภท
if (newTypeName !== null) {
const trimmedName = newTypeName.trim();
expect(trimmedName).toBe('ประกันภัยแบบกลุ่ม');
console.log('การตรวจสอบสำเร็จ : ถูกต้อง');
} else {
throw new Error('ไม่พบข้อมูลที่บันทึก');
}
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
});

View file

@ -0,0 +1,60 @@
import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';
import { log } from 'console';
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
if (page !== undefined) {
await page.close();
}
});
test('Login', async () => {
// Login
await page.goto('http://192.168.1.62:20101/');
await expect(page).toHaveTitle(/^Sign in to /);
await page.fill("input[name='username']", 'admin');
await page.fill("input[name='password']", '1234');
await page.click('id=kc-login');
await page.waitForTimeout(2000);
// await page.click('id=acceptBtn');
});
test('ทดสอบการเพิ่มประเภท', async () => {
await page.click('id=menu-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-ประเภท-ประกัน');
try {
// เพิ่มประเภท
await page.click('id=btn-add');
await page.click('id=btn-add-service');
// บันทึกการสร้างประเภท
await page.click('id=btn-form-submit');
// ตรวจสอบหลังการแจ้งเตือนหลังจากคลิกปุ่มบันทึก
const typeCodeError = page.locator(
"(//div[@class='q-field__messages col']//div)[1]",
);
const nameTypeError = page.locator(
"(//div[@class='q-field__messages col']//div)[2]",
);
await expect(typeCodeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
await expect(nameTypeError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้');
} catch (error) {
console.error('เกิดข้อผิดการในการทดสอบ');
throw error;
}
await page.waitForTimeout(2000);
});

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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