karate-config.js中可以有两个baseUrls吗?

时间:2019-01-18 12:17:57

标签: karate

我有一个场景,我将与其他产品进行集成测试。因此,我有两个URL,每个URL具有单独的授权令牌。在karate-config.js中可以有两个baseUrls,如果是,我们如何在功能文件中访问它们?

double permanent(double input_matrix[n][n], int sign_matrix[][n]){

int rows =  pow (2, n) ;
int partial_result = 0;
int result = 1;

for(int r = 0; r < n; r++)
{
   for(int c = 0; c < n; c++)
   {
      partial = partial + input_matrix[c][r] * sign_matrix[r][c];
      //cout << parziale <<  endl;
   }

   cout << partial << endl;
   partial_result = partial_result * parziale;
   partial = 0;

}

2 个答案:

答案 0 :(得分:3)

您可以在 像下面的karate-config.js文件

function() {
  var env = karate.env; // get java system property 'karate.env'
  karate.log('karate.env system property was:', env);
  if (!env) {
    env = 'local'; // a custom 'intelligent' default
  }
  var config = { // base config
    env: env,
    profile: 'local',
    DataSetUrl: 'http://localhost:9005/v0.2.4/',
    DMUrl: 'http://localhost:8004/v0.2.3/',
    SchemaUrl: 'http://localhost:8006/v0.2.3/',
    URUrl: 'http://localhost:9005/v0.2.4/',
    username: 'null', 
    password: 'null'
  };
  if (env == 'staging') {
    // over-ride only those that need to be
    var config = { // base config
            env: env,
            profile: 'staging',
            baseUrl: 'staging url',
            dbname: 'url2',
            server_url: '12.12.12.12',
            server_port: 31700,
            username: 'mongo-staging-user', 
            dbname: 'db_name',
            password: 'passoword'
          };    
  } 
  }
  // don't waste time waiting for a connection or if servers don't respond
    // within 5 seconds
  karate.configure('connectTimeout', 5000);
  karate.configure('readTimeout', 5000);
  return config;
}

对于授权,您可以创建一个看起来像这样的config.feature文件,

Feature: Auth

  Scenario: Auth
    * def Auth = 'auth'

在功能文件中,您可以使用网址和授权

Feature: Test 

Background: 
    * def config = call read('classpath:features/Config.feature')
    * def auth = config.Auth

Scenario:1

* url DMUrl
Given path 'yourpath'
When method get
Then status 200
#
* url DataSetUrl
Given path 'yourpath'
When method get
Then status 200

答案 1 :(得分:2)

最好的方法之一是在您的应用名称前加上前缀

if (env == 'pre-prod') {
    config.AppOne = {
        baseUrl: 'url1',
        getHeader: function() {
            return {
                Authorization: 'App one token'
            };
        }
    };
    config.AppTwo = {
        baseUrl: 'url2',
        getHeader: function() {
            return {
                Authorization: 'App two token'
            };
        };
    }
}

在功能使用中使用

* url AppOne.baseUrl
* path 'apiOne/endpoint'
* headers AppOne.getHeader()
# <other steps for App One>
* url AppTwo.baseUrl
* path 'apiTwo/endpoint'
* headers AppOne.getHeader()
# <other steps for App Two>

这样,您可以一次为一个以上的应用程序进行全局配置。

相关问题