71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { test as base, expect } from '@playwright/test';
|
|
import { HomeNavigation } from '@/pages/homeNavigationPage';
|
|
import { writeIndexedDB } from '@/utils/indexedDBUtils';
|
|
import { firstAccount, secondAccount, AuthAccount } from '@/common/auth';
|
|
|
|
type MyFixture = {
|
|
homeNavigation: HomeNavigation;
|
|
billSet: Set<string>;
|
|
};
|
|
|
|
export const test = base.extend<MyFixture>({
|
|
page: async ({ page, baseURL }, use) => {
|
|
await page.addLocatorHandler(page.locator('.left_img > .close_btn > .close_icon > svg'), async () => {
|
|
await page.locator('.left_img > .close_btn > .close_icon > svg').click();
|
|
await expect(page.locator('.versionModal_main_content')).toBeVisible();
|
|
});
|
|
|
|
if (!baseURL) throw new Error('baseURL is required');
|
|
await page.goto(baseURL);
|
|
|
|
const mobileObject = await page.evaluate(() => {
|
|
return window.localStorage.getItem('hlk_touch_mobile');
|
|
});
|
|
if (!mobileObject && mobileObject !== 'null') {
|
|
throw new Error('localStorage does not contain boss_account or boss_account2');
|
|
}
|
|
const mobileString = JSON.parse(mobileObject);
|
|
const data = AuthAccount.loadIndexedDBFile(mobileString.val, [firstAccount, secondAccount]);
|
|
|
|
await page.evaluate(
|
|
async ({ fnString, data }) => {
|
|
const writeIndexedDBFn = new Function('return ' + fnString)();
|
|
return await writeIndexedDBFn(data);
|
|
},
|
|
{ fnString: writeIndexedDB.toString(), data },
|
|
);
|
|
|
|
await page.waitForFunction(
|
|
async () => {
|
|
const databases = await indexedDB.databases(); // 获取所有数据库
|
|
return databases.some(db => db.name === 'hlk_touch_test_init'); // 判断是否存在目标数据库
|
|
},
|
|
{ timeout: 30000 },
|
|
);
|
|
|
|
await page.reload();
|
|
|
|
await page.getByRole('button', { name: /开\s单/ }).waitFor();
|
|
|
|
await use(page);
|
|
},
|
|
|
|
/**
|
|
* 首页导航
|
|
*/
|
|
homeNavigation: async ({ page }, use) => {
|
|
const homeNavigation = new HomeNavigation(page);
|
|
await use(homeNavigation);
|
|
},
|
|
|
|
/**
|
|
* 流水单据集合(无重复水单)
|
|
*/
|
|
billSet: async ({ page }, use) => {
|
|
const billSet = new Set<string>();
|
|
await use(billSet);
|
|
},
|
|
});
|
|
|
|
export { expect } from '@playwright/test';
|