Using Tags option for running only certain tests

Hi community, I created a simple script containing two groups, each of them with a single get request, like this:

import http from 'k6/http'
import { check, group } from 'k6'

export const options = {
  stages: [{ duration: '1m', target: 2 }],
  thresholds: {
    http_req_duration: ['p(90)<12000'],
  },
}

export default function () {
  group('getContacts', () => {
    const responseContent = http.get("https://test.k6.io/contacts.php", {
      tags: { name: 'getContacts' },
      responseType: 'text',
    })

    check(responseContent, {
      'response code was 200': (response) => response.status === 200,
      'response body contains this string': (response) => response.body.includes("Load Impact AB"),
    })
  })

  group('getNews', () => {
    const responseContent = http.get("https://test.k6.io/news.php", {
      tags: { name: 'getNews' },
      responseType: 'text',
    })

    check(responseContent, {
      'response code was 200': (response) => response.status === 200,
      'response body contains this string': (response) => response.body.includes("In the news"),
    })
  })
}

as you can see we set a tag name for each group, getNews and getContacts respectively.

My question is, could I set the tag name as an option when executing the script for running only specific requests?, for example:

k6 run tag-test.spec.js --http-debug="full" --tag NAME=getNews

From my results, I see that both requests are being sent instead the set one.

Let me know if you need additional information or if something is not clear on my end.

Thanks!

Hi @danielcatanoro !

Welcome to the community forums! :wave:

The purpose of the tags is different, and it’s impossible to achieve something you want by using them.

However, I something answered in the topic How to run only certain groups of requests can help you.

Let me know if that helps,
Cheers!

1 Like