Joerg M.
Joerg M.

Reputation: 427

Access the name of the current fixture and test at runtime

For usage as in

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

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

As of [email protected] 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?

Upvotes: 5

Views: 2409

Answers (3)

Dirk R
Dirk R

Reputation: 387

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.

Upvotes: 5

Jitesh Sojitra
Jitesh Sojitra

Reputation: 4043

Currently, there is no way to get testname from the test or fixture, please refer to enhancement request logged in TestCafe:

https://github.com/DevExpress/testcafe/issues/2823 (No way to get current testname using c.ctx or c.fixtureCtx? #2823)

https://github.com/DevExpress/testcafe/issues/2826 (Allow to use test and fixture names inside hooks and test bodies)

Upvotes: 3

mlosev
mlosev

Reputation: 5227

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.

Upvotes: 1

Related Questions