Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
titlejest.config.js
collapsetrue
module.exports = {
  globalSetup: './setup.js',
  globalTeardown: './teardown.js',
  testEnvironment: './puppeteer_environment.js',
  reporters: [ "default",
         ["jest-junit", {"classNameTemplate": "e2e","titleTemplate": "{classname} {title}"}]
        ]
}


We will create a two simple test tests based on Google search.

Code Block
languagejs
title__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) tests 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).

No Format
npm test __test__/google.js


Image RemovedImage Added


Each Scenario test/"it block" is mapped to a Generic Test in Jira, and the Generic Test Definition field contains an unique identifer based on the Test Suite and the test name. In fact, the jest-junit package allows full customization of the Scenario concatenated with the name of the Featuresome attributes of the JUnit XML, which in turn will allow you to define exactly how to fine tune the value for the "Generic Test Definition" field accordingly with the rules described in Taking advantage of JUnit XML reports.

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

Image RemovedImage Added

References