pyresttest
pyresttest copied to clipboard
Request: Loop a test
https://stackoverflow.com/questions/43811310/how-to-create-a-loop-in-pyresttest
I am trying to create a loop in PyRestTest, this is my code:
# Login
- test:
- group: 'Login'
- name: 'Test login post'
- url: {template: 'api/login/'}
- method: 'POST'
- body: {template:'{"username":"$username",
"email":"$username",
"password":"$password"}'}
- headers: {Content-Type: application/json}
- extract_binds:
- 'token': {'jsonpath_mini': "key"}
# Logout
- test:
- group: 'Logout'
- name: 'Test logout post'
- url: {template: 'api/logout/'}
- method: 'POST'
- headers: {Content-Type: application/json}
How can I execute this code over and over?. I am expecting something like:
loop(10):
# Login
...
# Logout
...
In order to execute 10 times these tests. Is it possible?
BTW, I don't want to use a benchmark because it does not throw if the test passed or failed
Hi @cniackz. Can i know the command to pass parameters from outside. i.e how did you passed username and password while executing the command? Thanks in advance, Ravi Teja
Hello @mravitej
In the top of the file I have these lines below:
- config:
- testset: 'Basic Tests'
- variable_binds: {'username': '[email protected]', 'password': 'admin',
'espuser_url': 'api/user/v0.1',
'authbkend_url': 'api/authentication/v0.1'}
Regards, -Cesar
@cniackz So did you do it? I will soon, but wanted to ask if you have any input of code.
I am willing to pay for development hours for developing a PT of "foreach: sequence" that will repeat a test for each element in the array.
It will need to get array from a json response in test1 and loop on test2 for element in that array. it will need to add the variable name and value to the test name
@nitzanav I think you may have hunted me down on LinkedIn a while back. While I don't have a ton of outside-of-work time (which is why side projects such as this have languished), I would consider doing some smaller features like this on a contract basis for the right amount. Drop me a message with a bit more details if you like.