update test
This commit is contained in:
parent
f3982978fa
commit
c4bdd18deb
123 changed files with 12136 additions and 5001 deletions
|
|
@ -0,0 +1,217 @@
|
|||
import { test, expect, Page } from '@playwright/test';
|
||||
import { strictEqual } from 'assert';
|
||||
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
|
||||
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-personnel');
|
||||
await page.click('id=sub-menu-personnel');
|
||||
|
||||
isLoginSuccessful = true;
|
||||
console.log('ระบบทำการ Login');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการ Login');
|
||||
isLoginSuccessful = false;
|
||||
}
|
||||
}
|
||||
|
||||
test('Login', async () => {
|
||||
await login(page);
|
||||
});
|
||||
|
||||
test('Create Personnel - ในกรณีที่ไม่กรอกข้อมูล', async () => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
await page.click('id=btn-add');
|
||||
|
||||
await page.click('id=btn-info-basic-save');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
const expectedErrors = [
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[2]",
|
||||
message: 'โปรดเลือกประเภทผู้ใช้งาน',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[3]",
|
||||
message: 'โปรดเลือกสิทธิ์ผู้ใช้งาน',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[4]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[5]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[6]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[7]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[8]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[9]",
|
||||
message: 'โปรดเลือกวันเดือนปีเกิด',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[10]",
|
||||
message: 'โปรดเลือกวันที่ออกบัตร',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[11]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[12]",
|
||||
message: 'โปรดเลือกจังหวัด',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[13]",
|
||||
message: 'โปรดเลือกเขต/อำเภอ',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[14]",
|
||||
message: 'โปรดเลือกแขวง/ตำบล',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[15]",
|
||||
message: 'จำเป็นต้องกรอกข้อมูลนี้',
|
||||
},
|
||||
];
|
||||
|
||||
for (const error of expectedErrors) {
|
||||
const locator = page.locator(error.locator);
|
||||
await expect(locator).toHaveText(error.message);
|
||||
}
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
await page.click('id=btn-form-close');
|
||||
console.log('การตรวจสอบการทำงานถูกต้อง');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test('Create Personnel - ในกรณีที่กรอกชื่อผู้ใช้งานที่ไม่ตรงกับตัวอักษรที่กำหนด', async () => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
await page.click('id=btn-add');
|
||||
|
||||
// กรอกชื่อผู้ใช้งาน
|
||||
await page.fill('id=input-username', 'ทดสอบ');
|
||||
|
||||
const usernameError = page.locator("(//div[@role='alert'])[1]");
|
||||
|
||||
await expect(usernameError).toHaveText(
|
||||
'โปรดใช้เฉพาะ _ ตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
|
||||
);
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
await page.click('id=btn-form-close');
|
||||
console.log('การตรวจสอบการทำงานถูกต้อง');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test('Create Personnel - ในกรณีที่กรอกชื่อและนามสกุลภาษาอังกฤษไม่ตรงตามรูปแบบ', async () => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
await page.click('id=btn-add');
|
||||
|
||||
// กรอกชื่อผู้ใช้งาน
|
||||
await page.fill('id=form-dialog-personnel-input-first-name-en', 'ทดสอบ');
|
||||
await page.fill('id=form-dialog-personnel-input-last-name-en', 'ทดสอบ');
|
||||
|
||||
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
|
||||
const lastNameEnError = page.locator("(//div[@role='alert'])[2]");
|
||||
|
||||
await expect(firstNameEnError).toHaveText(
|
||||
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
|
||||
);
|
||||
await expect(lastNameEnError).toHaveText(
|
||||
'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
|
||||
);
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
await page.click('id=btn-form-close');
|
||||
console.log('การตรวจสอบการทำงานถูกต้อง');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test('Create Personnel - ในกรณีที่กรอกอีเมลไม่ตรงรูปแบบ', async () => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
|
||||
try {
|
||||
await page.click('id=btn-add');
|
||||
|
||||
// กรอกชื่อผู้ใช้งาน
|
||||
await page.fill('id=form-dialog-personnel-input-email', 'ทดสอบ');
|
||||
|
||||
const firstNameEnError = page.locator("(//div[@role='alert'])[1]");
|
||||
|
||||
await expect(firstNameEnError).toHaveText('ข้อมูลไม่ถูกต้อง');
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
await page.click('id=btn-form-close');
|
||||
console.log('การตรวจสอบการทำงานถูกต้อง');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue