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的更多相关文章

  1. [SoapUI] 如何同时调用Global Script Library(放在SoapUI安装目录)和项目特有的Script Libary(放在项目代码下)

    SoapUI 支持引入多个package: Global Script library : 在SoapUI工具File->Preference中设置Project Script Library: ...

  2. SoapUI--the use of Script Library

    SoapUI--the use of Script Library 有两种方法在soapUI中引用自己的groovy脚本库. 方法一:把自己的script folder放到soapUI install ...

  3. Script Library 配置 和 使用

    Script Library有两个级别,Workspace级别和Project级别 使用:这里的package指的是Script Library下的文件夹名,和引用代码里的package没有关系

  4. [SoapUI] Property Expansion in soapUI

    1. Property Expansion in soapUI SoapUI provides a common syntax to dynamically insert ("expand& ...

  5. [翻译]Component Registration in Script System 在脚本系统中注册组件

    Component Registration in Script System 在脚本系统中注册组件   To refer to our component from a script, the cl ...

  6. 酷酷的mapv

    做城市热力图的时候无意浏览到mapv强大的功能.比如地图上路线的汇聚效果,如下 <!DOCTYPE html> <html> <head> <meta cha ...

  7. FIS

    学习官网 http://fis.baidu.com/docs/beginning/getting-started.html   1. fis release: 编译并发布     fis releas ...

  8. SingalR--demo

    原文链接 : http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and ...

  9. 很不错的jQuery学习资料和实例

    这些都是学习Jquery很不错的资料,整理了一下,分享给大家. 希望能对大家的学习有帮助. 帕兰 Noupe带来的51个最佳jQuery教程和实例, 向大家介绍了jQuery的一些基本概念和使用的相关 ...

随机推荐

  1. 本地git仓库常用操作

    SSH配置: 本机创建SSH key $ ssh-keygen -t rsa -C "youremail@example.com" 将SSHkey添加到git仓库:id_rsa.p ...

  2. bootstrapValidator针对设置赋值进行验证

    bootstrapValidator在提交的时候可以进行验证,但是对于点击输入框进行赋值的时候验证失效. 解决方法: 然后在设置change方法方可解决.

  3. C# IIS 服务器 HTTP 错误 500.21 - Internal Server Error 解决办法

    <1> 管理员身份启动控制台 <2> 输入 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe ...

  4. jquery 的 $.extend 和 $.fn.extend

    $.extend({ add:function(a,b){return a+b;}, bad:function(a,b){return a-b;} }); $.fn.extend({ loading: ...

  5. sitemap

    sitemap对于网站就像是字典的索引目录,而这个目录的读者则是搜索引擎的爬虫.网站有了sitemap,有助于搜索引擎“了解”网站,这样会有助于站点的内容被收录. sitemap是一个由google主 ...

  6. mavenLocal默认地址转移

    maven的默认本地仓库为 USER_HOME/.m2/ windows开发我们大多不会讲本地仓库放在c盘下,而是重新指定了另一个存储位置. 在gradle中 使用 mavenLocal() 时的查找 ...

  7. UI5-文档-4.15-Nested Views

    我们的面板内容变得越来越复杂,现在是时候将面板内容移动到一个单独的视图中了.使用这种方法,应用程序结构更容易理解,应用程序的各个部分可以重用. Preview The panel content is ...

  8. Css 特性之 transition和transform

    CSS 有一些新的属性,可以简化代码的书写,用简单的代码就可以实现复杂的变化.不用像 js 那样,需要写很多代码 这里主要介绍三个属性:transition ,transform,以及translat ...

  9. JSP页面实现自动跳转

    1 <html><head><script language=javascript> function out(obj) {  var i = obj;  if ( ...

  10. Can not find the tag library descriptor for "http://www.springframework.org/tags"

    1.Download the Spring dependency jar2.Place it to the lib folder path is /WEB-INF/lib/spring.jar 3.T ...