codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 723 forks source link

CodeceptJS: Allure report always opens the latest report - Multiple Browser Execution #3377

Closed myrepojuly1987 closed 2 years ago

myrepojuly1987 commented 2 years ago

What are you trying to achieve?

Trying to execute same tests on different browsers (Chrome and Edge) in parallel and view the test results.

What do you get instead?

CodeceptJS generates 2 reports in the allure-results directory, but always shows the latest report when viewed using allure serve command. Could you please guide me on how to generate a singe report and view the test results executed in both Chrome and Edge?

![image](https://user-images.githubusercontent.com/97806447/182031353-6bb54f3f-0ec2-4155-8565-d8500d2db478.png)

![image](https://user-images.githubusercontent.com/97806447/182031409-f24a484f-3e87-4ddd-bae8-e50bedc964ab.png)

![image](https://user-images.githubusercontent.com/97806447/182032100-dfdeb85c-e910-4ebf-98b6-e460c407b203.png)

Provide test source code if related

Feature('Test Allure report multiple browsers');

Scenario('test something', ({ I }) => {
    I.amOnPage('./');
}).tag('basic');

Details

const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');

// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

exports.config = {
  tests: './webdriver_tests/*_test.js',
  output: './allure-results',
  helpers: {
    WebDriver: {
      url: 'https://docs.qameta.io/allure/#_usage_8',
      browser: 'chrome',
    }
  },
  include: {
    I: './steps_file.js'
  },
  multiple:{
    basic:{
      "browsers": ["chrome", "MicrosoftEdge"],
    },
  },
  plugins: {
    wdio: {
      enabled: true,
      services: ['selenium-standalone'],
    },
    allure: {
      enabled: true,
      outputDir: "./allure-results"
    },
    screenshotOnFail: {
      enabled: true
    },
    stepByStepReport: {
      enabled: true,
      output: "./allure-results"
    },
  },
  bootstrap: null,
  mocha: {},
  name: 'tests'
}
kobenguyent commented 2 years ago

Hey @myrepojuly1987 if I'm not wrong the allure reports already aggregated all files in results folder to show up the final report for you.

myrepojuly1987 commented 2 years ago

@PeterNgTr Thanks for your reply. This is completely a new tool to me and learning a lot about this tool and it is a great one too.

I see the allure-results directory genreated as shown below with one for chrome and the other for edge. image

I am looking to combine these 2 reports into a single report which shows the execution results in both the browsers

Since allure has built-in aggretation functionalty, I tried doing the below but still it generates only one single report (which is either for chrome or edge). Not sure where I am gng wrong here.

allure serve ./allure-results/basic_chrome_1 ./allure-results/basic_edge_2

myrepojuly1987 commented 2 years ago

@PeterNgTr

Sharing the config again

const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');

// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

exports.config = {
  tests: './webdriver_tests/*_test.js',
  output: './allure-results/',
  helpers: {
    WebDriver: {
      url: 'https://docs.qameta.io/allure/#_usage_8',
      browser: 'chrome'
    }
  },  
  include: {
    I: './steps_file.js'
  },
  multiple:{
    basic:{
      "browsers": [
        {
            browser: "chrome",
            desiredCapabilities:{
               browserName: "chrome", 
            },
         //   outputName: "chrome"
        },
        {
            browser: "MicrosoftEdge",
           // outputName: "edge"
        }
    ]
    },
  },
  plugins: {
    wdio: {
      enabled: true,
      services: ['selenium-standalone'],
    },
    allure: {
      enabled: true,
      outputDir: "./allure-results"
    },
    screenshotOnFail: {
      enabled: true
    },
    stepByStepReport: {
       enabled: true,
       output: "./allure-results"
     },
  },
  bootstrap: null,
  mocha: {},
  name: 'tests'
}

This is the comannd that I am running to run the tests in chrome and edge npx codeceptjs run-multiple basic

Would be great if you can let me know if there is a way to combine the results generated.

image

Generating Report: allure serve ./allure-results Which generates report of either edge or chrome and not both

image

kobenguyent commented 2 years ago

hey @myrepojuly1987 oh I see you're using the run-multiple which is kinda obsolete, may you try using run-workers?

myrepojuly1987 commented 2 years ago

@PeterNgTr Editing my previous post. Was able to set up the parallel.js file and was able to run the workers as stated in https://codecept.io/parallel/#parallel-execution-by-workers

But even then the allure report opened only the latest report. Can you please try it from your end or share example if you have any?

myrepojuly1987 commented 2 years ago

@PeterNgTr : the issue was with the suite title which was common when I executed it in parallel for both the browsers … Changed the suite title using event suite.before and was able to generate the aggregate allure report. Closing this ticket.

StanislavGrishaev commented 1 year ago

Changed the suite title using event suite.before and was able to generate the aggregate allure report. Closing this ticket.

@myrepojuly1987 hi there, could you share code, please ? i'm stuck with same issue.

myrepojuly1987 commented 1 year ago

Hello… @StasGrishaevTutu … sure, will share it tomorrow without fail…

myrepojuly1987 commented 1 year ago

@StasGrishaevTutu

Here is the sample. Just ensure the below event gets dispatched as given here https://codecept.io/internal-api/#concepts under'Event Listeners' section and add the file to the helpers in codecept.conf.js

import { event, config} from 'codeceptjs';

event.dispatcher.on(event.suite.before, function (suite) {

    /**
     * Example to fetch the browser name. If executing in multiple test libs then add swtich case for helpers
     * const conf =  config.get();
       const browser = conf.helpers.WebDriver.browser;
     */

    const browser = UIHelper.getBrowserName(); //see example above to fetch the browserName
   //modify the suite.title value which is then used by the allure reports
    suite.title = 'Browser' + ': ' + browser.toUpperCase() + ' - ' + suite.title;
  }); 
StanislavGrishaev commented 1 year ago

@myrepojuly1987 much appreciated for quick response !

myrepojuly1987 commented 1 year ago

@StasGrishaevTutu You welcome… just leave a msg here if you are still facing issue in generating the aggregate report…will try to share a sample repo tomorrow…