0

testing website is taking OTP for registering a new user while recording the test script it registers and creates the new user but while running the same test in JMeter, it gives response code:400, and the user already exists. I have record 4 test script on the website with different fields every time but the /register shows error every time. but on the server, there is no error. SO something is missing in a JMeter/register response test. Please guide. I have added the header manager before this post request with application/JSON as a content-type but does not resolve the issue. My test plan:/register

2 Answers 2

1

Most probably your system simply doesn't allow multiple registrations using the same credentials set, looking into your request body "suspicious" parameters are:

  • email
  • phone
  • licenseId

Well-behaved load test should represent real life application usage as close as possible, it means that each JMeter thread (virtual user) must represent a real user. Two different real users cannot have same emails and phones so you need to parameterize at least these 2 options.

You can generate a random email address using __RandomString() function like:

${__RandomString(10,abcdefjhijklmnopqrstuvwxyz,)}@${__RandomString(5,abcdefjhijklmnopqrstuvwxyz,)}.${__RandomString(3,abcdefjhijklmnopqrstuvwxyz,)}

and similarly the phone number using __Random() function like:

${__Random(111111111,999999999,)}

Demo:

enter image description here

Check out Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept

1
  • With {__random String () } function it gives response 450: method not allowed.
    – coder_m
    Commented Dec 4, 2019 at 10:04
0

This is not a Jmeter issue. As the error message implies "User already exist!". It's because you already registered the user and just re-running the recorded scripts. Basically, they have the same details.

You need to modify the payload/request body when you run it again. Ask your developer on which values should be unique. Here's sample code on how to create random String using Beanshell PreProcessor

On your body data, something like: { "org_name": "${data-org_name}", "full_name": "${data-full_name}" }

and in Beanshell precproccessor:

import java.util.ArrayList; import java.util.List; import java.util.Random;

int leftLimit = 97; // letter 'a'
int rightLimit = 122; // letter 'z'
int targetStringLength = 20;
Random random = new Random();
StringBuilder buffer = new StringBuilder(targetStringLength);
for (int i = 0; i < targetStringLength; i++) {
   int randomLimitedInt = leftLimit + (int) 
     (random.nextFloat() * (rightLimit - leftLimit + 1));
   buffer.append((char) randomLimitedInt);
}
String generatedString = buffer.toString();

vars.put("data-org_name", generatedString);

targetStringLength = 20;
StringBuilder buffer = new StringBuilder(targetStringLength);
for (int i = 0; i < targetStringLength; i++) {
   int randomLimitedInt = leftLimit + (int) 
     (random.nextFloat() * (rightLimit - leftLimit + 1));
   buffer.append((char) randomLimitedInt);
}
generatedString = buffer.toString();

vars.put("data-full_name", generatedString);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.