import { test, expect, Page } from '@playwright/test'; import { strictEqual } from 'assert'; import { log } from 'console'; import { LOADIPHLPAPI } from 'dns'; 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('/'); 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.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("(//button[@id='btn-eye-อนุชา ศรีสวัสดิ์'])[2]"); await page.waitForTimeout(2000); const fullNamelegal = await page.locator( "//div[@class='col column']//span[1]", ); await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด'); } catch (error) { console.log('เกิดข้อผิดพลาดในการทดสอบ', error); isLoginSuccessful = false; throw error; } await page.waitForSelector('id=btn-info-close'); await page.click('id=btn-info-close'); await page.waitForTimeout(2000); }); 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-อนุชา ศรีสวัสดิ์'); await page.waitForTimeout(2000); const fullNamelegal = await page.locator( "//div[@class='col column']//span[1]", ); await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด'); } catch (error) { console.log('เกิดข้อผิดพลาดในการทดสอบ', error); isLoginSuccessful = false; throw error; } await page.waitForSelector('id=btn-info-close'); await page.click('id=btn-info-close'); await page.waitForTimeout(2000); }); test('ทดสอบการดูรายละเอียดนิติบุคคลในรูปแบบการ์ด', async () => { if (!isLoginSuccessful) { await login(page); } try { await page.waitForSelector("//button[@aria-pressed='false']"); await page.click("//button[@aria-pressed='false']"); const isCardView = await page .locator("(//div[@id='branch-card-undefined'])[2]") .isVisible(); const fullNamelegal = await page.locator( "//b[normalize-space(text())='บริษัท เอเชียเทค ซิสเต็มส์ จำกัด']", ); await expect(isCardView).toBe(true); await expect(fullNamelegal).toHaveText('บริษัท เอเชียเทค ซิสเต็มส์ จำกัด'); console.log('ระบบทำการเปลี่ยนรูปแบบเป็นการ์ดแล้ว'); } catch (error) { console.log('เกิดข้อผิดพลาดในการทดสอบ', error); isLoginSuccessful = false; throw error; } await page.waitForTimeout(2000); });