question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this.test.file is null when test is executing in UI Runner

See original GitHub issue

While running Cypress SPEC files, I would like to perform some actions in order to help with custom reporting (like: Updating the mochaFile name based on the current test file being run) - the reference to the this.test.file is always null when the file is executing and inaccessible when running the before/beforeEach hooks.

The before/beforeEach hook would be the ideal location to access and set the behavior of the mochaFile configuration.

Current behavior:

console.log(this.test.file) -> output is null. console.log(this.test) -> file: null

Desired behavior:

console.log(this.test.file) -> output something like: Cypress.config('integrationsFolder') + "example_spec.js" OR the fully qualified path of the test file being executed. Ideally this value would be available when the centralized before/beforeEach/after/afterEach hooks are executed (i.e. these hooks are normally placed within $CYPRESS_HOME/support/index.js.

before hook desired implementation:

var testFile = path.basename(this.test.file, '.js');
var reporterOpts = Cypress.config('reporterOptions');
var mochaFile = reporterOptions.mochaFile;
var resultsDir = path.dirname(mochaFile);
reporterOpts.mochaFile = resultsDir + '/' + testFile + '_test_results.xml';

Steps to reproduce:

describe('Get Test File name', function() {
    it('Display file name', function() {
        console.log('Test file name: ' + this.test.file);
        console.log('Test Object:')
        console.log(this.test)
    })
})

Versions

Windows 10, Chrome 67, Cypress 3.0.1 Node.js: 8.11.1 npm: 5.6.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Oct 31, 2018

Hey @scspieker, sorry for the delay in the response. You should be able to use Cypress.spec to access the current spec, including its name.

0reactions
scspiekercommented, Aug 9, 2018

There seems to be an element that would contain the value that I am looking for as outlined in: https://github.com/cypress-io/cypress/issues/2141

The element that I am referring to is: runs[].spec.name would be ideal.

Now the question becomes, how could I access this information within the Before hook?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the Android test runner reporting "Empty test suite"?
I am trying to run an ActivityUnitTestCase , since the tests will be dependent upon the Context -object. The package name of the...
Read more >
Can't run iOS unit or UI tests with Xcode Version 9.3 (9E145)
For the UI tests, the test-runner crashes with an assertion failure trying to load a UITestUITests.xctest plugin, for unit tests, the test fails...
Read more >
Explore test results | IntelliJ IDEA Documentation - JetBrains
After IntelliJ IDEA finishes running your tests, it shows the results in the Run tool window on the Test Runner tab.
Read more >
Testing - Spring
This chapter covers Spring's support for integration testing and best practices for unit testing. The Spring team advocates test-driven ...
Read more >
Testing Recipes - React
Testing Recipes. Common testing patterns for React components. Note: This page assumes you're using Jest as a test runner. If you use a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found