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. 解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办

    解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办 问题是出现在了PHP.INI上面了 ,原 ...

  2. 《GPU高性能编程CUDA实战》第十一章 多GPU系统的CUDA C

    ▶ 本章介绍了多设备胸膛下的 CUDA 编程,以及一些特殊存储类型对计算速度的影响 ● 显存和零拷贝内存的拷贝与计算对比 #include <stdio.h> #include " ...

  3. 1_Utilities__deviceQuery + 1_Utilities__deviceQueryDrv + 1_Utilities__topologyQuery

    使用 Runtime API 和 Driver API 检测设备相关属性.并检测了设备之间的拓扑以及主机与设备之间的拓扑(是否支持跨设备原子操作). ▶ 源代码:Runtime API #includ ...

  4. HTML5 通过文件输入框读取文件为base64文件, 并借助canvas压缩 FileReader, files, drawImage

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. leetcode179

    class Solution { public: string largestNumber(vector<int>& nums) { int n=nums.size(); vect ...

  6. 11.使用ForwardAction实现页面屏蔽。

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 我们在jsp页面之间写链接总会是.../xxx.jsp,而如果我们想屏蔽掉具 ...

  7. JetBrains产品永久破解

    吃水不忘挖井人,本博客转自:https://www.cnblogs.com/jyiqing/p/7699649.html 目的: 本人使用idea和webstorm进行开发,无奈正版实在是太贵了,只能 ...

  8. java.util包简介

    java.util包含集合框架.遗留的 collection 类.事件模型.日期和时间设施.国际化和各种实用工具类(字符串标记生成器.随机数生成器和位数组.日期Date类.堆栈Stack类.向量Vec ...

  9. Linux下基于官方源代码RPM包构建自定义MySQL RPM包

    rpmbuild时不要以root用户执行! 方法一: 1.首先安装rpmbuild #yum install rpm-build gcc gcc-c++ cmake bison ncurses-dev ...

  10. 吴裕雄 数据挖掘与分析案例实战(3)——python数值计算工具:Numpy

    # 导入模块,并重命名为npimport numpy as np# 单个列表创建一维数组arr1 = np.array([3,10,8,7,34,11,28,72])print('一维数组:\n',a ...