You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Overview

In this tutorial, we will create some tests in JavaScript using CodeceptJS and we'll use mocha-junit-reporter to generate a compatible JUnit XML report.

Requirements

  • pupetteer
  • jest-environment-node
  • jest
  • jest-junit

Code

The following code and the setup instructions were inspired on jest-puppeteer-example tutorial.

The first thing we need to do is configure jest to use the "jtest-junit" reporter, in order to produce a JUnit XML report.


jest.config.js
module.exports = {
  globalSetup: './setup.js',
  globalTeardown: './teardown.js',
  testEnvironment: './puppeteer_environment.js',
  reporters: [ "default", "jest-junit" ]
}



We will create a simple test based on Google search.

_tests_/google.js
const timeout = 5000

describe(
  '/ (Search Home Page)',
  () => {
    let page
    beforeAll(async () => {
      page = await global.__BROWSER__.newPage()
      await page.goto('https://www.google.com', { waitUntil: 'networkidle0' })
    }, timeout)

    afterAll(async () => {
      await page.close()
    })

    it('should return a proper title', async () => {
      // just to make sure
      const title = await page.title();
      expect(title).toBe('Google');
    })
    it('should return link to Marketplace upon searching Xray', async () => {
      await page.waitForSelector('input#lst-ib',{ visible: true});
      await page.type('input#lst-ib', 'Xray test management')

      await page.screenshot({path: 'screenshot1.png'});
      await page.keyboard.press('Enter');

      await page.waitForSelector('div#rcnt',{ visible: true});
      await page.screenshot({path: 'screenshot2.png'});
      const results = await page.evaluate(() => document.querySelector('div#rcnt').innerText);
      expect(results).toContain('Xray - Test Management for Jira | Atlassian Marketplace');
    })
  },
  timeout
)


After running the test(s) and generating the JUnit XML report (e.g. junit.xml), it can be imported to Xray (either by the REST API or through the Import Execution Results action within the Test Execution).

npm test __test__/google.js



Each Scenario is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the name of the Scenario concatenated with the name of the Feature.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the name of the Feature.

References

  • No labels