Skip to content

Cannot use both tag selector and cache key with karate.callSingle #2670

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

Open
nboisnea opened this issue Mar 14, 2025 · 2 comments
Open

Cannot use both tag selector and cache key with karate.callSingle #2670

nboisnea opened this issue Mar 14, 2025 · 2 comments

Comments

@nboisnea
Copy link

nboisnea commented Mar 14, 2025

I use karate-config.js for retrieving access tokens for testing an API. I have an authentication.feature file with two scenarios, one for getting a token with a username and password, one for getting a token with a client ID and secret. I used tags @password and @client on each scenario respectively. Now, I also need to obtain tokens for several users and clients so I would need to use cache keys as explained here, so authentication.feature would be called once per user/client.

It seems I can't get the tag selector and the cache key to work together. I could not find in which order they are supposed to be used, if it's even possible. Here's what I tried:

karate.callSingle('classpath:authentication.feature@password?' + username, {...}): always returns an empty object.

karate.callSingle('classpath:authentication.feature?' + username + '@password', {...}): runs both scenarios when I wanted only the password scenario.

For reference, here is the normal behavior when using only one, although it doesn't fit with my use case:
karate.callSingle('classpath:authentication.feature@password', {...}): runs only the password scenario but only for the first user, then the same token is returned because of the cache.

karate.callSingle('classpath:authentication.feature?' + username, {...}): runs both scenarios for every user/client.

Thanks for any help!

@ptrthomas
Copy link
Member

this is a case where we would insist on a small project to replicate, will tag as help wanted for now: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

ThierryLejeune added a commit to ThierryLejeune/karate that referenced this issue Mar 20, 2025
@nboisnea
Copy link
Author

nboisnea commented Apr 3, 2025

Thank you @ThierryLejeune for working on this issue. Hopefully my original message explained the problem clearly enough.

@ptrthomas If still needed I found the time to generate a quick project replicating the issue here: https://solid-space-memory-54r96gvvw9v2px94.github.dev/. The 4 scenarios I described can be found in karate-config.js.

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

No branches or pull requests

2 participants