How to get a value (ex: baseURL) in every Karate feature?

自作多情 提交于 2019-12-20 02:56:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/46299245/how-to-get-a-value-ex-baseurl-in-every-karate-feature

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!