In this article, I shall demonstrate a simple way we can integrate k6 with XRAY/Jira.
Sometime back I was assigned a task to write a performance test for an API that was expected to handle quite a number of requests. For this reason we needed a good tool which will be faster to pickup and easier for any QA engineer to contribute.
Having used load impact in the past, I was quite familiar with K6. These are the main reasons why we chose k6 over the other performance testing tools:
Uses Javascript: Most of the QA/Developers in my team were familiar with javascript, therefor which made it as there was no need to learn a new language
Open-source: This means, no payments are required to use the tool, and the community is active
CI/CD: Integrating k6 with our CI/CD pipelines was straightforward
I can continue with the advantages of choosing k6, but I shall write a new post to talk about that specifically.
After completing our test framework, we wanted to have our test results on Jira. Since we were already using XRAY, we needed a solution to convert the k6 JSON report to x-ray format. I couldn't get any solution that worked with our case.
K6 handleSummary()
K6 has an essential feature that can be used to get all the metrics. These options are stdout, XML, and JSON.
For this, we only needed to create a script to take in the data object from the handleSummary function.
Below is the script to convert the data object from k6 to a simple XRAY format report:
k6-XRAY-script
How to Setup the generator Helper Script for k6 and Xray Integration
Clone the repo to your desired location:
Preferably, create a folder inside the main project.
Example:
helper, src, report
This will help you manage the imports well without issues:
Prerequisites
Before you begin, ensure you have the following installed on your machine:
- Node.js
- npm
- k6
Usage
If your k6 tests are organized in groups, and each group title corresponds to a test case on Xray, you can use the generator script to create a JSON file compatible with Xray.
Example
The image below from Xray docs shows test cases with keys CALC-01 and CALC-02.
In your k6 test script, you can name the group titles as CALC-01 and CALC-02. The script will search for these group names and assign the test results to the respective test cases on Xray.
group('CALC-01', function() { // test code }); group('CALC-02', function() { // test code });
Output
The script generates a JSON file compatible with Xray, saved in the same directory as the script.
Clone the repo
git clone https://github.com/skingori/k6-json-xray.git
How to Setup the Script
We will use the handleSummary function provided by k6 and textSummary from our generator.js script to generate the JSON file. The handleSummary function takes in a data object, which we pass to getSummary to modify it into an Xray-compatible format.
Read more about k6 HandleSummary here
Change open your execution script and add the following lines:
import { getSummary } from "./generator.js"; import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
I am using the ./generator.js directly as it was in the same folder as my script. Let's assume you were using helper this should be:
import { getSummary } from "./helper/generator.js";
Add the end of your code add the handleSummary function:
export function handleSummary(data) { return { stdout: textSummary(data, { indent: " ", enableColors: true }), "summary.json": JSON.stringify(getSummary(data, "CALC-2062", "CALC"), null, 2) }; }
Our function getSummary will convert the data object to x-ray expected format and save the output to summary.json file
Why are we using textSummary?
To have a printed output on the console, we need to import textSummary from k6 JS utilities library
But this may not apply to everyone if you don't need any stdout report, you don't have to import the textSummary
Example
import http from 'k6/http'; import { sleep, group, check } from 'k6'; import { getSummary } from "./generator.js"; import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js"; export const options = { vus: 10, duration: '30s', }; export default function() { group('CALC-01', function() { const resp = http.get('http://test.k6.io'); check(resp, { 'status is 200': (r) => r.status === 200, }); sleep(1); }); group('CALC-02', function() { const resp = http.get('http://test.k6.io'); check(resp, { 'status is 200': (r) => r.status === 200, }); sleep(1); }); }; export function handleSummary(data) { return { stdout: textSummary(data, { indent: " ", enableColors: true }), "summary.json": JSON.stringify(getSummary(data, "CALC-2062", "CALC"), null, 2) }; }
Note: You can eliminate stdout: textSummary(data, { indent: " ", enableColors: true }), line if you don't want to import textSummary
handleSummary works by default and it's usually called at the end of the test lifecycle.
Running the Script
To run the script, use the following command:
k6 run script.js -e TEST_PLAN_KEY="CALC-2345" -e TEST_EXEC_KEY="CALC-0009"
The TEST_PLAN_KEY and TEST_EXEC_KEY are used to identify the test plan and test execution on Xray.
Read more about test plan and test execution keys here
Output
The above script will produce the following report under summary.json
{ "info": { "summary": "K6 Test execution - Mon Sep 09 2024 21:20:16 GMT+0300 (EAT)", "description": "This is k6 test with maximum iteration duration of 4.95s, 198 passed requests and 0 failures on checks", "user": "k6-user", "startDate": "2024-09-09T18:20:16.000Z", "finishDate": "2024-09-09T18:20:16.000Z", "testPlanKey": "CALC-2345" }, "testExecutionKey": "CALC-0009", "tests": [ { "testKey": "CALC-01", "start": "2024-09-09T18:20:16.000Z", "finish": "2024-09-09T18:20:16.000Z", "comment": "Test execution passed", "status": "PASSED" }, { "testKey": "CALC-02", "start": "2024-09-09T18:20:16.000Z", "finish": "2024-09-09T18:20:16.000Z", "comment": "Test execution passed", "status": "PASSED" } ] }
To get more details about k6 and X-ray kindly reach out to their documentation:
K6 Document
XRAY Document
Lihat ini juga - Cara mencipta dan mengurus kes ujian dengan Xray dan Jira artikel hebat yang ditulis oleh Sérgio Freire
Dan seperti biasa, sila hubungi saya!
LinkedIn
E-mel
Github
The above is the detailed content of How to integrate kith Xray/Jira. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
