zoukankan      html  css  js  c++  java
  • SoapUI中Groovy的实用方法

    1.依照上次结果判断下步是否执行:

    import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
    
    myTestStepResult = testRunner.runTestStepByName("Verify Step one")
    myStatus = myTestStepResult.getStatus(
                         if( myStatus ==TestStepStatus.OK)
                         ** execute the next testRunnerStep **

    2.获取到Assert的结果:

    def iAssertionName = assertionNameList[j]
    def iAssertionStatus = testStep.getAssertionAt(j).getStatus().toString()
    def tstep = testStep.getName()
    def gStatus =  testStep.getAssertionAt(j).status
    def expect = testStep.getAssertionAt(j).getToken()
    log.info "Expected Content: " + expect

    3.清空property

    def datasink = testCase.testSteps["DataSink"]
    
    String[] props = new String[datasink.getPropertyCount()]
    props = datasink.getPropertyNames();
    
    for (int i=0;i<props.size();i++)
    {
        datasink.setPropertyValue(props[i],"")
    }

    4.从test step中获取到结果

    import com.eviware.soapui.model.testsuite.*
    import com.eviware.soapui.impl.wsdl.teststeps.*
    
    def suiteRunner = (TestSuiteRunner) runner.getRunContext().getTestRunner()
    def listResults = suiteRunner.getResults()
    for (TestCaseRunner run : listResults){
        def stepResults = run.getResults();
        for(TestStepResult step : stepResults){
            if(!step.getStatus().toString().equals("OK")){
                def local = step.getTestStep()
                def caseName = local.getTestCase().getName();
                def modalItem = local.getModelItem() 
                log.info modalItem
                if (modalItem instanceof JdbcRequestTestStep){
                    log.error "TestCase " + caseName + " step " + local.getName() + " failed"
                    log.error "JDBC step failed, query was: " + local.getQuery() 
                    log.error "Response content:" + local.getResponseContent() 
                }
                if(modalItem instanceof WsdlTestRequestStep){
                    log.error "TestCase " + caseName + " step " + local.getName() + " failed"
                    log.error "Request: " + modalItem.getTestRequest().getResponse().getRequest().getRequestContent()
                    log.error "Response: " + modalItem.getTestRequest().getResponse().getContentAsXml()         
                }       
                if(modalItem instanceof WsdlRunTestCaseTestStep){
                    log.error "TestCase " + caseName + " step " + local.getName() + " failed"
                    def target = local.getTargetTestCase()              
                }
            }

    5. 使用context

    def myVar = context.expand( ‘${#TestCase#SourceTestStep}’) //expand TestCase property value into the new variable
    context.testCase  // returns the current testCase handle
    context.expand( '${QuerySubsPlanList - Request 1#Response#//count(*:QuerySubsPlanListResponse[1]/SubsPlanDtoList[1]/SubsPlanDto)}')

    for ( i in 1..numElements.toInteger()) {
        collection2.add(context.expand( '${QuerySubsPlanList - Request 1#Response#//*:QuerySubsPlanListResponse[1]/SubsPlanDtoList[1]/SubsPlanDto['+ i + ']/SubsPlanCode[1]}'))
    }

    6. 获取TestRunner的参数

    testRunner.testCase.getTestStepByName(“TestStepName”)
    testRunner.testCase 
    testRunner.testCase.testSuite.project.testSuites[“My_TestSuite”]

    7. 转换String和Integer

    anyStringVar = anyIntegerVar.toString()
    anyIntegerVar = anyStringVar.toInteger()

    8. 获取到project,testsuite,testcase,teststep

    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”)
  • 相关阅读:
    Python PEP8 编码规范中文版
    MySQL分区表
    mybatis缓存,包含一级缓存与二级缓存,包括ehcache二级缓存
    斐讯K2刷不死breed与第三方固件教程
    Mysql 多表连接查询 inner join 和 outer join 的使用
    mysql多表关联删除示例
    sublime Text 几款插件
    多进程vs多线程
    git 命令常用总结
    LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
  • 原文地址:https://www.cnblogs.com/goldenRazor/p/4850701.html
Copyright © 2011-2022 走看看