235 lines
8.7 KiB
TypeScript
235 lines
8.7 KiB
TypeScript
import { test, expect, Page } from '@playwright/test';
|
|
import { strictEqual } from 'assert';
|
|
import { 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('/');
|
|
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('ทดสอบการดูรายละเอียดสำนักงานใหญ่', 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()='บริษัท โคโม่ จำกัด ']/following-sibling::span",
|
|
);
|
|
|
|
await expect(detailTitle).toHaveText('CMO00000'); // เลขรหัสสำนักงานใหญ่
|
|
|
|
console.log('ตรวจสอบข้อมูลถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
|
|
await page.waitForTimeout(4000);
|
|
await page.click('id=btn-info-close');
|
|
});
|
|
|
|
test('ทดสอบการดูรายละเอียดสาขา', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
|
|
await page.click('id=btn-kebab-action-สีลม1');
|
|
await page.click('id=btn-kebab-view-detail-สีลม1');
|
|
|
|
const detailTitle = page.locator("//span[text()='สีลม1 ']");
|
|
|
|
await detailTitle.waitFor({ state: 'visible' });
|
|
|
|
await expect(detailTitle).toHaveText('สีลม1'); // เลขรหัสสำนักงานใหญ่
|
|
|
|
console.log('ตรวจสอบข้อมูลถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
|
|
await page.waitForTimeout(4000);
|
|
await page.click('id=btn-info-close');
|
|
});
|
|
|
|
test('ทดสอบการดูรายละเอียดจุดรับบริการ', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
try {
|
|
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
|
|
await page.click('id=btn-kebab-action-บางรัก1');
|
|
await page.click('id=btn-kebab-view-detail-บางรัก1');
|
|
|
|
const detailTitle = page.locator("//span[text()='บางรัก1 ']");
|
|
|
|
await detailTitle.waitFor({ state: 'visible' });
|
|
|
|
await expect(detailTitle).toHaveText('บางรัก1'); // เลขรหัสสำนักงานใหญ่
|
|
|
|
console.log('ตรวจสอบข้อมูลถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
|
|
await page.waitForTimeout(4000);
|
|
await page.click('id=btn-info-close');
|
|
});
|
|
|
|
test('ทดสอบการดูรายละเอียดสำนักงานใหญ่ในรูปแบบการ์ด', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
await page.reload();
|
|
|
|
await page.click("//button[@aria-pressed='false']");
|
|
await page.waitForTimeout(2000);
|
|
try {
|
|
const nameBrnach = page.locator(
|
|
"//b[normalize-space(text())='บริษัท คาโมมายด์ จำกัด']",
|
|
);
|
|
const legalPerson = page.locator(
|
|
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
|
|
);
|
|
const cellPhone = page.locator(
|
|
"(//div[text()='เบอร์โทรสำนักงาน']/following-sibling::div)[1]",
|
|
);
|
|
const contactName = page.locator("//div[normalize-space(text())='คุณต่อ']");
|
|
const address = page.locator(
|
|
"//div[normalize-space(text())='20/02 หมู่ 1, พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
|
|
);
|
|
|
|
await expect(nameBrnach).toHaveText('บริษัท คาโมมายด์ จำกัด');
|
|
await expect(legalPerson).toHaveText('1260846220284');
|
|
await expect(cellPhone).toHaveText('0866224228');
|
|
await expect(contactName).toHaveText('คุณต่อ');
|
|
await expect(address).toHaveText(
|
|
'20/02 หมู่ 1, พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
|
|
);
|
|
|
|
console.log('ตรวจสอบข้อมูลถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
|
|
await page.waitForTimeout(4000);
|
|
});
|
|
|
|
test('ทดสอบการดูรายละเอียดสาขาในรูปแบบการ์ด', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
|
|
try {
|
|
await page.click("//div[@id='tree-enter-บริษัท คาโมมายด์ จำกัด']/div[1]");
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
const legalPerson = page.locator(
|
|
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
|
|
);
|
|
const contactName = page.locator(
|
|
"(//div[text()='ติดต่อ']/following-sibling::div)[1]",
|
|
);
|
|
const address = page.locator(
|
|
"//div[normalize-space(text())='40/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
|
|
);
|
|
|
|
await expect(legalPerson).toHaveText('2022826282641');
|
|
await expect(contactName).toHaveText('คุณอุล');
|
|
await expect(address).toHaveText(
|
|
'40/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
|
|
);
|
|
|
|
console.log('ตรวจสอบข้อมูลถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
|
|
await page.waitForTimeout(4000);
|
|
});
|
|
|
|
test('ทดสอบการดูรายละเอียดจุดรับบริการในรูปแบบการ์ด', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
|
|
try {
|
|
await page.click("(//div[@id='tree-enter-บริษัท โคโม่ จำกัด']//div)[1]");
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
const legalPerson = page.locator(
|
|
"(//div[text()='ทะเบียนนิติบุคคล']/following-sibling::div)[1]",
|
|
);
|
|
const contactName = page.locator(
|
|
"(//div[text()='ติดต่อ']/following-sibling::div)[1]",
|
|
);
|
|
const address = page.locator(
|
|
"//div[normalize-space(text())='20/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200']",
|
|
);
|
|
|
|
await expect(legalPerson).toHaveText('1260846220281');
|
|
await expect(contactName).toHaveText('คุณอาท');
|
|
await expect(address).toHaveText(
|
|
'20/01 พระบรมมหาราชวัง, พระนคร, กรุงเทพมหานคร 10200',
|
|
);
|
|
|
|
console.log('ตรวจสอบข้อมูลถูกต้อง');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
|
|
await page.waitForTimeout(4000);
|
|
});
|