4

I would like to get a common variable for all features. Ex: base URL and path (in some features). I don't understand well in Karate official tutos what to do exactly. I put in user.feature

`Background:
* url urlBase
* path users

In karate-config.js

function() {
  var env = karate.env;
  karate.log('karate.env system property was:', env);
  if (!env) {
    env = 'dev';
  }
  var config = {
    env: env,
    appId: 'my.app.id',
    appSecret: 'my.secret',
    baseURL: 'https://someurl/',
    users: 'users'
  };
  karate.configure('connectTimeout', 5000);
  karate.configure('readTimeout', 5000);
  return config;
}

and in my runner class:

@RunWith(Karate.class)
@CucumberOptions(features = "classpath:features/users/User.feature")
public class TestRunner{
    }
}

User.feature and karate-config.js are in the same folder and Runner class is in another. Is it right? or I need more things to specify?

cygne
  • 527
  • 1
  • 10
  • 28

1 Answers1

3

No this is not right. I suggest you refer to the quickstart documentation of Karate where you can generate a simple project. Get that running first, and then try to set the URL from the karate-config.js. All the best.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • thanks, Peter Thomas, for your quick reply. I couldn't find any issue. I tried many things, but may be not the right one. Can you give us some tips, especially for the feature side, please. PS: marked the first answer as "accepted" – cygne Sep 19 '17 at 14:22
  • try this: read the documentation. also create a quickstart. here is a useful tutorial: https://blog.testproject.io/2017/08/21/api-testing-karate-framework/ – Peter Thomas Sep 19 '17 at 14:27
  • I found an issue here: https://semaphoreci.com/community/tutorials/testing-a-java-spring-boot-rest-api-with-karate. But it works for one parameter (ex: baseUrl). How to do for many parameters? – cygne Sep 19 '17 at 15:38
  • 1
    add more keys to the JSON returned by karate-config.js - it is that easy. if you still have trouble, get someone who knows basic JavaScript to look at your karate-config.js - that will solve your problem. all the very best :P – Peter Thomas Sep 19 '17 at 16:22
  • I'm using this tutorial, https://github.com/intuit/karate#configuration, to get environment dynamically from the command line but I keep getting an error stating that my url is not defined but when I use only one as mentioned above it works. @nirind were you able to get env dynamically (dev, staging, prod, etc). Thanks – ihossain Jan 05 '19 at 00:01