1. 程式人生 > >【SoapUI】在soapui中使用Groovy指令碼常用方法

【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://...";