update test
This commit is contained in:
parent
f3982978fa
commit
c4bdd18deb
123 changed files with 12136 additions and 5001 deletions
|
|
@ -0,0 +1,220 @@
|
|||
import { test, expect, Page } from '@playwright/test';
|
||||
import { strictEqual } from 'assert';
|
||||
import exp from 'constants';
|
||||
import { getSystemErrorMap } from 'util';
|
||||
|
||||
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');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
isLoginSuccessful = true;
|
||||
console.log('ระบบทำการ Login');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการ Login', error);
|
||||
isLoginSuccessful = false;
|
||||
}
|
||||
}
|
||||
|
||||
test('Login', async () => {
|
||||
await login(page);
|
||||
});
|
||||
|
||||
test('Create Personnel - ในกรณีที่ไม่กรอกข้อมูล', 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=btn-add');
|
||||
|
||||
await page.click('id=btn-info-basic-save');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
const expectedErrors = [
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select User Type.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select User Role.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select Birth Date.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select Citizen Issue.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select Province.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select District.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'Please select Sub-district.',
|
||||
},
|
||||
{
|
||||
locator: "(//div[@role='alert'])[1]",
|
||||
message: 'This field is required.',
|
||||
},
|
||||
];
|
||||
|
||||
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(
|
||||
'Only _ letters and number are allowed',
|
||||
);
|
||||
|
||||
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('Only letters are allowed');
|
||||
await expect(lastNameEnError).toHaveText('Only letters are allowed');
|
||||
|
||||
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('Invalid value.');
|
||||
|
||||
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