167 lines
6.5 KiB
TypeScript
167 lines
6.5 KiB
TypeScript
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');
|
|
});
|