265 lines
11 KiB
TypeScript
265 lines
11 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('/');
|
|
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');
|
|
|
|
isLoginSuccessful = true;
|
|
console.log('Login สำเร็จ');
|
|
} catch (error) {
|
|
console.error('เกิดข้อผิดพลาดในการ Login', error);
|
|
isLoginSuccessful = false;
|
|
}
|
|
}
|
|
|
|
test('Login', async () => {
|
|
await login(page);
|
|
});
|
|
|
|
test('Create Legalentitly Person', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
|
|
try {
|
|
await page.waitForTimeout(2000);
|
|
await page.click('id=btn-add');
|
|
await page.waitForSelector('id=add-customer-legal-entity');
|
|
await page.click('id=add-customer-legal-entity');
|
|
|
|
// ส่วนเกี่ยวกับ
|
|
await page.fill(
|
|
'id=input-register-name',
|
|
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด ',
|
|
);
|
|
await page.fill('id=input-register-name-en', 'AsiaTech Systems Co., Ltd.');
|
|
await page.fill('id=input-legal-person-no', 'อนุชา ศรีสวัสดิ์');
|
|
await page.fill('id=input-legal-person-code', '2022822642228');
|
|
|
|
// จดทะเบียนเมื่อ
|
|
await page.click("(//input[@id='form-input-register-date'])[1]");
|
|
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
|
|
await page.click("//div[text()='2020']");
|
|
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
|
|
await page.click("//div[text()='ก.ย.']");
|
|
await page.click("//div[@id='2020-09-18']/div[1]");
|
|
|
|
await page.fill('id=input-authorized-capital', '10000000');
|
|
await page.fill('id=input-telephone-no', '022202002');
|
|
|
|
// ส่วนข้อมูลธุรกิจ
|
|
await page.click("(//div[@class='q-tab__label'])[2]");
|
|
await page.click('id=form-select-business-type');
|
|
await page.waitForSelector('id=form-select-business-type_3');
|
|
await page.click('id=form-select-business-type_3');
|
|
await page.click('id=form-select-job-position');
|
|
await page.waitForSelector('id=form-select-job-position_0');
|
|
await page.click('id=form-select-job-position_0');
|
|
await page.fill('id=form-input-job-description', 'รายละเอียดงาน');
|
|
await page.fill(
|
|
"(//input[@id='form-input-pay-rate'])[1]",
|
|
'วันจ่ายเงินเดือน',
|
|
);
|
|
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay day');
|
|
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '2000');
|
|
|
|
// ส่วนผู้มีอำนาจลงนาม
|
|
await page.click("(//div[@class='q-tab__label'])[3]");
|
|
await page.fill(
|
|
"(//input[@id='form-input-contact-name'])[1]",
|
|
'อนุชา ศรีสวัสดิ์',
|
|
);
|
|
await page.fill(
|
|
"(//input[@id='form-input-contact-name'])[2]",
|
|
'Anucha Srisawat',
|
|
);
|
|
|
|
// ส่วนที่อยู่นายจ้าง
|
|
await page.click("(//div[@class='q-tab__label'])[4]");
|
|
await page.fill("(//input[@id='form-input-address'])[1]", '20228226242');
|
|
await page.fill(
|
|
'id=form-input-address-no',
|
|
'1234 อาคารซิตี้ทาวเวอร์ ชั้น 12',
|
|
);
|
|
await page.fill("(//input[@id='form-input-street'])[1]", 'สาทรใต้');
|
|
await page.click('id=form-select-province');
|
|
await page.waitForSelector('id=form-select-province_0');
|
|
await page.click('id=form-select-province_0');
|
|
await page.click('id=form-select-district');
|
|
await page.waitForSelector('id=form-select-district_11');
|
|
await page.click('id=form-select-district_11');
|
|
await page.click('id=form-select-sub-district');
|
|
await page.waitForSelector('id=form-select-sub-district_1');
|
|
await page.click('id=form-select-sub-district_1');
|
|
await page.fill(
|
|
'id=form-input-address-en',
|
|
'1234 City Tower Building, 12th Floor',
|
|
);
|
|
await page.fill("(//input[@id='form-input-street'])[2]", 'South Sathorn');
|
|
|
|
// ส่วนข้อมูลผู้ติดต่อ
|
|
await page.click("(//div[@class='q-tab__label'])[5]");
|
|
await page.fill('id=form-input-contact-name', 'วราภรณ์ ศรีสวัสดิ์');
|
|
await page.fill('id=form-input-mail', 'asiatech@support.com');
|
|
await page.fill("(//input[@id='form-input-telephone'])[1]", '0866522622');
|
|
await page.fill("(//input[@id='form-input-telephone'])[2]", '022022002');
|
|
await page.click('id=quotation-branch');
|
|
await page.waitForSelector('id=quotation-branch_1');
|
|
await page.click('id=quotation-branch_1');
|
|
await page.waitForSelector("//button[@type='submit']");
|
|
await page.click("//button[@type='submit']");
|
|
await page.click('id=btn-form-close');
|
|
await page.waitForTimeout(2000);
|
|
|
|
const legalentitlyNameCheck = await page.locator(
|
|
"//tr[contains(.,'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด') and contains (.,'022022002')]",
|
|
);
|
|
|
|
await expect(legalentitlyNameCheck).toContainText(
|
|
'บริษัท เอเชียเทค ซิสเต็มส์ จำกัด',
|
|
);
|
|
await expect(legalentitlyNameCheck).toContainText('022022002');
|
|
} catch (error) {
|
|
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('Create Legalentitly Person Second', async () => {
|
|
if (!isLoginSuccessful) {
|
|
await login(page);
|
|
}
|
|
|
|
try {
|
|
await page.click('id=btn-add');
|
|
await page.waitForSelector('id=add-customer-legal-entity');
|
|
await page.click('id=add-customer-legal-entity');
|
|
|
|
// ส่วนเกี่ยวกับ
|
|
await page.fill(
|
|
'id=input-register-name',
|
|
'บริษัท กรีนโกลบอล โซลูชั่นส์ จำกัด',
|
|
);
|
|
await page.fill(
|
|
'id=input-register-name-en',
|
|
'Green Global Solutions Co., Ltd.',
|
|
);
|
|
await page.fill('id=input-legal-person-no', 'ณัฐวุฒิ เกียรติกุล');
|
|
await page.fill('id=input-legal-person-code', '2022822642229');
|
|
|
|
// จดทะเบียนเมื่อ
|
|
await page.click("(//input[@id='form-input-register-date'])[1]");
|
|
await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
|
|
await page.click("//div[text()='2021']");
|
|
await page.click("(//button[@class='dp__btn dp__month_year_select'])[1]");
|
|
await page.click("//div[text()='ก.ย.']");
|
|
await page.click("//div[@id='2021-09-18']/div[1]");
|
|
|
|
await page.fill('id=input-authorized-capital', '10000000');
|
|
await page.fill('id=input-telephone-no', '022202002');
|
|
|
|
// ส่วนข้อมูลธุรกิจ
|
|
await page.click("(//div[@class='q-tab__label'])[2]");
|
|
await page.click('id=form-select-business-type');
|
|
await page.waitForSelector('id=form-select-business-type_2');
|
|
await page.click('id=form-select-business-type_2');
|
|
await page.click('id=form-select-job-position');
|
|
await page.waitForSelector('id=form-select-job-position_0');
|
|
await page.click('id=form-select-job-position_0');
|
|
await page.fill('id=form-input-job-description', 'รายละเอียดงาน');
|
|
await page.fill(
|
|
"(//input[@id='form-input-pay-rate'])[1]",
|
|
'วันจ่ายเงินเดือน',
|
|
);
|
|
await page.fill("(//input[@id='form-input-pay-rate'])[2]", 'Pay day');
|
|
await page.fill("(//input[@id='form-input-pay-rate'])[3]", '2000');
|
|
|
|
// ส่วนผู้มีอำนาจลงนาม
|
|
await page.click("(//div[@class='q-tab__label'])[3]");
|
|
await page.fill(
|
|
"(//input[@id='form-input-contact-name'])[1]",
|
|
'ณัฐวุฒิ เกียรติกุล',
|
|
);
|
|
await page.fill(
|
|
"(//input[@id='form-input-contact-name'])[2]",
|
|
'Nattawut Kiatkul',
|
|
);
|
|
|
|
// ส่วนที่อยู่นายจ้าง
|
|
await page.click("(//div[@class='q-tab__label'])[4]");
|
|
await page.fill("(//input[@id='form-input-address'])[1]", '20228226244');
|
|
await page.fill(
|
|
'id=form-input-address-no',
|
|
'5678 อาคารอินฟินิท พลาซ่า ชั้น 8',
|
|
);
|
|
await page.fill("(//input[@id='form-input-street'])[1]", 'เพลินจิต');
|
|
await page.click('id=form-select-province');
|
|
await page.waitForSelector('id=form-select-province_0');
|
|
await page.click('id=form-select-province_0');
|
|
await page.click('id=form-select-district');
|
|
await page.waitForSelector('id=form-select-district_6');
|
|
await page.click('id=form-select-district_6');
|
|
await page.click('id=form-select-sub-district');
|
|
await page.waitForSelector('id=form-select-sub-district_3');
|
|
await page.click('id=form-select-sub-district_3');
|
|
await page.fill(
|
|
'id=form-input-address-en',
|
|
'5678 Infinite Plaza Building, 8th Floor',
|
|
);
|
|
await page.fill("(//input[@id='form-input-street'])[2]", 'Ploenchit');
|
|
|
|
// ส่วนข้อมูลผู้ติดต่อ
|
|
await page.click("(//div[@class='q-tab__label'])[5]");
|
|
await page.fill('id=form-input-contact-name', 'ณัฐวุฒิ เกียรติกุล');
|
|
await page.fill('id=form-input-mail', 'asiatech@support.com');
|
|
await page.fill("(//input[@id='form-input-telephone'])[1]", '0866522624');
|
|
await page.fill("(//input[@id='form-input-telephone'])[2]", '022022000');
|
|
await page.click('id=quotation-branch');
|
|
await page.waitForSelector('id=quotation-branch_0');
|
|
await page.click('id=quotation-branch_0');
|
|
await page.waitForSelector("//button[@type='submit']");
|
|
await page.click("//button[@type='submit']");
|
|
await page.click('id=btn-form-close');
|
|
await page.waitForTimeout(2000);
|
|
|
|
const legalentitlyNameCheck = await page.locator(
|
|
"//tr[contains(.,'บริษัท กรีนโกลบอล โซลูชั่นส์ จำกัด') and contains (.,'022022000')]",
|
|
);
|
|
|
|
await expect(legalentitlyNameCheck).toContainText(
|
|
'บริษัท กรีนโกลบอล โซลูชั่นส์ จำกัด',
|
|
);
|
|
await expect(legalentitlyNameCheck).toContainText('022022000');
|
|
} catch (error) {
|
|
console.log('เกิดข้อผิดพลาดในการทดสอบ', error);
|
|
isLoginSuccessful = false;
|
|
throw error;
|
|
}
|
|
});
|