【SoapUI】在soapui中使用Groovy脚本常用方法



1. setPropertyValue
      a. 设置 project level property
        //set to project level property
        testRunner.testCase.testSuite.project.setPropertyValue("Name","propValue");
      b. 设置 testSuite level property
        //set to testSuite level property
        testRunner.testCase.testSuite.setPropertyValue("Name","propValue");
       c. 设置 testCase level property
        //set to testCase level property
        testRunner.testCase.setPropertyValue("Name","propValue");
      d. 设置XML
         def projectDir=context.expand('${projectDir}');
         def InitialXML = FileUtil.file2String(projectDir+"/XXX.xml");
         groovyUtils.setPropertyValue("stepName","Request",InitialXML);
       
2. 定位到某个testSuites
        def testSuite = testRunner.testCase.testSuite.project.testSuites['testSuites Name'];
       
3. getTestCaseCount()
       for(int i=0; i<testSuite.getTestCaseCount(); i++) {
         if (!testSuite.getTestCaseAt(i).isdisabled()) {
         if (!(testSuite.getTestCaseAt(i).getTestStepByName("stepName")).equals()){
       .....
             }
          }
       }
     
4. getTestSuiteCount()
     testRunner.testCase.testSuite.project.getTestSuiteCount()
    
5. getLabel()
        a. 取test case的名称
        def tc = testRunner.testCase;
        log.info (tc.getLabel());
        b. 取test suite的名称
        def ts = testRunner.testCase.testSuite;
        log.info (ts.getLabel());
     
 6. getName()
       去project 名称
       def tp = testRunner.testCase.testSuite.project;
       log.info (tp.getName());
 
7. 声明namespace
       def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
       def getRequest = groovyUtils.getXmlHolder( 'stepName#Request' );
       getRequest.namespaces["ns1"] = "http://...";

8.层级访问
        testRunner.testCase.testSuite.project.testSuites[testSuiteName].testCases[testCaseName].testSteps[testStepName]


备注:资料不错,怕遗忘,共享出来,但忘记出处,非常抱歉 ,请见谅!

相关文章

背景:    8月29日,凌晨4点左右,某服务告警,其中一个...
https://support.smartbear.comeadyapi/docs/soapui/steps/g...
有几个选项可用于执行自定义JMeter脚本并扩展基线JMeter功能...
Scala和Java为静态语言,Groovy为动态语言Scala:函数式编程,...
出处:https://www.jianshu.com/p/ce6f8a1f66f4一、一些内部...
在运行groovy的junit方法时,报了这个错误:java.lang.Excep...