Reputation: 255
The need is to assert roles and fail the test script for few roles if the buttons are not disabled for them. For which I tried performing steps similar to the following:
* assert (role=="DM"||role=="RM"||role=="AVP")
* eval if((role=="DM"||role=="AVP")? read('classpath:extraFeature.feature@checkIfDisabled') : print "options disabled... proceeding further!"
Here I am calling a scenario with tag @checkIfDisabled for the functionality which contains :
* if(exists(#listButton)) karate.fail("Options are enabled... Cannot proceed further! ")
I feel calling a different feature file for this little thing is not worth it. Moreover that as well is not working as expected. Nested if would've been a solution to this. If not or I am wrong with the approach please help me with something that can add to the logic.
I also tried storing the above called scenario code into a variable and call it.
* def fun = if(exists(#listButton)) karate.fail("Options are enabled... Cannot proceed further! ")
* call fun
But the error statement was something like, "this variable is not callable." Which I understand is something wrong from my side. But some hit and trials I did in search of an alternative to nested if. Any suggestions or way to deal this?
Thanks!
Upvotes: 2
Views: 1227
Reputation: 58058
You can use eval
and then delegate to pure JS like this:
* eval
"""
if (exists('#listButton')) karate.fail('blah')
else if (someCondition) {
// do something
}
"""
And even a JS switch case
can be used if you want !
If this doesn't help, I'll leave you with this answer and no other suggestions: https://stackoverflow.com/a/50350442/143475
Let me know what works though !
Upvotes: 1