Now many APPs or websites need to use the mobile phone number to log in, so when using the mobile phone number to log in, you must need "mobile phone number + SMS verification code" to log in successfully.
In the actual test process, testers generally only have one mobile phone number, so they need to test multiple mobile phone numbers to obtain the "SMS verification code" required for login through the SMS interface service, so how to solve the problem of multiple mobile phone numbers?
Collect personal mobile phone numbers of other colleagues in the company
Use Jmeter to provide a random function to generate the middle four digits of a mobile phone number
This article focuses on the interface function of obtaining the SMS verification code, so there is no need to check the format of each number segment of the mobile phone number, so choose the second "using Jmeter random number + fixed number" above. If you need a more realistic simulation (such as verifying whether the mobile phone number is legal, etc.), you can use other methods to generate 11-digit mobile phone numbers, such as generating legal mobile phone numbers through regular expressions.
01Interface
Analysis
Before starting an interface test or interface stress test task, you need to obtain the following relevant information from the interface documentation provided by the development:
Domain name (IP)
address (path)
Request method (post/get)
Input: mobile phone number and other information
…
This article focuses on "how to use the random number generated by Jmeter's random function" to combine different mobile phone numbers, so that the verification code required for login can be obtained through the "Get SMS Verification Code" interface.
02Using
Jmeter to generate four-digit random numbers
Using Jmeter's random function _Random, a four-digit random number can be generated:
-
Select the random function that comes with Jmeter
-
Defines the minimum value of a four-digit random number
-
Define the maximum value of a four-digit random number
-
Finally generate a random function expression: ${__Random(0000,9999,)}
03
Splicing mobile phone numbers
Use random functions and fixed numbers to form a mobile phone number. The domestic mobile phone number is 11 digits:
The first three digits: 152 (the fixed number segment of the mobile phone number in this example)
Middle four: use the random function expression "${__Random(0000,9999,)}"
The last four digits: 5208 (the mobile phone number in this example has a fixed tail number)
Splicing result: 152XXXX5208, where "XXXX" in the middle represents a four-digit random number.
To sum up, the mobile phone number "mobile" of the SMS interface input parameter:
“152${__Random(0000,9999,)}5208”
04
Simulate SMS interface request
menu path:
Right-click on the Thread Group - sample-HTTP Request
JMeter adds the domain name, path, request method, input parameters, etc. requested by the HTTP Request configuration interface, as shown in the following figure:
05Add
listening tree
menu path:
Right click on Thread Group - lisener - View Results Tree
The listening tree report configuration remains the default configuration (all request logs are displayed by default). If you need to simulate 1000 or more, you can choose to display only the error logs:
06
Set the number of script runs
If you need to simulate 1000 users concurrently, you can set it as follows:
Number of threads(users):1000
Ramp-up period(in seconds):0
Loop Count:1
The above configuration means that 1000 users initiate the acquisition of the verification code at the same time, and each user executes it once.
If you need to send SMS verification codes to 1000 users at intervals of 1s, you need to set Loop Count=1000 on the thread group
07Running
results
Since Loop Count=1000 is set on the thread group, the script runs 1000 times, and each time the random function generates a random four-digit number and a fixed number spliced into a different mobile phone number.
The result of running the script is as follows:
Click on each request to see that the mobile phone numbers entered are different
The process of logging in by phone number:
Use mobile phone number to get verification code
Use mobile phone number + verification code to log in
This article implements the first stage of the login process. If you need to log in at the same time, you can add a login interface request after obtaining the verification code.
Tips:
During the test, the test environment generally needs to add SMS whitelist before users can actually receive the SMS verification code, so there is no need to worry that the verification code will be actually sent to the mobile phone of the mobile phone number owner, and there will be no SMS deduction.