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的一些基本概念和使用的相关 ...
随机推荐
- HTML|CSS之布局相关总结
知识内容: 1.浮动相关 2.display属性 3.居中显示 4.盒模型和box-sizing 5.position属性 6.响应式设计 7.flex布局 8.其他 参考:http://zh.lea ...
- 常用数据库1 sqlserver
知识内容: 1.SqlServer数据库概述 2.SqlServer数据库基本操作 3.Transact-SQL程序设计 一.SqlServer数据库概述 1.SqlServer系统概述 SQLSer ...
- MVC 4 Razor Design Sample Demo Project
This is a demo project in MCV 4 razor design which encompases the general design of MVC pattern. The ...
- 34. CentOS-6.3安装配置Apache2.2.6
安装说明 安装环境:CentOS-6.3安装方式:源码编译安装 软件:httpd-2.2.6.tar.gz | pcre-8.32.tar.gz | apr-1.4.6.tar.gz | apr-u ...
- xml转json的方法
.第一种方法 使用JSON-JAVA提供的方法,之前一直使用json-lib提供的方法转json,后来发现了这个开源项目,觉得用起来很不错,并且可以修改XML.java中的parse方法满足自己的转换 ...
- xe7 控件升级
rm.ehlib.synedit OK SynSQLSyn1->TableNames 为NULL,导致添加数据失败,XE6正常 放在按钮里也不正常,就不说初始化次序引起的.
- Spring Boot 入门搭建
一.前言 Spring Boot 的设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 二.环境搭建 创建一个 ...
- Spring mvc 返回json包含双引号问题 解决
解决方式1: @RequestMapping(value="/shopsList.json", produces = "text/html;charset=UTF-8&q ...
- tensorflow Process finished with exit code 137 (interrupted by signal 9: SIGKILL) 错误
Process finished with exit code 137 (interrupted by signal 9: SIGKILL) 在使用tensorflow自带的数据集做手写数字识别的时候 ...
- locate包的安装
linux中locate命令可以快速定位我们需要查找的文件,但是在yum中,locate的安装包名为 mlocate(yum list | grep locate可以查看),安装方法: yum -y ...