Skip to content

[🐛 Bug]: wdio/junit-reporter : xml report shows testcases twice even when the test is executed only once #10962

@arundhatid

Description

@arundhatid

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

7.27.0

Node.js Version

14.21.3

Mode

Standalone Mode

Which capabilities are you using?

capabilities: [
    {
      // maxInstances can get overwritten per capability. So if you have an in-house Selenium
      // grid with only 5 firefox instances available you can make sure that not more than
      // 5 instances get started at a time.
      maxInstances: 5,
      //
      browserName: "chrome",
      "goog:chromeOptions": {
        args: [
          "--lang=en-US",
          "--no-sandbox",
          "--incognito",
          '--headless',
          "--autoplay-policy=no-user-gesture-required", // https://developer.chrome.com/blog/autoplay/
          //'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36',
          "--log-level=3", // Disable unusual logging in windows run
          "--disable-gpu",
          "--start-maximized",
          "--disable-popup-blocking",
          "--profile-directory=Default",
          "--disable-infobars",
          "--ignore-certificate-errors",
          "--disable-plugins-discovery",
          "--disable-dev-shm-usage",
          "--no-service-autorun",
          "--no-default-browser-check",
          "--disable-blink-features=AutomationControlled",
          "--disable-infobars",
          "--disable-browser-side-navigation",
          "--disable-translate",
          "--disable-extensions",
          "--allow-insecure-localhost",
          "--window-size=1920,1080", // This is browser size
          "--disable-features=VizDisplayCompositor",
          "--disable-prompt-on-repost",
          "--new-window",
          //"--headless",
        ],
      },
      acceptInsecureCerts: true,

What happened?

Working example of this bus is present here : https://github.com/arundhatid/Junit-Report
I am using following dev dependencies to run the UI automation tests:

"devDependencies": {
    "@babel/core": "^7.20.2",
    "@babel/preset-env": "^7.20.2",
    "@babel/register": "^7.18.9",
    "@wdio/allure-reporter": "^7.18.0",
    "@wdio/cli": "^7.27.0",
    "@wdio/dot-reporter": "^7.19.7",
    "@wdio/junit-reporter": "^7.31.1",
    "@wdio/local-runner": "^7.27.0",
    "@wdio/mocha-framework": "^7.26.0",
    "@wdio/selenium-standalone-service": "^7.26.0",
    "@wdio/spec-reporter": "^7.26.0",
    "allure-commandline": "^2.17.2",
    "chai": "^4.3.4",
    "chromedriver": "^109.0.0",
    "totp-generator": "^0.0.13",
    "wdio-allure-reporter": "^0.8.3",
    "wdio-chromedriver-service": "^7.3.2",
    "wdio-image-comparison-service": "^3.1.1",
    "wdio-video-reporter": "^3.2.0"
  },

wdio.conf.js file is as follows:


const path = require("path");
const { join } = require("path");
exports.config = {

  baseUrl: process.env,
  suites: {
    REGRESSION: [
      [
        "./test/specs/RegressionTests/001.test1.spec.js",
        "./test/specs/RegressionTests/933741.test2.spec.js",
      ],
    ],
    PERFORMANCE: [
      ["./test/specs/PerformanceTest/PerformanceTest.spec.js"],
    ],
  },

  specs: ["./test/specs/**/*.js"],
  // Patterns to exclude.
  exclude: [
    // 'path/to/excluded/files'
  ],
  capabilities: [
    {
      // maxInstances can get overwritten per capability. So if you have an in-house Selenium
      // grid with only 5 firefox instances available you can make sure that not more than
      // 5 instances get started at a time.
      maxInstances: 5,
      //
      browserName: "chrome",
      "goog:chromeOptions": {
        args: [
          "--lang=en-US",
          "--no-sandbox",
          "--incognito",
          '--headless',
          "--autoplay-policy=no-user-gesture-required", // https://developer.chrome.com/blog/autoplay/
          //'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36',
          "--log-level=3", // Disable unusual logging in windows run
          "--disable-gpu",
          "--start-maximized",
          "--disable-popup-blocking",
          "--profile-directory=Default",
          "--disable-infobars",
          "--ignore-certificate-errors",
          "--disable-plugins-discovery",
          "--disable-dev-shm-usage",
          "--no-service-autorun",
          "--no-default-browser-check",
          "--disable-blink-features=AutomationControlled",
          "--disable-infobars",
          "--disable-browser-side-navigation",
          "--disable-translate",
          "--disable-extensions",
          "--allow-insecure-localhost",
          "--window-size=1920,1080", // This is browser size
          "--disable-features=VizDisplayCompositor",
          "--disable-prompt-on-repost",
          "--new-window",
          //"--headless",
        ],
      },
      acceptInsecureCerts: true,
    },
  ],
 
  logLevels: {
    webdriver: "info",
    "@wdio/appium-service": "info",
  },
 
  bail: 0,
 
  baseUrl: "http://localhost",
 
  waitforTimeout: 90000,
 
  connectionRetryTimeout: 120000,
 
  connectionRetryCount: 3,
 
  services: [
    [
      [
        "chromedriver",
        {
          logFileName: "wdio-chromedriver.log", // default
          outputDir: "driver-logs", // overwrites the config.outputDir
          args: ["--silent"],
          chromedriverCustomPath:
            "C:\\some path\\chromedriver_win32 (1)",
        },
      ],
    ],

    [
      [
        "image-comparison",
        // The options
        {
          actualFolder: path.join(process.cwd()),
          baselineFolder: join(process.cwd(), "./basline"),
          formatImageName: "{tag}",
          screenshotPath: join(process.cwd(), "./screenshots"),
          savePerInstance: false,
          autoSaveBaseline: true,
          blockOutStatusBar: true,
          blockOutToolBar: true,
          clearRuntimeFolder: true,
          disableCSSAnimation: true,
          ignoreAlpha: true,
          ignoreAntialiasing: true,
        },
      ],
    ],
  ],

  framework: "mocha",
  mochaOpts: {
    ui: "bdd",
    timeout: 1200000,
  },
  afterTest: function (
    test,
    context,
    { error, result, duration, passed, retries }
  ) {},

  afterSuite: function (suite) {
    test, context, { error, result, duration, passed, retries };
  },
  reporters: ['dot',    
    ['junit', {
        outputDir: './reports',   
        outputFileFormat: function(options) { // optional
            return `mycustomfilename.xml`
        }
    }]
  ],  
};

When I run the regression test , it runs successfully. the junit report file which is mycustomfilename.xml is also generated. However, for each test case which is executed, it shows me two entries.

image

What is your expected behavior?

Junit report should show me only 1 test case since only one test case was executed

How to reproduce the bug.

001.test1.spec.js file is as follows:

var expectchai = require("chai").expect;

  describe("browser Launch:", async () => {
    
    it("Authentication", async () => {
      console.log('Testing Authentication')
          })
      
  })

933741.test2.spec.js is as follows:

var expectchai = require("chai").expect;
describe("Test Script 1", async () => {
  // after(async () => {
  //    await zoomToExtend.removeOldAction();
  // });

  it("Test Case1", async () => {
    console.log('Test Case1')
  });

  it("Test Case2", async () => {
    console.log('Test Case2')
  });

  it("Test Case3", async () => {
    
    console.log('Test Case3')
  });

  it("Test Case4", async () => {
    console.log('Test Case4')
  });

  it("Test Case5", async () => {
    console.log('Test Case5')
  });
  it("Test Case6", async () => {
    console.log("Test Case6");
    
  });

  it("Test Case7", async () => {
    console.log('Test Case7')
  });

  it("Test Case8", async () => {
    console.log('Test Case8')
  });
});

I run the test using command npm run regression

Relevant log output

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="browser Launch" timestamp="2023-08-17T11:55:31" time="0.004" tests="1" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="browser Launch:"/>
      <property name="capabilities" value="chromeheadless.115_0_5790_171.win32"/>
      <property name="file" value=".\test\specs\RegressionTests\001.test1.spec.js"/>
    </properties>
    <testcase classname="chromeheadless.115_0_5790_171.win32.browser_Launch:" name="Authentication" time="0.003"/>
  </testsuite>
  <testsuite name="Test Script 1" timestamp="2023-08-17T11:55:31" time="0.004" tests="8" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="Test Script 1"/>
      <property name="capabilities" value="chromeheadless.115_0_5790_171.win32"/>
      <property name="file" value=".\test\specs\RegressionTests\001.test1.spec.js"/>
    </properties>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case1" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case2" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case3" time="0.001"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case4" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case5" time="0.001"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case6" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case7" time="0.001"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case8" time="0">
      <system-out><![CDATA[
COMMAND: deleteSession - {}
RESULT: undefined
]]></system-out>
    </testcase>
  </testsuite>
  <testsuite name="browser Launch" timestamp="2023-08-17T11:55:31" time="0.004" tests="1" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="browser Launch:"/>
      <property name="capabilities" value="chromeheadless.115_0_5790_171.win32"/>
      <property name="file" value=".\test\specs\RegressionTests\933741.test2.spec.js"/>
    </properties>
    <testcase classname="chromeheadless.115_0_5790_171.win32.browser_Launch:" name="Authentication" time="0.003"/>
  </testsuite>
  <testsuite name="Test Script 1" timestamp="2023-08-17T11:55:31" time="0.004" tests="8" failures="0" errors="0" skipped="0">
    <properties>
      <property name="specId" value="0"/>
      <property name="suiteName" value="Test Script 1"/>
      <property name="capabilities" value="chromeheadless.115_0_5790_171.win32"/>
      <property name="file" value=".\test\specs\RegressionTests\933741.test2.spec.js"/>
    </properties>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case1" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case2" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case3" time="0.001"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case4" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case5" time="0.001"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case6" time="0"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case7" time="0.001"/>
    <testcase classname="chromeheadless.115_0_5790_171.win32.Test_Script_1" name="Test Case8" time="0">
      <system-out><![CDATA[
COMMAND: deleteSession - {}
RESULT: undefined
]]></system-out>
    </testcase>
  </testsuite>
</testsuites>

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions