7

I'd like to incorporate GitLab CI into my Karate testing. I'd like to loop through my tests with different user names and passwords to ensure our API endpoints are responding correctly to different users.

With that in mind, I'd like to be able to store the usernames and passwords as secure environment variables in GitLab (rather than in the karate-config as plain text) and have Karate pull them as needed from either the karate-config or the feature files.

Looking through the docs and StackOverflow questions, I haven't seen an example where it's being done.

Updating with new information

In regards to Peter's comment below, which is what I need I am trying to set it up as follows:

set client id in karate-config:
var client_id = java.lang.System.getenv('client_id');

in the actual config object:
clientId: client_id

In my feature file tried to access it:
* def client_id = clientId

It still comes through as null, unfortunately.

1 Answer 1

9

You can read environment variables in karate using karate.properties,

eg,

karate.properties['java.home']

If this helps you to read the environment variables that you are keeping securely on your gitlab, then you can use it in your karate-config for authentication.

But your config and environment variable will look cumbersome if you are having too many users.

If you want to run a few features with multiple users, I would suggest you look into this post,

Can we loop feature files and execute using multiple login users in karate

EDIT:

Using java interop as suggested by peter:

var systemPath = java.lang.System.getenv('PATH');

to see which are all variables are actually exposed try,

var evars= java.lang.System.getenv();
karate.log(evars);

and see the list of all environment variables.

Sign up to request clarification or add additional context in comments.

6 Comments

Babu: I think this is what the OP is looking for: github.com/intuit/karate/issues/547#issuecomment-427017681
@PeterThomas That is exactly what I'm looking for. I've updated my question with what I'm trying and not succeeding with.
@drew2 ok. I've tried it and it works, try the slightly more explicit way of using command-line arguments as per the answer. else please use this process: github.com/intuit/karate/wiki/How-to-Submit-an-Issue
@drew2 -Dsome.name=foo on the command line, and karate.properties['some.name'] to get the value in the karate-config.js
Peter: How did I forget interop :P, yeah passing from the command line would be the best option.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.