update test
This commit is contained in:
parent
f3982978fa
commit
c4bdd18deb
123 changed files with 12136 additions and 5001 deletions
|
|
@ -0,0 +1,106 @@
|
|||
import { test, expect, Page } from '@playwright/test';
|
||||
import { strictEqual } from 'assert';
|
||||
import { Console, error, log } from 'console';
|
||||
|
||||
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-branch');
|
||||
await page.click('id=sub-menu-branch');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
isLoginSuccessful = true;
|
||||
console.log('ระบบทำการ Login');
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการ Login', error);
|
||||
isLoginSuccessful = false;
|
||||
}
|
||||
}
|
||||
|
||||
test('Login', async () => {
|
||||
await login(page);
|
||||
});
|
||||
|
||||
test('Search Data Branch Management', async () => {
|
||||
if (!isLoginSuccessful) {
|
||||
await login(page);
|
||||
}
|
||||
try {
|
||||
// กำหนดคำที่จะค้นหา
|
||||
const searchDatas = [
|
||||
'โคโมโดะ',
|
||||
'คาโมมายด์',
|
||||
'CM',
|
||||
'CMO',
|
||||
'00000',
|
||||
'บางจาก',
|
||||
'บางรัก',
|
||||
'สีลม1',
|
||||
];
|
||||
|
||||
for (const searchData of searchDatas) {
|
||||
// พิมพ์คำที่ต้องการค้นหา
|
||||
await page.fill('id=input-search', searchData); // ดึงคำมาจาก searchDatas
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// ดึงผลลัพฑ์การค้นหาทั้งหมด
|
||||
const searchResults = page.locator("//table[@class='q-table']//tbody[1]");
|
||||
const resultCount = await searchResults.count();
|
||||
|
||||
// ถ้าไม่มีผลลัพธ์ให้ข้ามคำถัดไป
|
||||
if (resultCount === 0) {
|
||||
console.error(`ไม่พบการค้นหา: '${searchData}', ข้ามไปคำถัดไป`);
|
||||
continue; // ข้ามคำค้นหาคำถัดไป
|
||||
}
|
||||
|
||||
// ดึงข้อความทั้งหมดของผลลัพธ์การค้นหา
|
||||
const searchResultTexts = await searchResults.allTextContents();
|
||||
console.log(`ผลลัพธ์ของการค้นหา '${searchData}'`, searchDatas);
|
||||
|
||||
// ตรวจสอบว่าผลลัพธ์ทั้งหมดมีคำที่ค้นหาหรือไม่
|
||||
const allResultContainSearchData = searchResultTexts.every((result) =>
|
||||
result.includes(searchData),
|
||||
);
|
||||
|
||||
// ถ้าไม่พบคำค้นหา ให้แค่แจ้งเตือนและข้ามไปคำถัดไป
|
||||
if (!allResultContainSearchData) {
|
||||
console.error(
|
||||
`\x1b[31mผลลัพธ์บางรายการไม่ตรงกับคำค้นหา: '${searchData}', ข้ามไปคำถัดไป\x1b[0m`,
|
||||
);
|
||||
continue; // ข้ามไปคำค้นหาถัดไป
|
||||
}
|
||||
|
||||
expect(allResultContainSearchData).toBe(true);
|
||||
|
||||
console.log(`การค้นหา '${searchData}' และการแสดงผลสำเร็จ`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('เกิดข้อผิดพลาดในการทดสอบการค้นหาหลายคำค้นหา', error);
|
||||
isLoginSuccessful = false;
|
||||
throw error;
|
||||
}
|
||||
await page.waitForTimeout(2000);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue