SoapUI Script Library
Environment
Get active environment via groovy script
log.info testRunner.testCase.testSuite.project.getActiveEnvironment().getName()
Set active environment via groovy script
testRunner.testCase.testSuite.project.setActiveEnvironment("Live")
Get request
Get request header via messageExchange
def requestID = messageExchange.requestHeaders.get("X-API-RequestId")
Get test step name via messageExchange
def testStepName = messageExchange.modelItem.name
Get response
Get response by testRunner
def response = testRunner.testCase.testSteps["InitCase"].testRequest.response.contentAsString
Get response by Context
// Get response
String testStepName = "Intraday Table"
def responseLive = context.expand( '${'+testStepName+'#Response}' )
Get response by messageExchange
def response = messageExchange.getResponseContent()
Get response header
def headers = messageExchange.getResponseHeaders()
Parse XML
XPath Parse XML : Get node value
import com.eviware.soapui.support.GroovyUtils //Get xmlHolder of the xml response
def groovyUtils = new GroovyUtils( context )
def xmlHolder = groovyUtils.getXmlHolder( "testStepName#ResponseAsXml" ) //Parse response by XPath
def data = xmlHolder .getNodeValue("//html[1]/body[1]/text()")
XPath Parse XML : Get nodes list and attributes
import com.eviware.soapui.support.GroovyUtils def testStepName = "Intraday Table"
def XPath = "//B/I/I" // Get response
def groovyUtils = new GroovyUtils(context)
def xmlHolder = groovyUtils.getXmlHolder(testStepName+"#ResponseAsXml") // Get nodes list
def nodesArray = xmlHolder.getDomNodes(XPath)
List nodesList = nodesArray.toList() for(int i=0;i<nodesList.size();i++){
def attributes = nodesList.get(i).getAttributes()
def attributesNumber = attributes.getLength()
XmlParser parse XML : parse xml in json
import groovy.json.JsonSlurper def testStepname = "Attribution Detail"
def responseLive = context.expand( '${'+testStepName+'#Response}' ) def jsonLive = new JsonSlurper().parseText(responseLive)
String xmlRecordLive = jsonLive.data.data def xmlParser = new XmlParser()
def xmlLive = xmlParser.parseText(xmlRecordLive) def nodesArrayLive = xmlLive.Body.B.I
List nodesListLive = nodesArrayLive.toList()
int recordsNumberLive = nodesListLive.size()
Parse JSON
JsonPath Parse JSON : Get datas list
import com.jayway.jsonpath.* def testStepName = "Holdings Scatter Plot"
def JPath = '$.Holdings[*]' def response = context.expand( '${'+testStepName+'#Response}' )
def datasList = JsonPath.read(response, JPath)
JsonSlurper Parse JSON : Get data
import groovy.json.JsonSlurper
// Get response
def testStepName = "Holdings Scatter Plot" def response = context.expand( '${'+testStepName+'#Response}' )
def jsonSlurper = new JsonSlurper().parseText(response)
def datas = jsonSlurper.data.data
Verify JSON Node's value
import groovy.json.JsonSlurper def response = messageExchange.getResponseContent()
def json = new JsonSlurper().parseText(response)
def clientCount = json.pagination.count assert clientCount>0,"No client"
Get test suite/case/step name
Get test step, test case and test suite's name
// Get test steps' name
def currentStepIndex = context.currentStepIndex
String currentStepName = testRunner.testCase.getTestStepAt(currentStepIndex).name
String previousStepName = testRunner.testCase.getTestStepAt(currentStepIndex-1).name
String prePreStepName = testRunner.testCase.getTestStepAt(currentStepIndex-2).name // Get test case and test suite's name
String testCaseName = testRunner.testCase.getTestStepAt(currentStepIndex).getParent().getName()
String testSuiteName = testRunner.testCase.getTestStepAt(currentStepIndex).getParent().getParent().getName()
Get property
Get property value by testRunner
String testResultPath = testRunner.testCase.testSuite.project.getPropertyValue( "testResultPath" )
Get property value by context
String dataDeviationFile = context.expand( '${#Project#dataDeviationFile}' )
Set property
Set property value by testRunner
testRunner.testCase.testSuite.project.setPropertyValue( "cookie", cookieNew )
Control flow
Goto test step by name
testRunner.gotoStepByName("Copy File")
SoapUI Script Library的更多相关文章
- [SoapUI] 如何同时调用Global Script Library(放在SoapUI安装目录)和项目特有的Script Libary(放在项目代码下)
SoapUI 支持引入多个package: Global Script library : 在SoapUI工具File->Preference中设置Project Script Library: ...
- SoapUI--the use of Script Library
SoapUI--the use of Script Library 有两种方法在soapUI中引用自己的groovy脚本库. 方法一:把自己的script folder放到soapUI install ...
- Script Library 配置 和 使用
Script Library有两个级别,Workspace级别和Project级别 使用:这里的package指的是Script Library下的文件夹名,和引用代码里的package没有关系
- [SoapUI] Property Expansion in soapUI
1. Property Expansion in soapUI SoapUI provides a common syntax to dynamically insert ("expand& ...
- [翻译]Component Registration in Script System 在脚本系统中注册组件
Component Registration in Script System 在脚本系统中注册组件 To refer to our component from a script, the cl ...
- 酷酷的mapv
做城市热力图的时候无意浏览到mapv强大的功能.比如地图上路线的汇聚效果,如下 <!DOCTYPE html> <html> <head> <meta cha ...
- FIS
学习官网 http://fis.baidu.com/docs/beginning/getting-started.html 1. fis release: 编译并发布 fis releas ...
- SingalR--demo
原文链接 : http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and ...
- 很不错的jQuery学习资料和实例
这些都是学习Jquery很不错的资料,整理了一下,分享给大家. 希望能对大家的学习有帮助. 帕兰 Noupe带来的51个最佳jQuery教程和实例, 向大家介绍了jQuery的一些基本概念和使用的相关 ...
随机推荐
- 了解ES6
内容: 1.ES6介绍及基础 2.模块.类和继承 3.ES6高级特性 4.Generator和Iterator 5.异步编程 6.函数相关 内容参考:<ES6 标准入门> ES6标准阅读链 ...
- Redis 几个全局命令, 以及事物
1, 清空当前数据库的所有数据 => flushdb 2, 清空所有数据库的所有数据 => flushall 3, key 值检索命令 => scan num match if 会 ...
- ant 注意
nt文件在部署时,如果控制台出现乱码则需要调整语言. 高版本eclipse在jdk高版本中已经植入了ant的部署.因此不需要单独配置ant.jar. 如果版本低,可下载ant插件,或者下载ant的工具 ...
- 16 python xml模块
1.基本概念 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单. 不过,古时候,在json还没诞生的黑暗年代,大家只能选择用xml呀. 至今很多传统公司如金 ...
- 12 python json&pickle&shelve模块
1.什么叫序列化 序列化是指把内存里的数据类型转变成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘或网络传输时只能接受bytes(字节) 2.用于序列化的两个模块,json和pickle ...
- SAP订单状态最详细的解释
order status description explanation CRTD 建立 生产订单创建时的状态,表明订单处于刚刚创建时点,不允许做后续发料,确认等操作. PREL 部分释放(部分下达) ...
- from __future__ import division
导入python未来支持的语言特征division(精确除法),当我们没有在程序中导入该特征时,"/"操作符执行的是截断除法(Truncating Division),当我们导入精 ...
- libUpnp缓冲区溢出、拒绝服务等漏洞分析
该漏洞存在于UPnP™设备的便携式SDK中,也叫做 libupnp.这个库是用来实现媒体播放(DLAN)或者NAT地址转换(UPnP IGD).智能手机上的应用程序可用这些功能播放媒体文件或者利用用户 ...
- nginx+redis+4个tomcat 负载均衡
1,先配置nginx ,如果80接口被占用,且80 的端口又惹不起,参考:https://www.cnblogs.com/xiaohu1218/p/10267602.html 2,下载redis,并配 ...
- delphi 中判断对象是否具备某一属性
Uses TypInfo; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); ...