如何从CMDB系统检索初始配置并将其传递给KarateConfig
我有个情况。我需要向CMDB系统发送get请求,并将端点URI、路径、DB连接字符串等初始配置作为JSON对象检索。CMDB系统将发回一个JSON对象。如何在karate-config.js中实现这一点。我应该写一个自定义的javascript函数吗?或者我有任何内置的功能吗?我检查了空手道物体部分,但是,我不明白怎么做 我为此编写了一些自定义js函数。它们在我的系统中独立工作(我的机器上安装了node.js),但不会在karate-config.js中工作 第一个如何从CMDB系统检索初始配置并将其传递给KarateConfig,karate,Karate,我有个情况。我需要向CMDB系统发送get请求,并将端点URI、路径、DB连接字符串等初始配置作为JSON对象检索。CMDB系统将发回一个JSON对象。如何在karate-config.js中实现这一点。我应该写一个自定义的javascript函数吗?或者我有任何内置的功能吗?我检查了空手道物体部分,但是,我不明白怎么做 我为此编写了一些自定义js函数。它们在我的系统中独立工作(我的机器上安装了node.js),但不会在karate-config.js中工作 第一个 var HttpClient
var HttpClient = function () {
this.get = function (aUrl, aCallback) {
var XMLHttpRequest = require('xhr2');
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.onreadystatechange = function () {
if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200)
aCallback(anHttpRequest.responseText);
}
anHttpRequest.open("GET", aUrl, true);
anHttpRequest.send(null);
}
}
var url = 'https://reqres.in/api/users/2';
var client = new HttpClient();
client.get(url, function (response) {
var response1 = JSON.parse(response);
console.log(response1)
});
秒
var axios = require('axios');
// Make a request for a user with a given ID
axios.get('https://reqres.in/api/users/2').then(function (response) {
console.log(response)
}).catch(function (error) {
console.log(error);
});
我想你忘记了空手道恰好非常擅长发出HTTP请求:) 您只需编写一个可重用的空手道功能文件,使
GET
tohttps://reqres.in/api/users/2
。您可能需要找出所需的任何标题
有一个karate.callSingle()
方法,现在可以在karate config.js
中使用,以完全满足您的需要。请看第31行: