zoukankan      html  css  js  c++  java
  • Groovy读取properties及txt

    昨晚帮老同事解决了一个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
    }
  • 相关阅读:
    MySQL组提交(group commit)
    MySQL 热快问题解决
    Mysql 高可用集群PXC
    向量的点积(标量积、内积)
    BitmapData.threshold()方法
    Unity 自定义导入时切割Sprite
    匀变速直线运动的速度与位移的关系
    1.1.2 三角形余弦定理
    ccc切割刚体
    Unity 获取指定资源目录下的所有文件
  • 原文地址:https://www.cnblogs.com/goldenRazor/p/4850670.html
Copyright © 2011-2022 走看看