jws-frontend/tests/01-Manage/01-Admin-BranchManagement/JWS_BM_006-1_CreateServicePointFail.spec.ts

177 lines
6.1 KiB
TypeScript
Raw Normal View History

2024-12-03 17:59:46 +07:00
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
2025-01-13 11:47:01 +07:00
await page.goto('/');
2024-12-03 17:59:46 +07:00
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');
});