【发布时间】:2019-12-03 17:49:58
【问题描述】:
我想将字符串传递给页面模型中的对象以供.withText 选择使用。我可以使用该页面上的函数来执行此操作,它可以工作,但我必须以不同于页面上定义的对象的方式调用它。
我尝试使用FilterFn 和.filter(和.find),但没有成功。也许这正是我需要的,但需要帮助,或者我只是想多了。
示例页面模型摘录
export class AreaPage {
public pageTitle = Selector("#container h1").withText("My Area Title");
public async pageSubtitle(areaName: string) {
return await Selector("#container h2").withText(areaName);
}
}
示例测试摘录
test("test some code", async (t) => {
await t
.click(areaPage.pageTitle)
.click(await areaPage.PageSubtitle("my subtitle"));
}
当然,我可能不想“单击”这些标题,但它展示了调用这些页面组件的方式的不同之处。我也知道我可以在测试中捕获对象并进行验证,但这会破坏我正在尝试做的部分事情。
如上所述,它可以工作,但我希望我们的 QA 人员能够以相同的方式使用它们(即,在测试的最后一行中没有嵌入“await”)。如果我删除等待,我会收到错误:
Argument of type 'Promise<Selector>' is not assignable to parameter of type 'string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection)'.
Type 'Promise<Selector>' is missing the following properties from type 'SelectorPromise': childElementCount, childNodeCount, hasChildElements, hasChildNodes, and 51 more.ts(2345)
(......这只是让我的大脑抽筋)
我如何编写页面对象 pageSubtitle 以接受参数但在其他方面像 pageTitle 对象一样发挥作用?
【问题讨论】:
标签: testing automated-tests parameter-passing testcafe custom-selectors