SOAPUI从命令行执行groovy脚本

时间:2016-04-26 12:00:52

标签: batch-file soapui

我编写了批处理脚本,它从命令行执行soapui。它确实像启动LoadTestRunner并在指定的文件夹中生成报告。 在我的测试步骤中,我需要在明天日期更改特定节点中的日期。我写的groovy脚本在soapui中运行正常但我无法从批处理脚本加载它。

我的问题是:是否有可能从控制台运行测试(批处理脚本),但首先运行groovy脚本,它将更改同一批处理脚本中的日期?

我的常规剧本:

import com.eviware.soapui.impl.wsdl.teststeps.*

def ui = com.eviware.soapui.support.UISupport;
def project = context.testCase.testSuite.project

def testSuite = project.getTestSuiteAt(0)
def testCase = testSuite.getTestCaseAt(0)

//set date  
def today = new Date()
def dd = today.getDate() + 1
def mm = today.getMonth() + 1  //January is 0!
def yyyy = 1900 + today.getYear()

if (dd < 10)   dd = '0' + dd
if (mm < 10)  mm = '0' + mm

tomorrowsDateAndTime = yyyy + '-' + mm + '-' + dd  + "+01:00"

//xml paths to change date
def somePathToChangeDate = "//somePathToChangeDate"
def somePathToChangeDate2 = "//somePathToChangeDate2"

def stepList = testCase.getTestStepList() //list of all tests in package

for (singleTest in stepList) {
    log.info("          " + singleTest.getName())
    def testName = singleTest.getName()
    testSuite.setPropertyValue("testName",  testName)
    def testStep = testCase.getTestStepByName(testName)
    def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(testStepContext) 
    def inputHolder = testName + "#Request"
    def holderRawReq = groovyUtils.getXmlHolder(inputHolder)    

    holderRawReq[somePathToChangeDate] = tomorrowsDateAndTime
    holderRawReq[somePathToChangeDate2] = tomorrowsDateAndTime

    holderRawReq.updateProperty()
}
log.info "          Dates are updated"

我的批处理脚本:

@echo off

cd %~dp0\SoapUI-5.2\bin

cmd.exe /C loadtestrunner.bat -s"TestSuite 1" -cmyTests -l"LoadTest 1" -uusername -ppassword -r -f%~dp0\reports %~dp0\my-soapui-project.xml


setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" %~dp0\Reports\LoadTest_1-log.txt| find /C ":""

::this code checks if there are any error reports
for /f %%a in ('!cmd!') do set iterator=%%a
echo %iterator%
cls

if [%iterator%] equ [3] (echo "Tests was completed successfully") else ( 

    echo "Tests failed"
 )

pause

0 个答案:

没有答案