-
Notifications
You must be signed in to change notification settings - Fork 23
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
Cannot set the @disabled flag dynamically #292
Comments
Unfortunately, I commited a broken example, probably during manual testing. The classic error, nobody can double negate. I just stumbled across it myself and only noticed it when debugging. Disabled=true means that the request should be executed. a working example is this code. The request does not get executed
|
callRequest=true you want to call Request. Set callRequest to false. this does not execute the request for me
|
Ah, I see. The Send button is not really a problem. The problem is that once you execute all tests in a folder, the results for the ones marked with the So, there is no way to easily see which tests completed and which ones skipped by looking at the Test Results tab or Testing tree view. |
And ignoring the UI issue for now, how do you make the Here is my script, but if I run all tests, the returned request info shows that both test 3 and 4 are skipped. Shouldn't test 3 or 4 (at least, one of them) run? Or am I not passing the exported variable to the @validTitle1=Overview
@validTitle2=Wake up to WonderWidgets!
@invalidTitle=XYZ
###
### Test 0 (initial test which is a dependency for test 1, 2, 3, 4)
# @name results
GET https://httpbin.org/json
### Test 1 (ok)
# @ref results
{{
var item = results.slideshow.slides.find(item => item.title == validTitle1)?.title;
exports.item = item
}}
GET https://httpbin.org/anything/{{item}}
### Test 2 (error 'invalidItem is not defined' as expected)
# @ref results
{{
var item = results.slideshow.slides.find(item => item.title == invalidTitle)?.title;
exports.item = item
}}
GET https://httpbin.org/anything/{{item}}
### Test 3 (must be enabled since item is a valid string)
# @ref results
{{
var item = results.slideshow.slides.find(item => item.title == validTitle2)?.title;
exports.item = item
}}
# @disabled !item
GET https://httpbin.org/anything/{{item}}
### Test 4 (must be disabled since item is undefined or null)
# @ref results
{{
var item = results.slideshow.slides.find(item => item.title == invalidTitle)?.title;
exports.item = item
}}
# @disabled !item
GET https://httpbin.org/anything/{{item}} Responses (with unnecessary blank lines removed):
So, there are no logs for requests from either test 3 or 4. And once I picked the
I must not be doing it right. What I am trying to do here is to make sure that subsequent requests only execute based on some condition from a dependency (e.g. if a POST to create an item fails, then subsequent requests for GET, PATCH, and DELETE should be disabled), and I cannot figure out if I am passing the criteria retrieved from the dependency correctly to the |
This is due to how up-to-date the disabled detection is implemented. I currently check the condition before starting the region and after each individual step of the execution. But you expect it to be checked only at the point where you write the disabled. I think I adapt the behavior to your expected behavior, as this seems more intuitive. |
Thanks @AnWeber. I did not quite get your point about the disabled detection implementation. The two links in your response (starting with before... and after...) result in 404 Page Not Found, so I'm not sure if there is any useful info there. And if they intended to point to code, I'm not sure they would be meaningful (it's hard to read someone else's code from a domain you are not familiar with). I did not see any description of the $cancel variable (and maybe I missed it), but I think I figured it out. I rewrote the tests using @validTitle1=Overview
@validTitle2=Wake up to WonderWidgets!
@invalidTitle=XYZ
###
### Test A (initial test which is a dependency for other tests)
# @name test_a_results
GET https://httpbin.org/json
### Test B (must be enabled since item is a valid string)
# @ref test_a_results
{{
var item = test_a_results.slideshow.slides.find(item => item.title == validTitle1)?.title;
if (item == undefined || item == null) {
exports.$cancel = true;
} else {
exports.item = item;
}
}}
GET https://httpbin.org/anything/{{item}}
### Test C (must be disabled since item is undefined or null)
# @ref test_a_results
{{
var item = test_a_results.slideshow.slides.find(item => item.title == invalidTitle)?.title;
if (item == undefined || item == null) {
exports.$cancel = true;
} else {
exports.item = item;
}
}}
GET https://httpbin.org/anything/{{item}}
### Test D (must be enabled since item is a valid string)
# @ref test_a_results
{{
var item = test_a_results.slideshow.slides.find(item => item.title == validTitle2)?.title;
if (item == undefined || item == null) {
exports.$cancel = true;
} else {
exports.item = item;
}
}}
GET https://httpbin.org/anything/{{item}} And request output looks right (test C gets skipped):
The only problem is that to see which tests ran and which ones get skipped, I need to read the request log because in both the test tree results and test results panel, all tests look like they completed (including the one that was skipped): Also, while running all test in the folder via the testing tree is fine, if I try to run them via the To summarize, while it would be nice to get the |
I deleted my two previous comments. It was my fault (forgot |
The two links still worked before my commit, but then I deleted the file 🤦I am happy to add links. At the end of the day it's just code and yes the lack of context may be the problem. But that's where the fun begins in my eyes. Raise others to the same level of understanding and use the feedback to improve yourself The indicators will also work for |
How do you disable a request only if a previously executed request's response matches certain conditions?
For example, say you need to test a CRUD sequence, so you first execute a POST request to create an object, but if the response status is not '201 Created', then the subsequent GET, UPDATE, and DELETE requests would be disabled. Or, say, you run a GET request and based on the returned JSON object (or collection), you may or may not disable another GET request (e.g. I call a GET method to obtain a list of roles and if among the returned role objects I find a role with the
owner
property that is not null, I would call a GET by owner request, passing the owner ID, but if none of the items have a non-nullowner
property, then the GET by owner request would be disabled).I know how to get and pass values from one request to the other, it's just I cannot figure out how to use them to dynamically turn the
@disabled
flag on and off. I tried all kinds of things: setting a value in pre-request script, post-request script of the dependent request, using$global
,export
,@variable
. No matter what variable I passed to the@disabled
meta flag, the request was always disabled.So, I backed all the way to basics and tried to use the example from https://httpyac.github.io/guide/metaData.html#disabled to make the request enabled:
It didn't work:
Then I just hard coded
false
in the metadata, and it also did not work:Only if I remove the
@disabled
meta flag, the request would get executed:Am I missing something basic?
The text was updated successfully, but these errors were encountered: