------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脚本常用方法的更多相关文章

  1. soapUI系列之—-03 Groovy脚本常用方法2

    ------Groovy脚本常用方法 1.解析Json数据脚本 //groovy读取json的方式很简单,re.body.businessinfo.c2rate读取c2rate对应的值 import ...

  2. [SoapUI] Post请求Body里面限制特殊字符(&、%),Groovy脚本里特殊字符需要添加“\”转义($)。

    SoapUI的Post请求,在body里面不能包含(&.%),如果含有这些特殊字符,请求会报错:在添加的Groovy脚本里有些特殊字符需要使用“\”转义($),不然也会报错.

  3. soapUI参数中文乱码问题解决方法 (groovy脚本中文乱码)

    soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...

  4. excel文件的groovy脚本在SoapUI中进行数据驱动测试

    SoapUI Pro具有从外部文件读取数据的功能,例如:excel,csv等.但SoapUI不提供从excel文件读取数据的功能.因此,为了从SoapUI中的excel文件中读取数据,我们需要在gro ...

  5. 180807-Quick-Task 动态脚本支持框架之Groovy脚本加载执行

    Quick-Task 动态脚本支持框架之Groovy脚本加载执行 上一篇简答说了如何判断有任务动态添加.删除或更新,归于一点就是监听文件的变化,判断目录下的Groovy文件是否有新增删除和改变,从而判 ...

  6. [Tomcat 源码分析系列] (二) : Tomcat 启动脚本-catalina.bat

    概述 Tomcat 的三个最重要的启动脚本: startup.bat catalina.bat setclasspath.bat 上一篇咱们分析了 startup.bat 脚本 这一篇咱们来分析 ca ...

  7. jenkins2 groovy脚本参考

    使用plugin生成groovy脚本,或者参考已有的groovy脚本. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.co ...

  8. ODI 12c中使用Groovy脚本创建工程

    本文主要介绍在ODI中使用groovy创建工程,并添加一个表转换的映射.要创建groovy脚本,可以从ODI Studio的菜单:工具->Groovy->新脚本 打开一个编辑窗口.在执行下 ...

  9. JAVA嵌入运行Groovy脚本

    摘自: http://shift-alt-ctrl.iteye.com/blog/1938238 . 最近设计一个数据统计系统,系统中上百种数据统计维度,而且这些数据统计的指标可能随时会调整.如果基于 ...

随机推荐

  1. springmvc请求方法那些事

    @RequestMapping 用法详解之地址映射 (2013-08-11 16:06:58) 转载▼ 标签: it   前段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式 ...

  2. 695. Max Area of Island@python

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  3. [CF] 219D Choosing Capital for Treeland

    题意翻译 题目描述 Treeland国有n个城市,这n个城市连成了一颗树,有n-1条道路连接了所有城市.每条道路只能单向通行.现在政府需要决定选择哪个城市为首都.假如城市i成为了首都,那么为了使首都能 ...

  4. tensorflow with gpu 环境配置

    1.准备工作 1.1 确保GPU驱动已经安装 lspci | grep -i nvidia 通过此命令可以查看GPU信息,测试机已经安装GPU驱动

  5. 【HIHOCODER 1038】 01背包

    链接 问题描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了! 小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖 ...

  6. [SHELL]awk的用法举例

    从初学awk到现在小有所成,非常感谢CUers的帮助,总结了下自己曾经遇到的问题和犯的错误,供初学者借鉴,因本人非计算机专业,对专业词汇可能有表述不对的地方,还请指正和补充! 1. awk '{cod ...

  7. 大数据学习——实现多agent的串联,收集数据到HDFS中

    采集需求:比如业务系统使用log4j生成的日志,日志内容不断增加,需要把追加到日志文件中的数据实时采集到hdfs,使用agent串联 根据需求,首先定义以下3大要素 第一台flume agent l  ...

  8. Leetcode 264.丑数II

    丑数II 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10 ...

  9. 数据库连接 Mysqli

    //数据库连接 Mysqli $db= new Mysqli("localhost","root","root","asd_808 ...

  10. HDU-2509-Be the Winner,博弈题~~水过~~

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ht ...