空手道服务器功能文件无法访问karate-config.js文件中的变量 [英] Karate Server feature file cannot access variables in karate-config.js file

查看:99
本文介绍了空手道服务器功能文件无法访问karate-config.js文件中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事API测试项目,并已加入Karate.现在我的要求是创建一个将响应端点的服务器.所有这些都已完成,但我的要求是访问服务器功能中的karate-config文件中定义的变量.我无法这样做.

I am working on API testing project and have incorporated Karate to do so. Now my requirement is to create a server which will respond to the endpoint.All this is done but my requirement is to access variables defined in karate-config file in Server feature. I am unable to do so.

例如: 功能:示例服务器

For example: Feature: Sample server

场景:pathMatches('\ variablevalue)** methodIs('get')

Scenario: pathMatches('\variablevalue) ** methodIs('get')

  • def响应= default_env

注意:default_env是karate-config.js文件中的一个变量,并保留一些默认值.

Note: default_env is a variable in karate-config.js file and holds some default value.

推荐答案

很好的问题,我们特意不想将karate-config.js概念与空手道服务器端混合使用.

Great question, we deliberately did not want to mix the karate-config.js concept with the Karate server-side.

通常,当您通过API实例化模拟服务器时,您可以传递Java Map,并且所有键值都将最终成为空手道变量.

Normally when you instantiate a mock server via the API you can pass a Java Map and all key-values will end up as Karate variables.

但这是一个技巧,您可以在Background

But here's a trick, you can do this in the Background

* call read('classpath:karate-config.js')

这将具有与您正在寻找的效果完全相同的效果!请让我知道这是否可行,我将确保在文档中对此进行了更新.

And this will have the exact same effect you are looking for ! Do let me know if this works, I will make sure this is updated in the documentation.

请注意,如果您只需要一些种子数据,则可以使用JSON:

Note that you can use JSON if all you need is some seed-data:

* def cats = read('cats.json')

这篇关于空手道服务器功能文件无法访问karate-config.js文件中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆