首页 > 解决方案 > Karate Server feature file cannot access variables in karate-config.js file

问题描述

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

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

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

标签: karate

解决方案


很好的问题,我们故意不想将这个karate-config.js概念与空手道服务器端混为一谈。

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

但这里有个技巧,你可以在Background

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

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

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

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

推荐阅读