Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do if-then-else during testing #1862

Open
xu4wang opened this issue Aug 24, 2023 · 5 comments
Open

How to do if-then-else during testing #1862

xu4wang opened this issue Aug 24, 2023 · 5 comments

Comments

@xu4wang
Copy link

xu4wang commented Aug 24, 2023

Hi Greetings,

I'm testing some APIs. sometimes, I need to call an API based on the response of the previous API. For example, in below hurl file, if the user with user_email is not available, I want to skip the DELETE entry.

GET {{host}}/users
Authorization: Bearer {{access_token_admin}}
[QueryStringParams]
filter[email][_eq]:{{user_email}}

HTTP 200
[Captures]
user_uuid:  jsonpath "$.data[0].id" 

DELETE {{host}}/users/{{user_uuid}}
Authorization: Bearer {{access_token_admin}}

For now, if I run above hurl file, it complains

austin@dev testing % hurl --variables-file dev.env ./tests/1.user.hurl
error: No query result
   --> ./tests/1.user.hurl:54:13
    |
 54 | user_uuid:  jsonpath "$.data[0].id" 
    |             ^^^^^^^^^^^^^^^^^^^^^^^ The query didn't return any result
    |

I am not sure if I can do this in hurl, or is there a good practice doing this?

BR,Austin

@fabricereix
Copy link
Collaborator

Supporting a skip option could work (#1815)

DELETE {{host}}/users/{{user_uuid}}
Authorization: Bearer {{access_token_admin}}
[Options]
skip: user_uuid not exists

@mjhcorporate
Copy link

mjhcorporate commented Sep 20, 2023

In the Postman world, this is solved with something that boils down to GOTO <requestName>. The semantics aren't a great fit to hurl (which does not have request names), and programming with GOTOs is messy, but it allows if/else, do/while, and (by using dynamic variables decremented with test-javascript) for-loops.
A skip would be less powerful -- but also less confusing!

@chrisguest75
Copy link

chrisguest75 commented Oct 11, 2023

This is the current challenge with hurl for me. I love the simplified DSL approach to scripting tests. But we're missing features to enable certain types of testing. Simple conditional logic or branching, full persisted captures for analysis & interrogation and hooks for cleanup.

Maybe people have a few tricks to achieve the above. I'd be interested to hear if they do

@jcamiel
Copy link
Collaborator

jcamiel commented Nov 6, 2023

--skip option has been implemented in #1815 that enable request skipping:

GET https://bar.com
[Options]
skip: true
HTTP 200

GET https://baz.com
HTTP 200

@tbmreza
Copy link

tbmreza commented Nov 6, 2024

Will hurl ever see syntax for if-else, or even for-loops? The template language stands too much in the way for expressiveness...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants