feature "HTTP POST with foreach using httpbin"
actors: Web, System
var URL = "https://httpbin.io"
var PRODUCTS = ["PROD-A", "PROD-B", "PROD-C"]
scenario "Adding multiple items to the cart" {
# 1. The foreach loop iterates over the PRODUCTS array.
foreach ITEM in ${PRODUCTS} {
# 2. A test block is defined inside. The loop variable `ITEM`
# is used to create a unique and descriptive test name.
test AddToCart "Add ${ITEM} to cart" {
given:
Test can_start
System log "Adding item: ${ITEM}"
when:
Web set_header "Content-Type" "application/x-www-form-urlencoded"
# 3. The loop variable is used in the request body.
Web http_post "${URL}/post" with_body "product_id=${ITEM}"
then:
Web response_status_is 200
# 4. The loop variable is used in the assertion.
Web response_body_contains "product_id=${ITEM}"
}
}
}