Search code examples
testingautomated-testse2e-testingconfiguration-filestestcafe

Testcafe - How to set relative instead of absolute screenshot path in reports


I'm using spec and xunit reports. My .testcaferc.json is:

    {
  "screenshotPath": "artifacts/screenshots",
  "takeScreenshotsOnFails": true,
  "screenshotPathPattern": "${DATE}_${TIME}/${USERAGENT}/test-${TEST_INDEX}.png"
}

When the test failed in the spec and xunit reports shows the link to the screenshot, but that link has an absolute path. That is ok when I run tests locally. When running in Jenkins CI/CD the publish xunit report can't find the screenshot using absolute path due to using a relative path from "workspace" folder. Is there any way to config Testcafe to put the relative path into testRunInto.screenshotPath. I need a relative path to screenshots for any report providers.

Upd: I'm using a Jenkins Agent server to run test. The absolute path to workspace in this case: /home/jenkins/workspace/e2e. Screenshoots located in relative path: artifacts/screenshots or absolute path /home/jenkins/workspace/e2e/artifacts/screenshots. In xunit report (or any other) we got an absolute path for the screenshots. When all test finished Jenkins Agent push the whole workspace to the Master Jenkins server and absolute path to workspace became: /home/jenkins/job/test/ws/e2e and path to the screenshots: /home/jenkins/job/test/ws/e2e/artifacts/screenshots. Then Jenkins post-build action publish "Junit test result report". But inside that report we have the absolute path to the screenshot came from Jenkins Agent Server. As a result Master Jenkins unable to find the screenshot when shows the test result report. Previously I used to use Selenium and Maven or Gradle to run the test and there was a relative path to the screenshots.


Solution

  • At present, TestCafe does not have an option to use relative paths in reports. I've created a suggestion in the TestCafe repository for your case - https://github.com/DevExpress/testcafe/issues/3497. If this feature is important for you, then you can try to implement it yourself. It is not difficult. You need to do following: add a new option (see an example here) and change the path resolving mechanism depending this option (see an example here).