Automating Defect Logging with Jira and Selenium for algoQA Projects
Automate defect logging by integrating Jira with Selenium in algoQA projects to automatically create Jira tickets when tests fail.
Jira Overview
Jira is a tool used for bug and issue tracking. It also supports project management features for all kinds of use cases, from requirements and test case management to Agile software development.
Jira is free to use for up to 20 users. However, if any organization requires additional features, such as support, storage, and a large user limit, they must choose the commercial version. Since Jira is a bug/issue tracking tool, it enables the assignment, resolution, and implementation of bug life cycle management.
Integrating Jira with your Selenium framework can be helpful for managing issues that occur during automated testing. If an algoQA-generated script fails, Jira can be used to create a defect ticket automatically, which can then be assigned for resolution. This integration helps in the defect management process and ensures that issues are addressed.
Setting Up Jira Software with Your Google Account
Perform the following:
- Enter the URL Products | Atlassian into the browser bar.
- Select Jira Software. On this page, select the Get it free button in the top-right corner.
- The Get started with Jira page appears. Click the Google account button to create your account.
- Follow the on-screen prompts to create your first project.
Creating an API Token for Secure Integration with Jira
To enable secure connections between various software tools or automation scripts and your Jira account, you can create an API token. This token allows these tools to interact with Jira on your behalf without requiring your Jira password. This approach ensures security while facilitating smooth collaboration between different tools.
Perform the following to create an API token in Jira for use in Selenium Jira integration:
Open a web browser and go to your organization's Jira website.
For example, if your organization's Jira website is https://example.atlassian.net/, enter this URL in the address bar and press Enter.
Log in to your Jira account using your credentials (username and password).
After logging in, click the icon next to your profile and settings icon or username in the top-right corner of the Jira dashboard.
Select the Account Settings option.

Navigate to the Security tab, then click the Create and manage API tokens link.

In the API Tokens screen, click the Create API token button.

Enter the label and click the Create button.

Upon creating the API token, click the Copy button to copy the token to the clipboard and save it to an appropriate location.

Integrating Selenium with Jira and logging defects in Jira using algoQA Project
Applies to the JUnit, Selenium, and Maven framework with Java as the programming language.
Prerequisites
- Click here to download Eclipse IDE packages.
- Maven Project must be configured.
Creating a Jira Ticket when a Selenium test fails.
To automatically create a Jira ticket when a Selenium test fails, and skip ticket creation if the same ticket has already been created in the project, perform the following:
Add the required dependencies in pom.xml
- In order to integrate Jira with Selenium, use rcarz Jira-client. This is a wrapper built on top of the Jira REST API client. This file enables communication between Selenium and Jira, allowing Selenium tests to interact with Jira's features like creating and updating issues, and querying issue details.
- Scripts generated by algoQA follow a structured folder structure. Navigate to pom.xml in the project, and add the following dependency:

- Create basic tests using Selenium and Java.
- In the com.demo.projectpackage, two basic Selenium tests have been created: one designed to pass and one to fail. These tests can serve as examples for understanding Selenium test creation and execution.

Create a utility to handle Jira issues
Custom annotations can be used to mark specific test methods or classes to indicate that they should create Jira issues when certain conditions are met, such as a test failure.
This allows you to automate the process of creating Jira issues for failed tests, making it easier to track and manage issues related to your test automation. To create a package inside the main folder of your project, for example, com.demo.utility. Create a package to hold the utility classes related to Jira integration.

-
Create the JiraServiceProvider class: This class will handle the creation of Jira issues.\
Code snippet:

-
Create the JiraCreateIssue annotation: This annotation will be used to mark specific test methods or classes that should create Jira issues.
Code snippet:
Configure the Hooks File
In an algoQA-generated script folder structure, the hooks file contains code that runs before or after scenarios in your test suite. If there is a failure in a scenario, you can use the hooks file to perform certain actions, such as logging the failure, taking screenshots, or notifying team members.
The project folder structure is displayed.

To get the Project Key, perform the following:
- Navigate to the Projects main menu and select View All Projects.

- Choose the respective project.
- In the Project page, the key will be displayed next to the corresponding project name.

Configure the ApplicationSettings.xml file
- Navigate to the ApplicationSettings.xml file in your algoQA-generated script folder
- Set the Jira Integration parameter to true and add all the required parameters.

When you create a JiraServiceProvider object, consider the following parameters:
| Field | Description |
|---|---|
| JiraUrl | Indicates the company's Jira URL. If you are working on Jira Cloud, then the URL will be: https://<organisation>.atlassian.net |
| Username | The user is a parameter used for authentication, but its format can vary based on configuration. For example, the format is <Username>@gmail.com |
| Password | When using Jira Cloud, it is necessary to pass the API token as the password. Using your login password might not work. For example, the API token could be lorelimpusm12uijk. |
| Project Key | This refers to the project key, which is typically a short, two-letter identifier (e.g., "AS") assigned by Jira. Using the full project name, such as "Algoshack Project," might not work, so it's important to always use the short version. |
| Issue Type | Indicates the category of an issue. For example, Bug. |
| Reporter Name | Name of the person in the project who is reporting the bug. |
Configure the testng.xml file
After all the required setup, the testng.xml file must be configured to run the tests.
-
Execute your tests
Upon completing the setup, execute the tests. After test execution, any failures must automatically trigger the creation of a Jira ticket. Results will be visible in the console section for further analysis and verification.
The following screenshot represents sample console output:

Successful completion of Selenium tests triggers the automatic creation of a Jira issue, with the console displaying the issue ID and providing a URL to navigate to the specific issue.
-
Verifying Jira ticket creation
Navigate to the Jira dashboard to check whether an issue has been created. In the Jira dashboard, click the project dashboard to see if a new issue has been created, along with the particular test step failure details and issue details.

Most of the operations performed through the Jira user interface can be run using the REST API client. The Jira REST API client allows testers to automate the issue tracking and logging process, reducing the need for manual effort and attention.