Access the name of the current fixture and test at runtime
Asked Answered
A

3

5

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?

Awhile answered 29/8, 2018 at 22:46 Comment(0)
G
1

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.

Gamin answered 30/8, 2018 at 8:34 Comment(1)
Thank you for confirmation. I was aware of the custom screenshot pattern feature. But this is not exposed either at runtime. The intended goal of above usage is to implement a image diff of a current screenshot against an expected screenshot. So i must take control of the current screenshot file location to read it back. As an aside, i would prefer to opt to get the screenshot bytes in a Buffer. Which would allow me to be more flexible.Awhile
K
5

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.

Ketone answered 12/3, 2020 at 10:29 Comment(1)
For anyone using TypeScript, the following workaround is available github.com/DevExpress/testcafe/issues/…Jobey
A
3

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)

Abruption answered 3/8, 2019 at 7:59 Comment(0)
G
1

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.

Gamin answered 30/8, 2018 at 8:34 Comment(1)
Thank you for confirmation. I was aware of the custom screenshot pattern feature. But this is not exposed either at runtime. The intended goal of above usage is to implement a image diff of a current screenshot against an expected screenshot. So i must take control of the current screenshot file location to read it back. As an aside, i would prefer to opt to get the screenshot bytes in a Buffer. Which would allow me to be more flexible.Awhile

© 2022 - 2024 — McMap. All rights reserved.