zoukankan      html  css  js  c++  java
  • [SoapUI] 获取Cookie,并循环遍历当前Project下所有的Test Suite,Test Case,Test Step,将Cookie传递给这些Test Step

    import com.eviware.soapui.support.types.StringToStringMap
    
     //Get all th cookies in the response , here the test step name is provided
    def cookiesList = testRunner.testCase.getTestStepByName("Login").testRequest.response.responseHeaders["Set-Cookie"]
    log.info cookiesList
    
    //Get the second cookie, only this one is must for PA API testing
    String cookieNew = cookiesList.get(1)
    log.info "cookie : "+cookieNew
    
    // Set the project level property : cookie , its value will updated with cookieNew
    testRunner.testCase.testSuite.project.setPropertyValue( "cookie", cookieNew )
    
    //Put cookie to a StringMap
    def cookieMap = new StringToStringMap()
    cookieMap.put("Cookie",cookieNew)
    
    def testSuiteList =  testRunner.testCase.testSuite.project.getTestSuiteList()
    def testCaseList
    def testStepList
    for(testSuite in testSuiteList){
    	log.info "Test suite number : "+testSuiteList.size()
    	testCaseList =  testSuite.getTestCaseList()
    	for(testCase in testCaseList){
    		log.info "Test case number : "+testCaseList.size()
    		testStepList = testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.class)
    		log.info "Test step number : "+testStepList.size()
    		for (testStep in testStepList){
    			log.info "Pass cookie to  test step : "+testStep.name
    			testStep.testRequest.setRequestHeaders(cookieMap)
    		}
    	}
    }
    

    执行结果:

  • 相关阅读:
    git, tornado 小计
    算法小计-列表排列
    CMDB小计1
    linux 中mysql的主从复制
    SQL语句的种类
    mysql的结构,段页区,及客户端命令
    mysql的程序结构,实例, 及mysql的多实例
    在linux中操作mysql误删root用户的应对方法
    MySQL面试
    linux下载安装mysal
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/4623550.html
Copyright © 2011-2022 走看看