import { test, expect, Page } from '@playwright/test'; import { strictEqual } from 'assert'; import exp from 'constants'; let page: Page; test.beforeAll(async ({ browser }) => { page = await browser.newPage(); }); test.afterAll(async () => { if (page !== undefined) { await page.close(); } }); test('Login', async () => { // 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'); }); test('Create Personnel - ในกรณีที่ไม่กรอกข้อมูล', async () => { await page.click('id=menu-icon-personnel-management'); await page.click('id=btn-add'); await page.click('id=btn-add-personne'); await page.click('id=btn-info-basic-save'); await page.waitForTimeout(2000); const usernameError = page.locator("(//div[@role='alert'])[1]"); const userTypeError = page.locator("(//div[@role='alert'])[2]"); const userPermisionError = page.locator("(//div[@role='alert'])[3]"); const citizenIdError = page.locator("(//div[@role='alert'])[4]"); const firstNameError = page.locator("(//div[@role='alert'])[5]"); const lastNameError = page.locator("(//div[@role='alert'])[6]"); const firstNameEnError = page.locator("(//div[@role='alert'])[7]"); const lastNameEnError = page.locator("(//div[@role='alert'])[8]"); const brithDateError = page.locator("(//div[@role='alert'])[9]"); const citizenIdInError = page.locator("(//div[@role='alert'])[10]"); const addressError = page.locator("(//div[@role='alert'])[11]"); const provinceError = page.locator("(//div[@role='alert'])[12]"); const districtError = page.locator("(//div[@role='alert'])[13]"); const subDistrictErrorError = page.locator("(//div[@role='alert'])[14]"); const addressEnErrorError = page.locator("(//div[@role='alert'])[15]"); await expect(usernameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(userTypeError).toHaveText('โปรดเลือกประเภทผู้ใช้งาน'); await expect(userPermisionError).toHaveText('โปรดเลือกสิทธิ์ผู้ใช้งาน'); await expect(citizenIdError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(firstNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(lastNameError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(firstNameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(lastNameEnError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(brithDateError).toHaveText('โปรดเลือกวันเดือนปีเกิด'); await expect(citizenIdInError).toHaveText('โปรดเลือกวันที่ออกบัตร'); await expect(addressError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await expect(provinceError).toHaveText('โปรดเลือกจังหวัด'); await expect(districtError).toHaveText('โปรดเลือกอำเภอ'); await expect(subDistrictErrorError).toHaveText('โปรดเลือกตำบล'); await expect(addressEnErrorError).toHaveText('จำเป็นต้องกรอกข้อมูลนี้'); await page.waitForTimeout(2000); await page.click('id=btn-form-close'); console.log('การตรวจสอบการทำงานถูกต้อง'); }); test('Create Personnel - ในกรณีที่กรอกชื่อผู้ใช้งานที่ไม่ตรงกับตัวอักษรที่กำหนด', async () => { await page.click('id=btn-add'); await page.click('id=btn-add-personne'); // กรอกชื่อผู้ใช้งาน 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('การตรวจสอบการทำงานถูกต้อง'); }); test('Create Personnel - ในกรณีที่กรอกชื่อและนามสกุลภาษาอังกฤษไม่ตรงตามรูปแบบ', async () => { await page.click('id=btn-add'); await page.click('id=btn-add-personne'); // กรอกชื่อผู้ใช้งาน 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('การตรวจสอบการทำงานถูกต้อง'); }); test('Create Personnel - ในกรณีที่กรอกอีเมลไม่ตรงรูปแบบ', async () => { await page.click('id=menu-icon-personnel-management'); await page.click('id=btn-add'); await page.click('id=btn-add-personne'); // กรอกชื่อผู้ใช้งาน 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('การตรวจสอบการทำงานถูกต้อง'); });