3

I am using the following syntax in karate feature file and it works but I want to add this globally in karate config file so that I don't have to add in all of my feature file individually

* configure proxy = { uri: 'http://xx.xx.xxx.xx:8080', username: 'myuserid', password: 'xxxxxx' }

I need to know how we can add above globally in karate-config.js file

Thanks

Peter
  • 4,752
  • 2
  • 20
  • 32

1 Answers1

5

The karate documentation is quite comprehensive.

If you have any questions, it's pretty likely to find the answer there or in a related demo .feature file.

From the documentation:

And if you need to set some of these 'globally' you can easily do so using the karate object in karate-config.js - for e.g. karate.configure('ssl', true).

So, I would try to put the following snippet in karate-config.js:

function() {
    var config = {
        BASE_URL:  'base url one,
        BASE_URL2: 'base url two'
    };
    karate.configure('proxy',  { uri: 'http://xx.xx.xxx.xx:8080', username: 'myuserid', password: 'xxxxxx' });
    return config;
}

Needless to say, that you can use karate.env property to configure your proxy on the base of your environment.

Peter
  • 4,752
  • 2
  • 20
  • 32
  • Thanks Peter for your reply. Yes I tried that karate.configure but it didnt work for me so I thought there may be some other way to resolve. – Aziz Mubarak Dec 03 '19 at 19:33
  • Are you sure that your `karate-config.js` gets picked up? – Peter Dec 03 '19 at 19:56
  • Yes as I have BASE URL is defined and it work when i use my feature file – Aziz Mubarak Dec 03 '19 at 20:25
  • Here is my config file please let me know if anything wrong, as BASE_URL is working fine function() { var config = { BASE_URL : 'https://myfirstURL', BASE2_URL : 'https://mysecondURL', karate.configure('proxy', { uri: 'http://xx.xx.xxx.xx:8080', username: 'myuserid', password: 'xxxxxx' }); }; return config; – Aziz Mubarak Dec 03 '19 at 20:40
  • Looks like you put the `karate.configure` at the wrong place - updated my answer. – Peter Dec 03 '19 at 20:50
  • 3
    It works.. Yayyyy Thank you peter for your help and quick response. Thanks – Aziz Mubarak Dec 03 '19 at 21:48
  • 2
    Great and it would be better if you accept my answer. – Peter Dec 04 '19 at 06:26