jws-frontend/tests/01-Manage/03-Admin-ManageCustomer/JWS_MC_017-1_CreateEmployeeFailEn.spec.ts
2024-12-04 09:12:52 +07:00

273 lines
11 KiB
TypeScript

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