我正在尝试根据 playwright.config.ts 中配置的项目设置测试数据。
projects: [
{
name: "NY",
use: {
storeID: 1
},
},
{
name: "NC",
use: {
storeID: 888
},
},
],
我使用固定文件根据项目数据进行登录过程,但由于不同州的应用程序不同,如何根据商店 ID 分配正确的 json 数据文件? 这是需要通过条件测试来完成的事情吗?
这是我的夹具文件:
import {test as base} from '@playwright/test';
import {LogIn} from '../pom/secureLogInFlow';
export type TestOptions = {
storeID: Number;
};
type MyFixtures = {
logIn: LogIn;
};
export const test = base.extend<TestOptions & MyFixtures>({
storeID: [ 1, {option: true}],
logIn: async ({page, storeID}, use) => {
// Set up the fixture.
const logIn = new LogIn(page);
await logIn.goto();
await logIn.loginWorkFlow(storeID);
// Use the fixture value in the test.
await use(logIn);
},
});
export {expect} from '@playwright/test';
想通了。
export const test = base.extend<TestOptions & MyFixtures>({
storeID: [1, { option: true }],
logIn: async ({ page, storeID }, use) => {
// Set up the fixture.
const logIn = new LogIn(page);
await logIn.goto();
await logIn.loginWorkFlow(storeID);
// Use the fixture value in the test.
await use(logIn);
},
testData: async ({ storeID }, use) => {
let NY = await require('../testData/NYTestData.json');
let NC = await require('../testData/NCTestData.json');
if (storeID == 1) {
await use({ ...NY });
} else {
await use({ ...NC });
}
},
});
export { expect } from '@playwright/test';