【发布时间】:2021-07-09 17:34:09
【问题描述】:
我希望这不是 TL;DR。我真的需要剧作家方面的帮助。
简而言之:有人知道如何将灯具设置迁移到使用 Playwright v.01101 进行配置吗?没有关于如何执行此操作的文档。
v0.1101 之前的 Playwright/Test 版本启用了自定义装置,您可以从 Playwright/Test 模块覆盖或扩展这些装置。我利用这一点来实现页面对象模型(POM)。这是我的示例夹具:
// In tests/fixtures.ts
import { folio as baseFolio } from '@playwright/test'; //now missing in v.0.1101
import { IndexPage } from "../PO/IndexPage";
require('dotenv').config();
const baseURL = process.env.BASE_URL;
// Extend built-in fixtures and declare types for new fixtures
const builder = baseFolio.extend<{ indexPage: IndexPage }>();
// In fixtures.ts
builder.indexPage.init(async ({ page }, runTest) => {
// get built-in page and wrap with POM
const indexPage = new IndexPage(page, baseURL);
// pass this to your test
runTest(indexPage);
});
// Build and export the modified fixtures
const folio = builder.build();
export const it = folio.it;
export const expect = folio.expect;
export const describe = folio.describe;
以下是我使用此 POM 运行的测试示例:
// In tests/e2e.spec.ts
import { IndexPage } from '../PO/IndexPage';
import { describe, it, expect } from './fixtures'
it('EN/FR', async ({ indexPage }) => {
await indexPage.navigateHome();
await indexPage.getCurrentLanguage()
await assertGreetingLanguage(indexPage);
await indexPage.toggleLanguage();
await assertGreetingLanguage(indexPage);
});
async function assertGreetingLanguage(indexPage: IndexPage) {
const lang = await indexPage.getCurrentLanguage();
const greeting = lang === 'English' ? 'Welcome!' : 'Bienvenue!';
// console.log(`LANG: ${lang} Greet: ${greeting}`);
expect(await indexPage.getGreeting()).toBe(greeting);
// expect(await indexPage.getGreeting()).not.toBe(greeting);
}
不过,对于 v0.1101,似乎不再支持固定装置,and instead can be setup with a config file。当然,Folio is what implements this config setup。
【问题讨论】:
-
您应该将更新发布为答案然后接受它 - 这将有助于其他人在未来提出同样的问题。