How do I add random values to the request body using the Taurus performance test?

31 views Asked by At

This is my perfomanse test, but it's not clear how I can add random values for email and phone

taurus_config.yaml :

execution:
  concurrency: 10
  ramp-up: 1m
  hold-for: 10m
  scenario: create_user

scenarios:
  create_user:
    requests:
      - url: http://localhost:8080/user/create
        method: POST
        headers:
          Content-Type: application/json
          Accept: application/json
        body:
          json: '{
            "firstName": "Any",
            "lastName": "Any",
            "email": "${randomEmail()}",
            "msisdn": "${randomPhone()}",
            "birthdayAt": "3458694323421",
            "sex": "UNKNOWN"
          }'
          
reporting:
  - final-stats
  - console

I also have python functions that generate values.:

import random
import string

def random_email():
    username = ''.join(random.choices(string.ascii_lowercase, k=10))
    domain = ''.join(random.choices(string.ascii_lowercase, k=5))
    extension = random.choice(['com', 'net', 'org'])
    return f"{username}@{domain}.{extension}"

def random_phone():
    country_code = random.choice(['1', '44', '61'])
    phone_number = ''.join(random.choices(string.digits, k=10))
    return f"{country_code}{phone_number}"

However, I still can't figure out how to add them to yaml and is it possible

0

There are 0 answers