簡體   English   中英

空手道 API:將變量傳遞給其他功能文件不起作用

[英]Karate API : Passing variables to other feature file is not working

我正在從傳遞 url、用戶名和密碼的其他功能文件中調用登錄功能文件,但它對我不起作用。 我在這里沒有使用背景鍵,我也不想。

 @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

在 Login.feature 中,我也嘗試將用戶名和密碼作為表單數據傳遞,即使它們不起作用。 有人能告訴我我在這里犯了什么錯誤嗎?

我正在使用最新的空手道版本 0.9.0

我在你的腳本中看到了一些問題,

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)'

如果你從這里閱讀空手道文檔,我會更清楚你 - >空手道文檔並參考空手道演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM