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

112 lines
4.2 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);
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-eye-กิตติศักดิ์');
const fullNameEmployee = await page.locator(
"//span[text()='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบตรวจสอบรายละเอียดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click("(//button[@id='btn-info-close'])[2]");
await page.waitForTimeout(1000);
});
test('ทดสอบการดูรายละเอียดลูกจ้างโดยการคลิกเมนูย่อย', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.click('id=btn-kebab-action-กิตติศักดิ์');
await page.waitForSelector('id=btn-kebab-view-detail-กิตติศักดิ์');
await page.click('id=btn-kebab-view-detail-กิตติศักดิ์');
const fullNameEmployee = await page.locator(
"//span[text()='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบตรวจสอบรายละเอียดถูกต้อง');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.click("(//button[@id='btn-info-close'])[2]");
await page.waitForTimeout(1000);
});
test('ทดสอบการดูรายละเอียดลูกจ้างในรูปแบบการ์ด', async () => {
if (!isLoginSuccessful) {
await login(page);
}
try {
await page.waitForSelector("//button[@aria-pressed='false']");
await page.click("//button[@aria-pressed='false']");
const fullNameEmployee = await page.locator(
"//div[normalize-space(text())='กิตติศักดิ์ วิจิตรานนท์']",
);
await expect(fullNameEmployee).toHaveText('กิตติศักดิ์ วิจิตรานนท์');
console.log('ระบบทำการเปลี่ยนเป็นรูปแบบการ์ดแล้ว');
} catch (error) {
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
isLoginSuccessful = false;
throw error;
}
await page.waitForTimeout(1000);
});