KARATE - How to get data from response/by running another feature file

时间:2018-10-17 12:52:47

标签: karate

I have a feature file that connects to oracle database and gets data and prints in response. Below's the sample piece of code.

dbconnect.feature

def queryDATA = 'QueryData' 
When def db = DBConnect.queryDB(host, port, serviceName, username, password, queryDATA)
Then print db

***Note that I have a few more lines of code before this which sets up jdbc and connects to DB with proper credentials

Post this, I need to run real test case which inturn should call dbconnect.feature to get DATA and feed to request. It goes like this;

UserDetails.feature

Background: 
* url 'https://soaheader-env-name.com'
* header agent_uid = 'AUTO_TST'
* configure ssl = true
* header Authorization = call read('classpath:ABC/JSFiles/auth.js') { 
username: 'XYZ', password: '123' }
* configure logPrettyResponse = true
* configure logPrettyRequest = true

@UserDetails
Scenario Outline: Get User Details
Given path 'somefooterurl/account/<accountno>/user-details-summary'
When method get
Then status 200
Then match response contains 'OK'

I really need to use the data from dbconnect.feature and provide in UserDetails.feature request.

Please suggest a way/ help me with the proper path in karate-github.

1 个答案:

答案 0 :(得分:2)

一个简单的例子,

* def dbCall = call read('dbconnect.feature')
* def db = dbCall.db

请参阅karate documentation

其他参考,如果您想将值传递给功能部件

Properly calling an authorization Karate feature with arguments

karate - How to set specific values in a feature file which is called internally