Access the name of the current fixture and test at runtime

Viewed 1700

For usage as in

test(testName, async (t) => {
  const ua = await getUA()

  await t.takeScreenshot(
    fixtureName +
      "/" +
      testName +
      "/" +
      identifyUserAgent(ua) +
      "/" +
      "scsh_1.png",
  )
...

As of testcafe@0.21.1 my workaround is

const fixtureName = "Index_Page_Test"

fixture(fixtureName).page(...)

...

const testName = "dom_has_critical_elements"

test(testName, async (t) => {
...

but would prefer to have it available on t. Am i missing something?

3 Answers

According to https://github.com/DevExpress/testcafe/issues/2826, you can use

  • t.testRun.test.name to obtain the current test's name, and
  • t.testRun.test.testFile.currentFixture.name to obtain the current fixture's name.

Tried it myself, and it works. It seems to be a non-documented feature, though.

At preset, t does not contain the test and fixtures names. For your purpose (build path for takeScreenshot action) you can use the custom screenshot pattern feature.

Related