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. jquery knob旋钮插件

    <!DOCTYPE html> <html> <head> <title>jQuery Knob 尝试</title> <script ...

  2. django-类装饰器method_decorator

    import os from django.shortcuts import render from django.contrib.admin.views.decorators import staf ...

  3. scrapy与redis分布式组件

    Scrapy 和 scrapy-redis的区别 Scrapy 是一个通用的爬虫框架,但是不支持分布式,Scrapy-redis是为了更方便地实现Scrapy分布式爬取,而提供了一些以redis为基础 ...

  4. 0_Simple__simpleCubemapTexture

    立方体纹理贴图 ▶ 源代码.用纹理方法把元素按原顺序从 CUDA3D 数组中取出来,求个相反数放入全局内存,输出. #include <stdio.h> #include "cu ...

  5. UI5-文档-1-前言

    主要是将SAP UI5官网文档做下了解,相关内容请查阅:https://sapui5.hana.ondemand.com/#/topic 设置您的开发环境并阅读我们的教程.它们使用交互式格式中的实际示 ...

  6. ztree参考

    ztree一 ztree二 ztree三

  7. 安装 neo4j 在 .../bin 目录下使用 ./neo4j 没反应 和 从csv 导入数据到neo4j

    可以使用 /bin/sh ./neo4j start 如果提示:./neo4j: 28: set: Illegal option -o pipefail 那么 ubuntu”set Illegal o ...

  8. Python基础语法题库

    引言: 语法练习包括Python基础语法.数据类型.字符编码和简单文件操作等内容. 正文(参考答案附录在题目下方): 1.Python 里用来告知解释器跳过当前循环中的剩余语句,然后继续进行下一轮循环 ...

  9. linux下mongodb授权登录

    mongodb版本为3.2(目前最新),演示的是linux下的mongodb授权认证 第一次登录不启动授权(mongo默认不启动) ./mongod --dbpath=/home/db/data -- ...

  10. ubuntu下搭建testlink

    环境配置: 1. 安装mysql 教程网上找 2. 安装apache sudo apt-get install apache2 重启apache服务 sudo /etc/init.d/apache2 ...