soapUI系列之—-02 Groovy脚本常用方法
------Groovy脚本常用方法
1. 设置参数值:setPropertyValue
a. 设置 project level property
//set to project level property 下面两种写法都可
testRunner.testCase.testSuite.project.setPropertyValue("Name", "propValue");
testRunner.testCase.getTestSuite().getProject().setPropertyValue("Name", "propValue");; //项目对象
b. 设置 testSuite level property
//set to testSuite level property
testRunner.testCase.testSuite.setPropertyValue("Name","testSuiteValue");
testRunner.testCase.getTestSuite().setPropertyValue("Name","testSuiteValue");
c. 设置 testCase level property
//set to testCase level property
testRunner.testCase.setPropertyValue("Name","testCaseValue");
d. 设置 testStep level property
//set to testStep level property
testRunner.testCase.testSteps['Groovy'].setPropertyValue("Name","testSuiteValue");
testRunner.testCase.getTestStepByName("Groovy").setPropertyValue("Name","testSuiteValue");
2. 定位到某个testSuites
def testSuite = testRunner.testCase.testSuite.project.testSuites['testSuites Name'];
3. 获取TestCase个数:getTestCaseCount()
for(int i=0; i<testSuite.getTestCaseCount(); i++) {
if (!testSuite.getTestCaseAt(i).isDisabled()) {
if (!(testSuite.getTestCaseAt(i).getTestStepByName("stepName")).equals()){
.....
}
}
}
4. 获取TestSuite个数:getTestSuiteCount()
testRunner.testCase.testSuite.project.getTestSuiteCount()
5. 获取名称
a. 取test case的名称:getLabel()
def tc = testRunner.testCase;
log.info (tc.getLabel());
b. 取test suite的名称:getLabel()
def ts = testRunner.testCase.testSuite;
log.info (ts.getLabel());
c. 取project 名称
def tp = testRunner.testCase.testSuite.project;
log.info (tp.getName());
6.层级访问
testRunner.testCase.testSuite.project.testSuites[testSuiteName].testCases[testCaseName].testSteps[testStepName]
/*Case1:练手详图如下*/
import com.eviware.soapui.support.GroovyUtils
def testSuite = testRunner.testCase.testSuite.project.testSuites['业务场景']
log.info(testSuite.getName())
log.info(testSuite.getTestCaseCount())
for(int i=0; i<testSuite.getTestCaseCount(); i++) {
if (!testSuite.getTestCaseAt(i).isDisabled()) {
log.info( testSuite.getTestCaseAt(i).getLabel() )
if (!(testSuite.getTestCaseAt(i).getTestStepByName("issueconfirmJQ")).equals()){
def appnoJQ =testSuite.getTestCaseAt(i).getPropertyValue("proposalNoJQ")
log.info( "JQ:"+ appnoJQ)
}
if (!(testSuite.getTestCaseAt(i).getTestStepByName("issueconfirmSY")).equals()){
def appnoSY =testSuite.getTestCaseAt(i).getPropertyValue("proposalNoSY")
log.info( "SY:"+ appnoSY)
}
}
}
层级关系如下图所示

log 如下图:

7.SoapUI允许在项目的各个层次中定义变量,常用的层次包括: Project,TestSuite,TestCase,Global等
如果在 Groovy Script中使用这些全局变量的话,可以用以下方法:
def time_num= context.expand ('${#Project#hospitalId}') //##号内为定义哪个级别的属性变量,后面为属性名
soapUI系列之—-02 Groovy脚本常用方法的更多相关文章
- soapUI系列之—-03 Groovy脚本常用方法2
------Groovy脚本常用方法 1.解析Json数据脚本 //groovy读取json的方式很简单,re.body.businessinfo.c2rate读取c2rate对应的值 import ...
- [SoapUI] Post请求Body里面限制特殊字符(&、%),Groovy脚本里特殊字符需要添加“\”转义($)。
SoapUI的Post请求,在body里面不能包含(&.%),如果含有这些特殊字符,请求会报错:在添加的Groovy脚本里有些特殊字符需要使用“\”转义($),不然也会报错.
- soapUI参数中文乱码问题解决方法 (groovy脚本中文乱码)
soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...
- excel文件的groovy脚本在SoapUI中进行数据驱动测试
SoapUI Pro具有从外部文件读取数据的功能,例如:excel,csv等.但SoapUI不提供从excel文件读取数据的功能.因此,为了从SoapUI中的excel文件中读取数据,我们需要在gro ...
- 180807-Quick-Task 动态脚本支持框架之Groovy脚本加载执行
Quick-Task 动态脚本支持框架之Groovy脚本加载执行 上一篇简答说了如何判断有任务动态添加.删除或更新,归于一点就是监听文件的变化,判断目录下的Groovy文件是否有新增删除和改变,从而判 ...
- [Tomcat 源码分析系列] (二) : Tomcat 启动脚本-catalina.bat
概述 Tomcat 的三个最重要的启动脚本: startup.bat catalina.bat setclasspath.bat 上一篇咱们分析了 startup.bat 脚本 这一篇咱们来分析 ca ...
- jenkins2 groovy脚本参考
使用plugin生成groovy脚本,或者参考已有的groovy脚本. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.co ...
- ODI 12c中使用Groovy脚本创建工程
本文主要介绍在ODI中使用groovy创建工程,并添加一个表转换的映射.要创建groovy脚本,可以从ODI Studio的菜单:工具->Groovy->新脚本 打开一个编辑窗口.在执行下 ...
- JAVA嵌入运行Groovy脚本
摘自: http://shift-alt-ctrl.iteye.com/blog/1938238 . 最近设计一个数据统计系统,系统中上百种数据统计维度,而且这些数据统计的指标可能随时会调整.如果基于 ...
随机推荐
- [IOS初学]ios 第一篇 storyboard 与viewcontroller的关系 - Zoe_J
时间 2014-07-27 16:08:00 博客园-所有随笔区 原文 http://www.cnblogs.com/zoe-j/p/3871501.html 主题 StoryBoard 学习了一 ...
- RN传参的问题
RN父组件通过props属性给子组件传参,假设参数 target={target} 子组件在render函数里 let { target } = this.props; 如果子组件有个 FlatLis ...
- 【简●解】[ZJOI2005]午餐
[简●解][ZJOI2005]午餐 [关键词] \(DP\) 排序/贪心 [分析] 首先,一个很明显的贪心思路,就是吃的慢的人先打饭.所以把数据按吃饭时间从大到小排一遍序. 根据\(dp\)的尿性,比 ...
- python常用模块之sys, os, random
一. sys模块 1. 作用: sys模块是与python解释器交互的一个接口 2. 具体使用 1. sys.argv 获取当前正在执行的命令行列表, 第一个为程序本身路径 print('file n ...
- Django-Ajax组件
Ajax Ajax简介 AJAX(Asynchronous Javascript And XML),翻译成中文为"异步Javascript和XML".即使用Javascript语言 ...
- LeetCode(14)Longest Common Prefix
题目 Write a function to find the longest common prefix string amongst an array of strings. 分析 该题目是求一个 ...
- 实现List集合中数据逆序排列
Collections.reverse(list); 实现list集合逆序排列
- Java.lang.NoSuchMethodError: 后带 V/Z等字母的
知道 Java.lang.NoSuchMethodError: 后带 V/Z等字母的 错误,一般都是 jar包冲突引起的,找到冲突的jar包,去掉一个就好
- 服务器架构及实战(架构篇)- PHP建站
概述 详解 PHP的环境搭建 PHP的帮助使用和配置文件 PHP的Hello World PHP的库函数调用 PHP的Web程序 PHP的函数和面向对象使用 PHP的数据库访问 Nginx安装和配置访 ...
- HDU4135容斥原理
#include <cstdio> #include <string.h> #include <cmath> using namespace std; #defin ...