Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name of the report is not saving as expected (even though 'reportFilename' in cypress.json file is changed) #293

Closed
prudhvidandamudi opened this issue Oct 24, 2019 · 7 comments

Comments

@prudhvidandamudi
Copy link

prudhvidandamudi commented Oct 24, 2019

i am using mochawesome for my cypress tests.

This is my cypress.json file

{
  "viewportWidth": 1440,
  "viewportHeight": 800,
  "defaultCommandTimeout": 8000,
  "reporter": "mochawesome",
  "reporterOptions": {
      "reportDir": "cypress/reports/mochawesome-report",
      "reportFilename": "sample",
      "overwrite": false,
      "html": true,
      "json": true  
   },
  "env": {
    "environment": "Stagging"
  },
  "screenshotsFolder": "cypress/reports/mochawesome-report/assets",
}

when I ran my tests, the reports are generated with name 'sample.html' which is expected as I have defined my report title as sample in cypress.json file.

now I wanted to have unique name for each report generated based on the test suite name.

so I have used the cypress event 'test:before:run' and set the reportFilename in cypress.json to the test suite name before the execution of each test, the sample code is down below

Cypress.on("test:before:run", (test, runnable) => {
    console.log(Cypress.config("reporterOptions").reportFilename);
    const suiteTitle = runnable.parent.title;
    Cypress.config({
        "reporterOptions":{
            "reportFilename": suiteTitle
        }
    });
    const reportFileName = Cypress.config("reporterOptions").reportFilename;
    console.log(reportFileName);
});

I see the reportFilename is successfully changed to Tests suite name

image

But my report is still saved as 'sample.html'
image

Why my report is still saving as sample.html , instead of my test suite name?

can you help me to resolve this @adamgruber ?

@adamgruber
Copy link
Owner

This will not work because the reporter has already been created with the initial options and no longer references the Cypress config. There is currently no way to have custom filenames for each test.

@prudhvidandamudi
Copy link
Author

prudhvidandamudi commented Oct 24, 2019

@adamgruber

Is it possible to implement it as a new feature?
So that each report file is created with the name of the Spec files by default
or
at least an option to alter the reporter options before test execution, so that report will be saved under the altered name?

@adamgruber
Copy link
Owner

It might be possible but I don't have a ton of time to devote to it right now.

@adamgruber
Copy link
Owner

Looking into this a bit, adding the feature is pretty straightforward but to work with Cypress will require cypress-io/cypress#1495 to be complete.

@mohanhbk
Copy link

is this feature implemented?

@adamgruber
Copy link
Owner

Not yet but PRs are welcome.

@adamgruber
Copy link
Owner

Please see https://github.com/adamgruber/mochawesome#reportfilename-replacement-tokens which is now available in v7.1.0. I believe this should address your issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants