this.test.file is null when test is executing in UI Runner
See original GitHub issueWhile 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:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
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.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?