{"id":29177,"date":"2025-10-17T12:24:16","date_gmt":"2025-10-17T12:24:16","guid":{"rendered":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/?page_id=29177"},"modified":"2025-10-17T21:43:35","modified_gmt":"2025-10-17T12:43:35","slug":"k6","status":"publish","type":"page","link":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/test-automation\/automation-frameworks\/k6\/","title":{"rendered":"Integrating with K6"},"content":{"rendered":"<p class=\"wysiwyg-text-align-justify\"><a href=\"https:\/\/k6.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">k6<\/a> is an open-source, developer-friendly, and extensible load testing tool, that allows to prevent performance issues and proactively improve reliability. Using k6, you can test the reliability and performance of your application and infrastructure, preventing errors and SLO breaches, enabling to build resilient and high-performing applications that scale.<\/p>\n<p class=\"wysiwyg-text-align-justify\">In this tutorial, we\u2019ll explore how to integrate k6 test results into TestRail using the <a href=\"\/testrail-cli\/overview-and-installation\/\" target=\"_blank\" rel=\"noopener\">TestRail CLI<\/a>. This integration enables you to centralize automated test results and leverage TestRail\u2019s analytical and reporting capabilities.<\/p>\n<h2 id=\"01G75119Y2NVKTNND00MJ4YKPC\" class=\"wysiwyg-text-align-justify\">Overview<\/h2>\n<p>In this tutorial, we\u2019ll use a <a href=\"https:\/\/github.com\/gurock\/automation-frameworks-integration\/tree\/main\/samples\/k6\" target=\"_blank\" rel=\"noopener\">sample project<\/a> to walk you through setting up a k6 performance test project that integrates with the TestRail CLI to upload the generated test results.<\/p>\n<p>By the end of this tutorial, you will be able to:<\/p>\n<ul>\n<li>Execute tests from a simple k6 project<\/li>\n<li>Install the TestRail CLI<\/li>\n<li>Configure your TestRail instance<\/li>\n<li>Use the CLI to execute performance tests and upload results to TestRail<\/li>\n<li>View your test cases and results in TestRail<\/li>\n<\/ul>\n<h2 id=\"01G75119Y2K6SRBV3GVTSMGXHR\">Prerequisites<\/h2>\n<p>To be able to run a k6 tests project you can install it through npm, so <a href=\"https:\/\/nodejs.org\/en\" target=\"_blank\" rel=\"noopener noreferrer\">Node.js<\/a> is considered a pre-requisite.<\/p>\n<p>You will also need <a href=\"https:\/\/www.python.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Python<\/a> to install and run the TestRail CLI that will be used to import the test results to TestRail.<\/p>\n<table class=\"table table--hover\" style=\"border-collapse: collapse; width: 100%;\">\n<thead>\n<tr>\n<th style=\"width: 21.5714%;\">Prerequisite<\/th>\n<th style=\"width: 78.2857%;\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"width: 21.5714%;\"><a href=\"https:\/\/nodejs.org\/en\/\" target=\"_blank\" rel=\"noopener\">Node.js<\/a><\/td>\n<td style=\"width: 78.2857%;\">Download the version for your operating system and follow the install wizard instructions.<br \/>\nTo make sure the install was successful, try executing the commands <code class=\"inline-code\">node --version<\/code> and <code class=\"inline-code\">npm --version<\/code> from your command line and they should output the installed version.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 21.5714%;\"><a href=\"https:\/\/www.python.org\/downloads\/release\/python-3104\/\" target=\"_blank\" rel=\"noopener\">Python 3.10.4<\/a><\/td>\n<td style=\"width: 78.2857%;\">Download the version for your operating system and follow the install wizard instructions.To make sure the install was successful, try executing the commands <code class=\"inline-code\">python --version<\/code> and <code class=\"inline-code\">pip --version<\/code> from your command line and they should output their versions.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"01G75119Y22FTVXMYFB9ZQYJK9\">Installing the sample project<\/h2>\n<p>Let\u2019s start by fetching the sample project code and installing the required dependencies.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol class=\"list-colored\">\n<li>Clone or download the <a href=\"https:\/\/github.com\/gurock\/automation-frameworks-integration\/tree\/main\/samples\/k6\" target=\"_blank\" rel=\"noopener\">sample project<\/a><\/li>\n<li>Open your command prompt on the project root folder and execute the command below<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<pre><code class=\"shell\">$ npm install -g k6\n$ npm install -g k6-to-junit<\/code><\/pre>\n<p><strong>Note: <\/strong><em>k6-to-junit<\/em> is a simple command line utility to convert the stdout of k6 tests into a junit xml format, ready to be used for TRCLI. Currently this just works by looking for thresholds in the output and creating a testcase for each threshold in the output xml file.<\/p>\n<h2 id=\"01G75119Y2Q97D9RMMXDP7R4XS\">Exploring the sample project<\/h2>\n<p>Use your favorite IDE to open the sample project and start digging into the test files. We\u2019ve kept the automated tests code simple so that the focus of this tutorial remains on how to import the execution results. These tests consist of simple interactions with a free fake and reliable API for testing.<\/p>\n<pre><code class=\"java\">import http from 'k6\/http';\nimport { check, group } from 'k6';\n\nconst baseUrl = 'http:\/\/jsonplaceholder.typicode.com';\n\nexport const options = {\n  vus: 5,\n  stages: [\n    { duration: '10s', target: 10 }\n  ],\n  thresholds: {\n    http_req_failed: ['rate&lt;0.01'],\n    http_req_duration:=['p(95)=\"p(95)'],\n    http_reqs: ['count = 1400', 'count &lt;= 1600'],\n  }\n}\n export default function () {\n  group('JSON Placeholder Performance Testing', function () {\n    group('Posts endpoint', function () {\n      const res = http.get(`${baseUrl}\/posts`);\n      check(res, {\n        'is status code 200': (r) = r.status === 200,\n      });\n    });\n  });\n}<\/code><\/pre>\n<p>Understanding the configuration and test objectives:<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol data-start=\"780\" data-end=\"1483\">\n<li data-start=\"780\" data-end=\"839\">\n<p data-start=\"783\" data-end=\"839\"><strong data-start=\"783\" data-end=\"795\"><code data-start=\"785\" data-end=\"793\">vus: 5<\/code><\/strong>: 5 Virtual Users (VUs) will start the test.<\/p>\n<\/li>\n<li data-start=\"841\" data-end=\"1018\">\n<p data-start=\"844\" data-end=\"857\"><strong data-start=\"844\" data-end=\"856\"><code data-start=\"846\" data-end=\"854\">stages<\/code><\/strong>:<\/p>\n<ul data-start=\"780\" data-end=\"1483\">\n<li data-start=\"861\" data-end=\"918\"><strong data-start=\"863\" data-end=\"884\"><code data-start=\"865\" data-end=\"882\">duration: '10s'<\/code><\/strong>: This stage (i.e., the test execution) lasts for 10 seconds.<\/li>\n<li data-start=\"922\" data-end=\"1018\"><strong data-start=\"924\" data-end=\"940\"><code data-start=\"926\" data-end=\"938\">target: 10<\/code><\/strong>: The number of VUs will gradually increase to 10 over the 10-second duration. So it will begin with 5 VUs and will achieve 10 VUs.<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"1020\" data-end=\"1483\">\n<p data-start=\"1023\" data-end=\"1096\"><strong data-start=\"1023\" data-end=\"1039\"><code data-start=\"1025\" data-end=\"1037\">thresholds<\/code><\/strong>: These are performance criteria that the test must meet:<\/p>\n<ul data-start=\"780\" data-end=\"1483\">\n<li data-start=\"1100\" data-end=\"1182\"><strong data-start=\"1102\" data-end=\"1138\"><code data-start=\"1104\" data-end=\"1136\">http_req_failed: ['rate&lt;0.01']<\/code><\/strong>: Less than 1% of HTTP requests should fail (request response 4xx or 5xx).<\/li>\n<li data-start=\"1186\" data-end=\"1353\"><strong data-start=\"1188\" data-end=\"1226\"><code data-start=\"1190\" data-end=\"1224\">http_req_duration: ['p(95)&lt;500']<\/code><\/strong>: The 95th percentile of HTTP request durations should be under 500ms (i.e., 95% of requests must complete in less than 500ms).<\/li>\n<li data-start=\"1357\" data-end=\"1483\"><strong data-start=\"1359\" data-end=\"1405\"><code data-start=\"1361\" data-end=\"1403\">http_reqs: ['count=1400', 'count&lt;=1600']<\/code><\/strong>: The test should result in at least 1400 HTTP requests and no more than 1600 HTTP requests.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2 id=\"01G75119Y21QRF2N6ZTVDT55SK\">Executing the sample project<\/h2>\n<p>On the same command prompt, execute the following command to run the k6 tests in the project and save the results in JUnit XML format.<\/p>\n<pre><code class=\"shell\">$ k6 run test_k6.js | k6-to-junit .\/reports\/junit.xml<\/code><\/pre>\n<p>If the k6 command was correctly executed, you should be able to see your test results on the reports folder.\u00a0 There should also be a file called <em>junit.xm<\/em><span class=\"wysiwyg-underline\"><em>l<\/em><\/span>, as per our command options, with test results in JUnit XML format. This is the file which will be parsed by the TestRail CLI in order to create the test run and upload your test results to TestRail on the next step.<\/p>\n<p><a href=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_01-1024x618.png\" alt=\"\" width=\"1024\" height=\"618\" class=\"aligncenter size-large wp-image-29184\" srcset=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_01-980x592.png 980w, https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_01-480x290.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/a><\/p>\n<h2 id=\"01G75119Y2H242KNXNAYXHR3G2\">Importing results to TestRail<\/h2>\n<p>After the tests have been executed and the JUnit report files are generated, you can easily import your test results (and test cases!) to TestRail. This will bring visibility to your automated test runs and will enable you to look at the big picture of how you\u2019re actually testing your app all within TestRail.<\/p>\n<h3 id=\"01G74W5ZPF70V4NQ21ETVF32HP\">Installing the TestRail CLI<\/h3>\n<p>Given you already have Python installed on your machine, installing the TestRail CLI is as simple as executing the following command on your command line.<\/p>\n<pre>$ pip install trcli<\/pre>\n<h3 id=\"01G74W5ZPFV5E48FZ7R2K2VKT6\">Configuring TestRail<\/h3>\n<p>Secondly, you need to configure your TestRail instance according to the instructions below.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Enable the <a href=\"\/api-manual\/getting-started-with-testrail-api\/introduction-api\/\" target=\"_blank\" rel=\"noopener\"><strong>TestRail API<\/strong><\/a> by going to <strong>Admin &gt; Site Settings<\/strong>, click on the <strong>API<\/strong> tab, and checking the <strong>Enable API<\/strong> option.<\/li>\n<li>Create a <a href=\"\/user-guide\/administration-and-customizations\/custom-fields\/\" target=\"_blank\" rel=\"noopener\"><strong>Custom Field<\/strong><\/a> in order to map your automated test cases code to the actual TestRail cases. You can do so by going to <strong>Admin &gt; Customizations<\/strong> and clicking <strong>Add Field<\/strong>. After you\u2019ve reached the field creation screen, there are two requirements for this custom field:\n<ul>\n<li>The <strong>System Name<\/strong> must be <em>automation_id<\/em><\/li>\n<li>The <strong>Type<\/strong> must be <em>Text<\/em><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h3 id=\"01G75135AQK5NE98CCGK0V3X9P\">Sending results to TestRail<\/h3>\n<p>After you\u2019re done installing the TestRail CLI and finished configuring your TestRail instance, you can upload your test results by simply using a one-liner such as the one below.<\/p>\n<pre><code class=\"shell\">$ trcli -y \n&gt;  -h https:\/\/INSERT-INSTANCE-NAME.testrail.io \n&gt;  --project \"My Project\" \n&gt;  --username INSERT-EMAIL \n&gt;  --password INSERT-PASSWORD \n&gt;  parse_junit \n&gt;  --title \"k6 Automated Test Run\" \n&gt;  -f \".\/test-results\/junit-report.xml\"<\/code><\/pre>\n<p>Note that the file name after the <strong>-f<\/strong> option should match the path to your report file in case you change its default location. All others options should be according to your TestRail instance and project. You can check other command line options by checking the <a href=\"https:\/\/github.com\/gurock\/trcli\/blob\/main\/README.md\" target=\"_blank\" rel=\"noopener noreferrer\">TestRail CLI README.md<\/a> file on the project repository, the TRCLI documentation article, or the embedded CLI help through the commands below.<\/p>\n<pre><code class=\"shell\">$ trcli --help\n$ trcli parse_junit --help<\/code><\/pre>\n<h3 id=\"01G7516DH0HBST87T8QBD87RJC\">Visualizing the results on TestRail<\/h3>\n<p>Now, if you go to the <strong>Test Cases<\/strong> page in your TestRail project, you\u2019ll notice that the TestRail CLI automatically created the test cases that were on your test results report.<\/p>\n<p><a href=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_02.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_02.png\" alt=\"\" width=\"291\" height=\"214\" class=\"aligncenter size-full wp-image-29185\" \/><\/a><\/p>\n<div class=\"callout callout--warning\">\n<p>On the <strong>Test Runs &amp; Results<\/strong> page, we can see that a test run with the name <strong>k6\u00a0Test Run<\/strong> was created. By opening it we can dig further into the details of each automated test result and perform a high level analysis of why any test is failing since the error message provided by the test automation framework is also registered on the test result, as you can see on the image below.<\/p>\n<p><a href=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_03-e1760704857414.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-content\/uploads\/k6_03-e1760704857414-150x150.png\" alt=\"\" width=\"150\" height=\"150\" class=\"aligncenter wp-image-29186 size-thumbnail\" \/><\/a><\/p>\n<\/div>\n<h2 id=\"01G74W5ZPGTYQ0PY1K37T54TF0\">What next?<\/h2>\n<p>Now that you have centralized your test results on TestRail, not only can you check the results of your automated test runs, along with the error messages for failed tests, but you can also aggregate both your manual and automated testing efforts on reports that show you the full test coverage surrounding your app and even track test automation progress. You can also report a bug directly from the automated test result to an issue tracker of your preference as you would do for your manual test results!<\/p>\n<p>You can look into the <a href=\"https:\/\/www.youtube.com\/watch?v=XXygDfOD2MY\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>TestRail\u2019s Reports and Test Metrics video<\/strong><\/a> to learn about how you can leverage TestRail\u2019s reporting capabilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>k6 is an open-source, developer-friendly, and extensible load testing tool, that allows to prevent performance [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":24156,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-29177","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/pages\/29177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/comments?post=29177"}],"version-history":[{"count":8,"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/pages\/29177\/revisions"}],"predecessor-version":[{"id":29188,"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/pages\/29177\/revisions\/29188"}],"up":[{"embeddable":true,"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/pages\/24156"}],"wp:attachment":[{"href":"https:\/\/docs.testrail.techmatrix.jp\/testrail\/docs\/9\/wp-json\/wp\/v2\/media?parent=29177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}