Skip to content

Smoliarick/cypress-testrail-integration-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example for cypress-testrail-integration package

⚠️ Check that all Test Case IDs, which you use, are existed in Test Rail. If you try to add a new Test Run (if you don't use existed Test Run ID), it doesn't work, because Test Rail API doesn't allow creating a new Test Run using non-existed IDs. Example: you have these Test Case IDs = ['1', '2', '3'], your Cypress autotests have these IDs in results = ['1', '2', '3', '4'] => error! because Test Rail doesn't contain Test Case with ID = 4.

  1. Clone this project:
  • https://github.com/Smoliarick/cypress-testrail-integration-example.git for HTTPS
  • [email protected]:Smoliarick/cypress-testrail-integration-example.git for SSH
  1. Run npm install command
  2. Create .env file with configs for Test Rail. You can use this example:
TESTRAIL_USERNAME=your_testrail_username
TESTRAIL_PASSWORD=your_testrail_password
TESTRAIL_HOSTNAME=https://your_domain.testrail.io/
TESTRAIL_PROJECT_ID=your_testrail_project_id
  1. Create several Test Cases into your Test Rail and add their IDs into the autotests using this template:
it('C1, C2: Verify that google page has input field', () => {
  cy.visit('https://www.google.com/');
  cy.get('input').should('be.visible');
});

where C1 and C2 are Test Case IDs. You can use another letter for Test Case IDs. Add , to separate several Test Case IDs. If you want to use only 1 Test Case ID, don't add a new ,. Example:

it('C3: Verify that google page doesn\'t have input field ', () => {
  cy.visit('https://www.google.com/');
  cy.get('input').should('not.be.visible');
});
  1. Run npx cypress run command
  2. When Cypress Run is completed, open Test Runs in Test Rail. New Test Run with default name (e.g. 2023-01-03 Test Run: Cypress Autotest) and results from Cypress Run should be created

Add a new parser for autotest's titles

Default template for autotests:

it('[Test Case IDs with any first letter]: [Autotest\'s title]', () => {
  // autotest
});

Example:

it('C1, C2: Verify that google page has input field', () => {
  // autotest
});
it('C3: Verify that google page doesn\'t have input field ', () => {
  // autotest
});

If you want to add a new parser for autotest's titles, add it into the constructor. Example:

setupNodeEvents(on, config) {
  on('after:run', async (results) => {
    function newParser(title) { // new parser
      const splittedTitle = title.split(':');
      const testCaseIds = splittedTitle[0]
        .split(',')
        .map((element) => element = element.trim().substring(1));
      return testCaseIds;
    }
        
    const TestrailIntegration = require('cypress-testrail-integration');
    const testrailIntegration = new TestrailIntegration(
      process.env.TESTRAIL_USERNAME,
      process.env.TESTRAIL_PASSWORD,
      process.env.TESTRAIL_HOSTNAME,
      process.env.TESTRAIL_PROJECT_ID,
      parser = newParser // adding a new parser
    );
    await testrailIntegration.addResultsToTestRailTestRun(results);
  });
  return config;
},

⚠️ Be careful, new parser should return array of the Test Case IDs. Example: ['1', '2', '3', '4', '5', '6', '7'] or ['1'] for 1 Test Case ID.

Add another title for Test Rail Test Run

Default name is [Today's date] Test Run: Cypress Autotest, e.g. 2023-01-03 Test Run: Cypress Autotest.

If you want to add a new name for Test Rail Test Run, add it into the constructor. Example:

setupNodeEvents(on, config) {
  on('after:run', async (results) => {   
    const TestrailIntegration = require('cypress-testrail-integration');
    const testrailIntegration = new TestrailIntegration(
      process.env.TESTRAIL_USERNAME,
      process.env.TESTRAIL_PASSWORD,
      process.env.TESTRAIL_HOSTNAME,
      process.env.TESTRAIL_PROJECT_ID,
      testRunName = 'New Test Run' // adding a new name for Test Run
    );
    await testrailIntegration.addResultsToTestRailTestRun(results);
  });
  return config;
},

Video example with running

2023-01-03.12-36-21.mp4