Home Web Front-end JS Tutorial How to integrate kith Xray/Jira

How to integrate kith Xray/Jira

Sep 10, 2024 am 11:30 AM

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.

How to integrate kith Xray/Jira

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
});
Copy after login

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
Copy after login

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";
Copy after login

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";
Copy after login

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)
    };
}
Copy after login

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)
    };
}
Copy after login

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"
Copy after login

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"
    }
  ]
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

JavaScript: Exploring the Versatility of a Web Language JavaScript: Exploring the Versatility of a Web Language Apr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles