Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 691
Joerg M. Avatar asked Aug 29 '18 22:08

Joerg M.


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.

like image 196
Dirk R Avatar answered Sep 24 '22 00:09

Dirk R


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)

like image 30
Jitesh Sojitra Avatar answered Sep 27 '22 00:09

Jitesh Sojitra


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.

like image 37
mlosev Avatar answered Sep 23 '22 00:09

mlosev