/* 
@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()

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

블로그 이미지

요다할아범

,

※ [] 안에 표시된 명칭이 Visual Studio 2015의 도구-옵션-환경-키보드에서 지정할 위치


Goto implementation(Alt+G) : 함수 원형 및 함수 구현 위치로 보내줌 [편집.정의로이동]

Open H <-> CPP(Alt+O) : .h파일과 .cpp파일 사이를 왔다갔다 하게 해줌 [편집기상황에맞는메뉴.코드창.헤더코드파일전환]

Popup context menu(Shift+오른쪽마우스) : va 확장 메뉴 보여줌

List method in current file(Alt+M) : 현재 파일의 모든 method 리스트를 보여줌

Dlg open file in workspace(Shift+Alt+O) : warkspace에 존재하는 모든 파일 리스트를 보여줌

Back(Alt+Left Arrow) : 브라우져에서처럼 뒤로 돌아가기를 실행한다. [보기.뒤로탐색]

Forward(Alt+Right Arrow) : 브라우져처럼 앞으로 가기를 실행한다. [보기.앞으로탐색]

Paste Multiple(Shift+Ctrl+V) : 멀티플 클립보드 버퍼 내용을 보여주고 paste할 수 있게 한다. 

Find Next(Alt+Shift+F3) : 현재 마우스커서가 가르키고 있는 Symbol을 이후에서 찾는다.

블로그 이미지

요다할아범

,

예전에 사용하던 마우스 포인터 모음

갑자기 생각나서 올려놔본다

이제부터 다시 사용해야지

MacBusy.ani

MacWait.ani

MacWait.cur

MACWAT.ANI

Starcraft Arrow.ani


블로그 이미지

요다할아범

,