------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}')     //##号内为定义哪个级别的属性变量,后面为属性名

最新文章

  1. NSInternalInconsistencyException
  2. 二模12day1解题报告
  3. 拦截JQuery的ajax
  4. dom cookie记录用户名
  5. Java [Leetcode 337]House Robber III
  6. 如何在 Java 中正确使用 wait, notify 和 notifyAll – 以生产者消费者模型为例
  7. FireDAC
  8. 栈ADT的链表实现
  9. C++ 学习之函数重载、基于const的重载
  10. 杂记:腾讯暑期实习 Web 后端开发面试经历
  11. IP的面向无连接状态
  12. leetcode — permutations-ii
  13. vue-router路由懒加载(解决vue项目首次加载慢)
  14. java框架之SpringBoot(2)-配置
  15. [Redis]Redis的五种数据类型与键值/服务器相关命令
  16. php实现猴子选大王
  17. Django开发笔记五
  18. python爬虫之分析Ajax请求抓取抓取今日头条街拍美图(七)
  19. ZooKeeper系列(8):ZooKeeper伸缩性
  20. Windows 网卡超过序列

热门文章

  1. MySQL(C#的链接姿势)
  2. 2019年,Python工程师必考的6个面试题,Python面试题No5
  3. Huffman codes
  4. 数据结构实验3:C++实现顺序栈类与链栈类
  5. 大数据学习——安装zooleeper
  6. python018 Python3 输入和输出
  7. GO 语言周报【七月第 1 期】
  8. HackerRank# Wet Shark and Two Subsequences
  9. HDU 1426 dancing links解决数独问题
  10. 【优先级队列】 Holedox Eating