【发布时间】:2022-11-17 06:43:07
【问题描述】:
我想组成固定装置。第一个夹具应该始终可用(将其视为基类)。第二个夹具在不同的测试文件中会有所不同(将其视为派生类) 我尝试了以下代码,它按预期工作。可以采用这种方法还是有更好的选择?
//baseFixture.js
import { test as base} from '@playwright/test';
interface MyFixtures {
fixture1: string;
}
export const test = base.extend<MyFixtures>({
fixture1: "fixture-one"
}, );
//derivedFixture.js
import {test as test1} from 'baseFixture'
interface MyFixtures2 {
fixture2: string;
}
export const test = test1.extend<MyFixtures2>({
fixture2: "fixture-two"
}, );
//in test_file.js
import {test} from 'derivedFixture'
test('should allow me use composed fixture', async ({ page, fixture1, fixture2 }) => {
console.log(`from first fixture ${fixture1}`)
console.log(`from second fixture ${fixture2}`)
});
【问题讨论】:
标签: playwright playwright-test