首页 > 解决方案 > Karate API : Passing variables to other feature file is not working

问题描述

I am calling login feature file from other feature file from where I am passing url, username and password but it is not working for me. I am not using Background key here and i do not want also.

 @CallAnotherFeature
 Feature: Call Login Feature

 Scenario: Calling Login Test
 * def config = { endPointURL: 'https://qa1.testurl.com/login',username: 'user123', password: 'password123' }
* def result= call read('Login.feature') config
* print result.response
* print 'Sign In-'+signIn
* print 'Sign In Reponse-'+signIn.response


Feature:  Login Feature

Scenario: Test Login for different users

* print 'Starting Test','#(endPointURL)'
Given url '#(endPointURL)'
* print 'user name','#(username)'
* print 'Password ','#(password)'
#And form field username = '#(username)'
#And form field password = '#(password)'
And request { username: '#(username)', password: '#(password)'}
When method post
Then status 200
* print response
* match response.loginSuccess == true

In Login.feature I tried to pass username and password as form data also even though these did not work. Could someone tell me what mistake I am making here.

I am using latest karate version 0.9.0

标签: karate

解决方案


我在您的脚本中看到了一些问题,

1. 来电登录功能

1.1)我在此功能的任何地方都没有看到signIn变量初始化,也没有从您那里看到变量,login feature但您正在尝试打印它。

1.2)=应正确放置;)

* def result = call read('Login.feature') config

2.登录功能

2.1)我认为您误解了嵌入式表达式的概念。仅用于将其模板化为 JSON,您可以使用它。但是要调用它,您可以简单地使用变量名。

例如。

Given url endPointURL
And form field username = username
And request { username: '#(username)', password: '#(password)'}

不是

Given url '#(endPointURL)'
And form field username = '#(username)'

如果您从此处阅读空手道文档 -> karate Doc并参考karate Demos,我会更清楚


推荐阅读