在功能空手道Soap API的背景中声明全局变量 [英] Declare Global variables in background of feature-karate Soap API

查看:79
本文介绍了在功能空手道Soap API的背景中声明全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将空手道用于SOAP API服务.如何声明全局变量?正如您在下面的功能文件中看到的那样?打印响应后,我的变量名为def ourSession = /Envelope/Body/LoginReturn,我在下一种情况下正在使用此变量(ourSession),但失败了吗?但这不是全球性的. 那么我怎样才能将"ourSession"声明为全局变量?所以我可以用在其他场景中吗? 任何帮助将不胜感激.请在下面查看我的功能文件;

I am using karate for SOAP API services. How can I declare a global variable ?? as you can see in below feature file? after print response I have variable name def ourSession = /Envelope/Body/LoginReturn I am using this variable (ourSession) in next scenario but it's failing ? but it's not global. So how can I declare "ourSession" as a global variable ?? so I can use into other scenarios? Any help will be highly appreciated. Please have a look of my feature file below;

Feature: 
    SOAP calls to the following service:

Background:

     * url baseUrl
     * def configSS = Java.type('practice.utilities.Shellscripts')

##################################### LOG IN #########################################################
@DataAcquisition
 Scenario: login
     Given request
     """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsh="http://www.informatica.com/wsh">
   <soapenv:Header/>
   <soapenv:Body>
      <wsh:Login>
         <RepositoryDomainName>Domain_Aqr_Dev_Powercenter</RepositoryDomainName>
         <RepositoryName>Powercenter_Repository_Service</RepositoryName>
         <UserName>#(AM_USERNAME)</UserName>
         <Password>#(AM_PASSWORD)</Password>
         <UserNameSpace/>
      </wsh:Login>
   </soapenv:Body>
</soapenv:Envelope>

     """
     When soap action '/login'
     Then assert responseStatus == 200
     And print 'response: ', response
     * def ourSession = /Envelope/Body/LoginReturn
     * print ourSession

推荐答案

在下一种情况下,我正在使用此变量(ourSession)

i am using this variable (ourSession) in next scenario

不能.堆栈溢出中有很多答案可以解决此问题,请找到并阅读.

You can't. There are many answers in Stack Overflow addressing this question, please find them and read them.

并且请阅读文档: https://github.com/intuit/karate#script -结构

引用:

如果您希望后台中的一个变量被一个方案修改,以便以后的人可以看到更新的值-那不是您应该如何看待的,您应该将流"组合到一个方案中.

if you are expecting a variable in the Background to be modified by one Scenario so that later ones can see the updated value - that is not how you should think of them, and you should combine your 'flow' into one scenario.

有许多方法可以在空手道中重用",例如 call .因此,您应该能够弄清楚如何做自己想做的事.

There are many ways to "re-use" in Karate such as call. So you should be able to figure out how to do what you want.

现在,如果您确实想要全局"变量,请使用 callonce 最有可能是您要寻找的东西:

Now if you really want a "global" variable, please use callonce that is most likely what you are looking for:

这篇关于在功能空手道Soap API的背景中声明全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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