194 lines
8.8 KiB
TypeScript
194 lines
8.8 KiB
TypeScript
import { test, expect, Page } from '@playwright/test';
|
|
import { strictEqual, throws } from 'assert';
|
|
import { error, log } from 'console';
|
|
import { date, is } from 'quasar';
|
|
|
|
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-icon-product-service');
|
|
|
|
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 detailTitle = page.locator("//span[text()='ประกัน']");
|
|
|
|
// ตรวจสอบความถูกต้องของชื่อกลุ่มสินค้าและบริการ
|
|
await expect(detailTitle).toHaveText('ประกัน');
|
|
console.log('ตรวจสอบข้อมูลกลุ่มสินค้าและบริการถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-info-close');
|
|
});
|
|
|
|
test('ดูรายละเอียดกลุ่มสินค้าและบริการ ', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.click('id=btn-kebab-action-ประกัน');
|
|
await page.click('id=btn-kebab-view-detail-ประกัน');
|
|
|
|
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
|
|
const detailTitle = page.locator("//span[text()='ประกัน']");
|
|
|
|
// ตรวจสอบความถูกต้องของชื่อกลุ่มสินค้าและบริการ
|
|
await expect(detailTitle).toHaveText('ประกัน');
|
|
console.log('ตรวจสอบข้อมูลกลุ่มสินค้าและบริการถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-info-close');
|
|
});
|
|
|
|
test('ดูรายละเอียดประเภทของสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.reload();
|
|
await page.click('id=tree-enter-ประกัน');
|
|
await page.click('id=tree-enter-ประเภท-ประกัน');
|
|
await page.click('id=btn-eye-ประกันภัยแบบกลุ่ม');
|
|
|
|
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
|
|
const detailTitleType = page.locator(
|
|
"//span[normalize-space(text())='ประกันภัยแบบกลุ่ม']",
|
|
);
|
|
|
|
// ตรวจสอบความถูกต้องของชื่อประเภทสินค้าและบริการ
|
|
await expect(detailTitleType).toHaveText('ประกันภัยแบบกลุ่ม');
|
|
console.log('ตรวจสอบข้อมูลประเภทของสินค้าและบริการถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-form-close');
|
|
});
|
|
|
|
test('ดูรายละเอียดประเภทของสินค้าและบริการ', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.click('id=tree-enter-ประกัน');
|
|
await page.click('id=tree-enter-ประเภท-ประกัน');
|
|
await page.click('id=btn-kebab-action-ประกันภัยแบบกลุ่ม');
|
|
await page.click('id=btn-kebab-view-detail-ประกันภัยแบบกลุ่ม');
|
|
|
|
// กำหนดค่าเพื่อนำไปตรวจสอบความถูกต้อง
|
|
const detailTitleType = page.locator(
|
|
"//span[normalize-space(text())='ประกันภัยแบบกลุ่ม']",
|
|
);
|
|
|
|
// ตรวจสอบความถูกต้องของชื่อประเภทสินค้าและบริการ
|
|
await expect(detailTitleType).toHaveText('ประกันภัยแบบกลุ่ม');
|
|
console.log('ตรวจสอบข้อมูลประเภทของสินค้าและบริการถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-form-close');
|
|
});
|
|
|
|
test('ดูรายละเอียดสินค้าและบริการของสินค้าและบริการ โดยการคลิกไอคอนรูปดวงตา', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.click('id=tree-enter-ประกัน');
|
|
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
|
|
await page.click('id=btn-eye-ประเภทกลุ่ม');
|
|
|
|
// กำหนดค่าเพื่อตรวจสอบความถูกต้อง
|
|
const detailTitleType = page.locator(
|
|
"//span[normalize-space(text())='ประเภทกลุ่ม']",
|
|
);
|
|
|
|
// ตรวจสอบความถูกต้องของชื่อสินค้าและบริการ
|
|
await expect(detailTitleType).toHaveText('ประเภทกลุ่ม');
|
|
console.log('ตรวจสอบข้อมูลสินค้าและบริการของสินค้าและบริการถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-form-close');
|
|
});
|
|
|
|
test('ดูรายละเอียดสินค้าและบริการของสินค้าและบริการ', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.click('id=tree-enter-ประกัน');
|
|
await page.click('id=tree-enter-สินค้าและบริการ-ประกัน');
|
|
await page.click('id=btn-kebab-action-ประเภทกลุ่ม');
|
|
await page.click('id=btn-kebab-view-detail-ประเภทกลุ่ม');
|
|
|
|
// กำหนดค่าเพื่อตรวจสอบความถูกต้อง
|
|
const detailTitleType = page.locator(
|
|
"//span[normalize-space(text())='ประเภทกลุ่ม']",
|
|
);
|
|
|
|
// ตรวจสอบความถูกต้องของชื่อสินค้าและบริการ
|
|
await expect(detailTitleType).toHaveText('ประเภทกลุ่ม');
|
|
console.log('ตรวจสอบข้อมูลสินค้าและบริการของสินค้าและบริการถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-form-close');
|
|
});
|