def name = context.expand( '${Input#TG}' )
def locatie = context.expand( '${#TestCase#locatie}' )

def createFolder(locatie) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy')
shortDate = dateFormat.format(date)
outputFolder = locatie+shortDate
createFolder = new File(outputFolder)
createFolder.mkdir()
}

def getResponseFilename(shortDate,name) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy HH:mm:ss')
shortDate = dateFormat.format(date)
respFilename = shortDate+"_"+name+"_response.xml"
}

def getRequestFilename(shortDate,name) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy HH:mm:ss')
shortDate = dateFormat.format(date)
reqFilename = shortDate+"_"+ name+"_request.xml"
}

def file = new PrintWriter (createFolder(locatie)+getResponseFilename(shortDate,name))
def response = testRunner.testCase.testSteps["CheckAdres"].testRequest.response.contentAsString
file.println(response)
file.flush()
file.close()

def file2 = new PrintWriter (createFolder(locatie)+getRequestFilename(shortDate,name))
def request = context.expand('${CheckAdres#Request}')
file2.println(request)
file2.flush()
file2.close()


You could start with a different date format, since ":" is not accepted in a filename, try:

shortDate = new Date().format("ddMMyyyy HHmmss").toString();



The error occurs because of your line:

def file = new PrintWriter (createFolder(locatie)+getResponseFilename(shortDate,name))



If I run the following line against your script, it returns a boolean, hence the boolean.plus.

log.info createFolder(locatie)



The script seems to run if I add the following line at the end of createFolder(locatie):

return outputFolder


블로그 이미지

요다할아범

,

import java.io.File

import java.util.Date

import jxl.*


import groovy.xml.MarkupBuilder

import org.custommonkey.xmlunit.*


//read excelfile

wb = Workbook.getWorkbook(new File('C:/.../ChangedData.xls'))


sheet = wb.getSheet(0)


def writer = new FileWriter('C:/.../data.xml')

def xml = new MarkupBuilder(writer)

xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")

//=======================

//xml.users(){user(count:'i')



   for (int i=1; i<sheet.getRows();i++) {



      for (int j=0; j<sheet.getColumns(); j++){

           p=sheet.getCell(j,i).getContents()



      log.info p

       }

   }

}

wb.close()

블로그 이미지

요다할아범

,
/* 
@Author : Pradeep Bishnoi
@Description : Collection of groovy script snippets required to achieve automation in soapUI
*/

1. Using Log variable
 log.info(“Any Text message ” + anyVariable)

2. Using Context variable
 def myVar = context.expand( ‘${#TestCase#SourceTestStep}’) //will expand TestCase property value into the new variable
    context.testCase  // returns the current testCase handle

3. Using TestRunner variable
 testRunner.testCase.getTestStepByName(“TestStepName”)
    testRunner.testCase // return the handle to current testCase
    testRunner.testCase.testSuite.project.testSuites[“My_TestSuite”]

4. Using MessageExchange variable
 messageExchange.getEndpoint() //endpoint to the selected teststep
    messageExchange.getTimestamp()    //timestamp
    messageExchange.getTimeTaken()    //time taken to process the request/response

5. Using Project, TestSuite, TestCase, TestStep methods
def project = testRunner.testCase.testSuite.project
    def project = context.testCase.testSuite.project

    def myTestSuite = project.getTestSuiteAt(IndexNumber)
    def myTestSuite = project.getTestSuiteByName(“Name of the TestSuite”)

    def myTestCase = myTestSuite.getTestCaseAt(IndexNumber)
    def myTestCase = myTestSuite.getTestCaseByName(“Name of the TestCase”)

    def myTestStep = myTestCase.getTestStepAt(IndexNumber)
    def myTestStep = myTestCase.getTestStepByName(“Name of the TestStep”)

6. RawRequest & RawResponse
    messageExchange.getRequestContentAsXml.toString()
    messageExchange.getResponseContentAsXml.toString()

7. groovyUtils & XmlHolder
 def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder (“Assert_Script#Response”)

8. Converting String into Integer & Integer into String using groovy
   anyStringVar = anyIntegerVar.toString()
    anyIntegerVar = anyStringVar.toInteger()

9. Reading & Writing user-defined property with Groovy
 def userIdInStep = testRunner.testCase.getTestStepByName( “UserDefinedProperty” )
    def userIdStr = userIdInStep.getPropertyValue( “myPropertyName” );
    userIdInStep.setPropertyValue(“myPropertyName”, “StringValueAsInput”)

10. Refer soapUI API docs & go soapUI Pro inorder to get Advanced functionality without writing code 😉

11. today

today = new Date().format("yyyy-MM-dd")

log.info today

블로그 이미지

요다할아범

,

/*

 * https://thetestsuite.wordpress.com/2013/09/30/soapui-groovy-slurping-json-in-script-assertions/

*/

//imports

import groovy.json.JsonSlurper

 

//grab the response

def ResponseMessage = messageExchange.response.responseContent

def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)

 

//verify the slurper isn't empty

assert !(jsonSlurper.isEmpty())


//verify the Id, Type and Guid aren't null

assert jsonSlurper.data.messages.msg != null

assert jsonSlurper.data.confidenceScore != null

assert jsonSlurper.data.nluResult != null


def nluResultSlurper = new JsonSlurper().parseText(jsonSlurper.data.nluResult)

assert !(nluResultSlurper.isEmpty())

assert nluResultSlurper.text != null


def score = jsonSlurper.data.confidenceScore

def msg = jsonSlurper.data.messages.msg

def text = nluResultSlurper.text


if( score >= 0.8 ) //  등록된 응답

{

assert jsonSlurper.data.messages.msg.contains("인간의 수명은 길어졌지만 병과 사고는 더 많아졌습니다. 급작스런 투병이나 사고로부터 나와 내 가족을 지키기 위해 보험은 필수입니다.")

}

else if( score >= 0.6 && score < 0.8 ) // 재질문

{

assert jsonSlurper.data.messages.msg.contains("보험이 왜 필요한지 알려드릴까요?")

}

else if( score < 0.6 ) // 상담사 연결 응답

{

assert jsonSlurper.data.messages.msg.contains("원하시는 답변 드리지 못해 죄송합니다.\n전문 상담사가 도와 드리겠습니다.")

}



/////////////////////////////////////////////////////////////////////////////////////

{"data":{"confidenceScore":0.88,"isTalkOpen":false,"nluResult":"[{\"text\":\"요즘 저가 보험 어떤거야\",\"error\":{\"message\":\"\",\"code\":0},\"asr_rank\":0,\"nlu_nbest\":[{\"action_kr\":\"search.insurance.by_price\",\"confidence_score\":0.88,\"status\":\"accept\",\"action\":\"search.insurance.by_price\",\"domain\":\"finance\",\"entities\":[{\"text\":\"요즘\",\"role\":\"DATETIME\",\"type\":\"TI_RECENT\",\"type_kr\":\"시간(최신)\"},{\"text\":\"저가\",\"role\":\"\",\"type\":\"PRICE_LOW\",\"type_kr\":\"가격\"},{\"text\":\"보험\",\"role\":\"PRODUCT\",\"type\":\"FP_CATEGORY\",\"type_kr\":\"FP_CATEGORY\"}]}]}]","errorCode":0,"messages":[{"flag":"B","seq":1,"type":"CEV","cdate":"20170207104250","msg":"저희 보험사를 이용하시면 좋은 보험을 저렴하게 이용하실 수 있습니다. \u003ca href \u003d \u0027http://www.anycardirect.com/m/index.html\u0027 target\u003d\u0027_blank\u0027\u003e 자세히 보기 \u003c/a\u003e"}]},"errorCode":0}

/////////////////////////////////////////////////////////////////////////////////////

블로그 이미지

요다할아범

,

Use of the testrunner variable to get the response data of any specific teststep.

def request = testRunner.testCase.getTestStepByName( “myTestStepName” );
def responseData = request.getProperty( “Response” );
log.info(responseData.value)

To display the name of project, testsuite, testcase & teststep:

def project = context.testCase.testSuite.project
log.info(project.name + ”   ” + project)
def testSuite = project.getTestSuiteAt(1)  // 1 is the index number of testsuite
log.info(testSuite.name + ”   ” + testSuite)
def testCase = testSuite.getTestCaseAt(0)  // 0 is the index number of testcase
log.info(testCase.name + ”      ” + testCase)
def testStep = testCase.getTestStepAt(7) // 7 is the index number of teststep
log.info(testStep.name + ”    ” + testStep)

To count the number of testsuites, testcases, teststeps use the below code :

def project = context.testCase.testSuite.project
log.info(project.name + ”   ” + project.testSuiteCount)
def testSuite = project.getTestSuiteAt(1)
log.info(testSuite.name + ”   ” + testSuite.testCaseCount)
def testCase = testSuite.getTestCaseAt(0)
log.info(testCase.name + ”      ” + testCase.testStepCount)
def testStep = testCase.getTestStepAt(7)
log.info(testStep.name + ”    ” + testStep)

We can use the above code and put them into a loop (for/each) to iterate through all the elements. In below example, we iterate through all the test steps under a testcase :

for (int count in 0..<testCase.testStepCount)
{
log.info(testCase.getTestStepAt(count).getName() + ”  is our testStep number ” + count)
log.info(“Is this test step disabled? : ” + testCase.getTestStepAt(count).isDisabled())
}

OR

( 0..<testStep1 ).each{ 
    log.info(testCase.getTestStepAt(it).getName())
    }

====================================================

Response Time 

def ResponseTime = messageExchange.response.timeTaken

log.info "Time taken " + ResponseTime + "ms"

====================================================

log.info messageExchange.getRequestContent().toString()

====================================================

블로그 이미지

요다할아범

,