昨晚帮老同事解决了一个SoapUI的代码问题,好长时间没用SoapUI,好多东西都忘了,今天先总结下Groovy读取properties

首先吐槽下SoapUI的apidocs,我几乎从中看不出什么东西,官网的tips有那么一点用,但是好长时间没有更新了,好多东西都找不到。而且在SoapUI里调试Groovy代码几乎不太可能。

APIDocs: http://www.soapui.org/apidocs/index.html?com/eviware/soapui/model/testsuite/TestRunContext.html

废话不多说,首先获取当前的testsuite:

def ts =  testRunner.testCase.testSuite

获取的properties文件路径:

def filename =  “C:\\TestSuiteProperties\\CurrentTestingEnvironment\\endpoints.properties"
log.info "Loading properties from " + filename

使用java包导入properties:

def props = new java.util.Properties();
props.load( new java.io.FileInputStream(filename));

利用Emumeration读取properties value,并设置到testsuite的properties中去:

Enumeration e = props.keys();
while (e.hasMoreElements())
{
key = e.nextElement();
val = props.get(key);
ts.setPropertyValue(key, val);
log.info "Set property " + key + " to " + val;
}

这是一个properties参数的初始化过程。

另外一个一次读取txt文件的内容赋值给request的脚本:

def file = new File("C:/temp/yourFile.txt")

// for each line
file.eachLine { line ->
// put the property for your request
testRunner.testCase.setPropertyValue("myProperty",line)
// execute your request
testRunner.runTestStepByName( "myRequest")
log.info "execute request for line: " + line
}

Groovy读取properties及txt的更多相关文章

  1. Java 读取Properties文件时应注意的路径问题

    1. 使用Class的getResourceAsStream()方法读取Properties文件(资源文件)的路径问题:  InputStream in = this.getClass().getRe ...

  2. 使用Properties类和ResourceBundle类读取properties文件

    一.介绍: 项目中经常把一些常用的用户名和密码都填写到一个对应的配置文件中,这样每次修改密码或者用户名的时候就可以直接修改这个配置文件了,不用动源码. 这里讲两种方式读取properties文件的方法 ...

  3. Spring用代码来读取properties文件

    我们都知道,Spring可以@Value的方式读取properties中的值,只需要在配置文件中配置org.springframework.beans.factory.config.PropertyP ...

  4. 五种方式让你在java中读取properties文件内容不再是难题

    一.背景 最近,在项目开发的过程中,遇到需要在properties文件中定义一些自定义的变量,以供java程序动态的读取,修改变量,不再需要修改代码的问题.就借此机会把Spring+SpringMVC ...

  5. java分享第十六天( java读取properties文件的几种方法&java配置文件持久化:static块的作用)

     java读取properties文件的几种方法一.项目中经常会需要读取配置文件(properties文件),因此读取方法总结如下: 1.通过java.util.Properties读取Propert ...

  6. 用eclipse做项目中常遇到的问题-如何创建并读取properties文件

    在用eclipse做项目开发的时候我们常常会将一些重要的内容写在配置文件里面, 特别是连接数据库的url,username,password等信息,我们常常会新建一个properties文件将所有信息 ...

  7. jsp读取properties文件

    jsp读取properties文件 jsp中读取properties文件,并把值设到js变量中: mpi.properties文件内容: MerchantID=00000820 CustomerEMa ...

  8. java读取.properties文件

    在web开发过程中,有些配置要保存到properties文件里,本章将给出一个工具类,用来方便读取properties文件. 案例: 1:config.properties文件 name=\u843D ...

  9. 读取.properties配置文件

    方法1 public  class SSOUtils { protected static String URL_LOGIN = "/uas/service/api/login/info&q ...

随机推荐

  1. [转]设置控件全局显示样式appearance proxy

    转自:huifeidexin_1的专栏 appearance是apple在iOS5.0上加的一个协议,它让程序员可以很轻松地改变某控件的全局样式(背景) @selector(appearance) 支 ...

  2. Windows Services Windows Services的操作

    Windows Services的操作 一.服务的创建: 1.新建项目——Windows服务 2.这是每个人都会犯的错误,新建一个项目后,都会按F5(运行),就会出现如下错误: 3.安装服务有很多种方 ...

  3. postgreSQLG关闭活动的connection、删除活动的数据库

    First, find the activities that are taken place against the target database, you can query thepg_sta ...

  4. Python 脚本生成测试数据,Python生成随机数据,Python生成大量数据保存到文件夹中

    代码如下: import random import datetime import time dataCount = 10*100*100 #10M. codeRange = range(ord(' ...

  5. R之批处理

    在linux下如何编写脚本调用R语言写的程序呢? R语言进行批处理有2种方式: R CMD BATCH --options scriptfile outputfile Rscript --option ...

  6. hdu-4893-Wow! Such Sequence!-线段树【2014多校第三场-J】

    题意:一个初始为0的数组,支持三种操作:1.向第k个数添加d,(|d| < 2^31);2.把[l, r]区间内的数字都换成与它最相近的Fibonacci数;3.询问[l, r]区间的和. 思路 ...

  7. leetcode:Reverse Bits

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  8. hdu4003Find Metal Mineral(树形DP)

    4003 思维啊 dp[i][j]表示当前I节点停留了j个机器人 那么它与父亲的关系就有了 那条边就走了j遍 dp[i][j] = min(dp[i][j],dp[child][g]+dp[i][j- ...

  9. java.lang.InstantiationException: DWR can't find a spring config. See the logs for solutions

    在spring整合dwr时,报找不到配置文件 DWRcan't find a spring config. See the logs for solutions 解决办法: 在web.xml中添加一下 ...

  10. 今天maven install时碰到的两个问题(堆溢出和编译错误)

    问题1.maven install时出现,日志如下: 系统资源不足.有关详细信息,请参阅以下堆栈追踪. java.lang.OutOfMemoryError: Java heap space at c ...