update test
This commit is contained in:
parent
f3982978fa
commit
c4bdd18deb
123 changed files with 12136 additions and 5001 deletions
|
|
@ -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);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue