Completely new to Postman and I don’t come from an automation background…
but an incremental key-value pair is really kicking my butt! I have some syntax for a loop, but I’ve included a value that shouldn’t be there and removed one that should be there.
This is my response body for my post
{
"firstName": "",
"lastName": "",
"panelCode": "",
"userName": "",
"password": null,
"token": "",
"errorMessage": "Your Username/Password/Panel Code is incorrect. You have 4 more attempt(s) left.",
"locked": false,
"badLoginAttempts": 2
}
The check I’m trying to get right is for badLoginAttempts and this is the test that is being returned as passed every time:
It’s probably a horrible mess, but I’ve tried many different variations for the variable and I always get a pass. I’m expecting a fail if the value of the increment is/isn’t present for badLoginAttempts OR if the number of badLoginAttempts surpasses the max value ie. 5.
I have tried adding and removing quotes to var badLoginAttempts = [0, 1, 2, 4, 5];
The jsonData variable seems like it’s not needed here, that might be for another part of the script though. The different parts of the for loop don’t seem to be the correct syntax either.
What the end goal? What do you expect each of those values to be if you were to hardcode them? Are you expecting that test to log in 5 times?
My apologies, I was rushed yesterday afternoon and couldn’t give all the detail.
The login creds are AD-related and there are 6 bad login attempts before the AD account is locked out. This is indicated with the value of badLoginAttempts incrementing a total of 5 times.
I’m trying to check that value is incrementing by 1 for each bad login attempt.
The jsonData variable belongs to another test in the script, but I didn’t know whether it was important to stipulate that here.
I guess my expectation is that each time the test runs, it will check a value in here var badLoginAttempts = [0, 1, 2, 4, 5];. If the value is not present, the test would fail.
My first sentiment was to just list 1,2,3,4,5 and then the expectation was for the test to fail on the 6th attempt because 5 is the highest value, but that did not happen.
Should I even be trying to use a loop for this kind of check, or is there another way to validate values incrementing?
As it is that’s just going run a single request - there’s nothing in the Tests tab that would force it to send multiple requests.
You could send that main request and in the test script, create another request using pm.sendRequest() that would loop through another 4 times and assert against the response returned from the server each time or at the end.
If this is the response, it looks like the errorMessage is going to change for each request sent and the badLoginAttempts is something that could be checked on each request too.
{
"firstName": "",
"lastName": "",
"panelCode": "",
"userName": "",
"password": null,
"token": "",
"errorMessage": "Your Username/Password/Panel Code is incorrect. You have 4 more attempt(s) left.",
"locked": false,
"badLoginAttempts": 2
}