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)
    		}
    	}
    }
    

    执行结果:

  • 相关阅读:
    GUI的最终选择Tkinter模块初级篇
    JavaScript的进阶篇
    html标签详解
    docker使用自定义镜像zabbix服务
    Django之url定义和ORM框架的使用
    zabbix实现企业微信监控报警
    centos6 搭建nginx实现负载均衡
    mysql数据库进阶篇
    Linux运维之Ansible自动化运维管理工具
    php菜刀分析学习
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/4623550.html
Copyright © 2011-2022 走看看