You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like we can iterate through data within the step, but we can't do that for entire test case. Is it possible to support looping in test case level?
Also, is it possible to capture the outputs of the step to the vars if we use range?
Something like this. The range is at the test case level. That way you could group a number of steps for each item in the range array.
EDIT: It occured to me this example isn't perfect, since it's using exec twice and they could be combined into one step, but if you were using sql in the first step and http in the second, that would be a more accurate example.
---
name: RangeTestCaseExample
description: >
Simple example demonstrating the need for range at testcase level.
Currently this doesn't work but would be very useful for data-driven testing.
vars:
databases:
- name: postgres
port: 5432
command: "psql --version"
- name: mysql
port: 3306
command: "mysql --version"
- name: mongodb
port: 27017
command: "mongod --version"
testcases:
# This is what we WANT to be able to do (but currently doesn't work)
- name: DatabaseConnectionTest
info: Test connection to {{.value.name}} database
range: >
{{.databases}}
steps:
- info: Check if {{.value.name}} is installed
type: exec
script: "{{.value.command}}"
assertions:
- result.systemout ShouldNotBeEmpty
- result.code ShouldEqual 0
- info: Test {{.value.name}} port availability
type: exec
script: "nc -z localhost {{.value.port}} || echo 'Port {{.value.port}} not available'"
assertions:
- result.code ShouldEqual 0
This is what we have to do instead (much more verbose and repetitive)
- name: PostgresConnectionTest
info: Test connection to postgres database
steps:
- info: Check if postgres is installed
type: exec
script: "psql --version"
assertions:
- result.systemout ShouldNotBeEmpty
- result.code ShouldEqual 0
- info: Test postgres port availability
type: exec
script: "nc -z localhost 5432 || echo 'Port 5432 not available'"
assertions:
- result.code ShouldEqual 0
- name: MySQLConnectionTest
info: Test connection to mysql database
steps:
- info: Check if mysql is installed
type: exec
script: "mysql --version"
assertions:
- result.systemout ShouldNotBeEmpty
- result.code ShouldEqual 0
- info: Test mysql port availability
type: exec
script: "nc -z localhost 3306 || echo 'Port 3306 not available'"
assertions:
- result.code ShouldEqual 0
- name: MongoDBConnectionTest
info: Test connection to mongodb database
steps:
- info: Check if mongodb is installed
type: exec
script: "mongod --version"
assertions:
- result.systemout ShouldNotBeEmpty
- result.code ShouldEqual 0
- info: Test mongodb port availability
type: exec
script: "nc -z localhost 27017 || echo 'Port 27017 not available'"
assertions:
- result.code ShouldEqual 0
Activity
09bassOp commentedon Jul 28, 2025
It is possible. Can you elaborate more on the expected behavior? @joh9347
shanestillwell commentedon Aug 11, 2025
Something like this. The
rangeis at the test case level. That way you could group a number of steps for each item in the range array.This is what we have to do instead (much more verbose and repetitive)