• SoapUI Script Library


    Environment

    Get active environment via groovy script

    log.info testRunner.testCase.testSuite.project.getActiveEnvironment().getName()
    

    Set active environment via groovy script

    testRunner.testCase.testSuite.project.setActiveEnvironment("Live")

    Get request

    Get request header via messageExchange

    def requestID = messageExchange.requestHeaders.get("X-API-RequestId")
    

    Get test step name via messageExchange

    def testStepName = messageExchange.modelItem.name

    Get response

    Get response by testRunner

    def response = testRunner.testCase.testSteps["InitCase"].testRequest.response.contentAsString  
    

    Get response by Context

    // Get response
    String testStepName = "Intraday Table"
    def responseLive = context.expand( '${'+testStepName+'#Response}' )
    

    Get response by messageExchange

    def response = messageExchange.getResponseContent()
    

    Get response header

    def headers = messageExchange.getResponseHeaders()

    Parse XML

    XPath Parse XML : Get node value

    import com.eviware.soapui.support.GroovyUtils
     
     //Get xmlHolder of the xml response
    def groovyUtils = new GroovyUtils( context )
    def xmlHolder = groovyUtils.getXmlHolder( "testStepName#ResponseAsXml" )
     
    //Parse response by XPath
    def data = xmlHolder .getNodeValue("//html[1]/body[1]/text()")
    

    XPath Parse XML : Get nodes list and attributes

    import com.eviware.soapui.support.GroovyUtils
      
    def testStepName = "Intraday Table"
    def XPath = "//B/I/I"
      
    // Get response
    def groovyUtils = new GroovyUtils(context)
    def xmlHolder = groovyUtils.getXmlHolder(testStepName+"#ResponseAsXml")
     
    // Get nodes list
    def nodesArray = xmlHolder.getDomNodes(XPath)
    List nodesList = nodesArray.toList()
      
    for(int i=0;i<nodesList.size();i++){
        def attributes = nodesList.get(i).getAttributes()
        def attributesNumber = attributes.getLength()
    

    XmlParser parse XML : parse xml in json

    import groovy.json.JsonSlurper
      
    def testStepname = "Attribution Detail"
    def responseLive = context.expand( '${'+testStepName+'#Response}' )
      
    def jsonLive = new JsonSlurper().parseText(responseLive)
    String xmlRecordLive = jsonLive.data.data
      
    def xmlParser = new XmlParser()
    def xmlLive = xmlParser.parseText(xmlRecordLive)
      
    def nodesArrayLive = xmlLive.Body.B.I
    List nodesListLive = nodesArrayLive.toList()
    int recordsNumberLive = nodesListLive.size()

    Parse JSON

    JsonPath Parse JSON : Get datas list

    import com.jayway.jsonpath.*
      
    def testStepName = "Holdings Scatter Plot"
    def JPath = '$.Holdings[*]'
      
    def response = context.expand( '${'+testStepName+'#Response}' )
    def datasList = JsonPath.read(response, JPath)
    

    JsonSlurper Parse JSON : Get data

    import groovy.json.JsonSlurper
    // Get response
    def testStepName = "Holdings Scatter Plot"
     
    def response = context.expand( '${'+testStepName+'#Response}' )
    def jsonSlurper = new JsonSlurper().parseText(response)
    def datas = jsonSlurper.data.data
    

    Verify JSON Node's value 

    import groovy.json.JsonSlurper
     
    def response = messageExchange.getResponseContent()
    def json = new JsonSlurper().parseText(response)
    def clientCount = json.pagination.count
     
    assert clientCount>0,"No client"
    

    Get test suite/case/step name

    Get test step, test case and test suite's name

    //  Get test steps' name
    def currentStepIndex = context.currentStepIndex
    String currentStepName = testRunner.testCase.getTestStepAt(currentStepIndex).name
    String previousStepName = testRunner.testCase.getTestStepAt(currentStepIndex-1).name
    String prePreStepName = testRunner.testCase.getTestStepAt(currentStepIndex-2).name
     
    // Get test case and test suite's name
    String testCaseName = testRunner.testCase.getTestStepAt(currentStepIndex).getParent().getName()
    String testSuiteName = testRunner.testCase.getTestStepAt(currentStepIndex).getParent().getParent().getName()

    Get property

    Get property value by testRunner

    String testResultPath = testRunner.testCase.testSuite.project.getPropertyValue( "testResultPath" )
    

    Get property value by context

    String dataDeviationFile = context.expand( '${#Project#dataDeviationFile}' )

    Set property

    Set property value by testRunner

    testRunner.testCase.testSuite.project.setPropertyValue( "cookie", cookieNew )

    Control flow

    Goto test step by name

    testRunner.gotoStepByName("Copy File")
  • 相关阅读:
    Javaweb之 servlet 开发具体解释1
    struts2_6_多个struts配置文件的应用
    PHP多种序列化/反序列化的方法
    CF459C Pashmak and Buses 打印全排列
    HDOJ 题目3564 Another LIS(线段树单点更新,LIS)
    Android UI开发第四十三篇——使用Property Animation实现墨迹天气3.0引导界面及动画实现
    [ACM] HDU 1533 Going Home (二分图最小权匹配,KM算法)
    POJ 3895 Cycles of Lanes (dfs)
    【iOS开发-51】案例学习:动画新写法、删除子视图、视图顺序、延迟方法、button多功能使用方法及icon图标和启动页设置
    iOS-代理托付的使用
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/7097988.html
Copyright © 2020-2023  润新知