访问当前夹具的名称并在运行时进行测试
Access the name of the current fixture and test at runtime
用法如
test(testName, async (t) => {
const ua = await getUA()
await t.takeScreenshot(
fixtureName +
"/" +
testName +
"/" +
identifyUserAgent(ua) +
"/" +
"scsh_1.png",
)
...
从 testcafe@0.21.1 开始,我的解决方法是
const fixtureName = "Index_Page_Test"
fixture(fixtureName).page(...)
...
const testName = "dom_has_critical_elements"
test(testName, async (t) => {
...
但希望在 t 上可用。我错过了什么吗?
在预设中,t
不包含测试和夹具名称。为了您的目的(为 takeScreenshot
操作构建路径),您可以使用 custom screenshot pattern 功能。
目前无法从测试或夹具中获取测试名称,请参考 TestCafe 中记录的增强请求:
https://github.com/DevExpress/testcafe/issues/2823(无法使用 c.ctx 或 c.fixtureCtx 获取当前测试名称?#2823)
https://github.com/DevExpress/testcafe/issues/2826(允许在挂钩和测试主体中使用测试和夹具名称)
根据https://github.com/DevExpress/testcafe/issues/2826,您可以使用
t.testRun.test.name
获取当前测试的名称,
t.testRun.test.testFile.currentFixture.name
获取当前灯具名称。
自己试了一下,确实有效。不过,这似乎是一个未记录的功能。
用法如
test(testName, async (t) => {
const ua = await getUA()
await t.takeScreenshot(
fixtureName +
"/" +
testName +
"/" +
identifyUserAgent(ua) +
"/" +
"scsh_1.png",
)
...
从 testcafe@0.21.1 开始,我的解决方法是
const fixtureName = "Index_Page_Test"
fixture(fixtureName).page(...)
...
const testName = "dom_has_critical_elements"
test(testName, async (t) => {
...
但希望在 t 上可用。我错过了什么吗?
在预设中,t
不包含测试和夹具名称。为了您的目的(为 takeScreenshot
操作构建路径),您可以使用 custom screenshot pattern 功能。
目前无法从测试或夹具中获取测试名称,请参考 TestCafe 中记录的增强请求:
https://github.com/DevExpress/testcafe/issues/2823(无法使用 c.ctx 或 c.fixtureCtx 获取当前测试名称?#2823)
https://github.com/DevExpress/testcafe/issues/2826(允许在挂钩和测试主体中使用测试和夹具名称)
根据https://github.com/DevExpress/testcafe/issues/2826,您可以使用
t.testRun.test.name
获取当前测试的名称,t.testRun.test.testFile.currentFixture.name
获取当前灯具名称。
自己试了一下,确实有效。不过,这似乎是一个未记录的功能。