首页 文章

SoapUI循环通过TestCases并记录测试用例自定义属性

提问于
浏览
0

我有一个groovy脚本,在每个测试用例中,在项目的每个测试套件中循环遍历每个测试步骤 . 项目中的每个测试用例都分配了两个自定义属性,即 Test_Case_Response_TimeTest_Case_Response_Size . 我试图得到它,以便当它遍历每个测试用例时,log.info为每个测试用例的那两个自定义属性 .

Groovy脚本:

//Loop thru the suites, followed by cases in each suite
suites.each 
{ suite ->
    //For each test SUITE perform the following action
    //------------------------------------------------  
    def tSuite = project.getTestSuiteByName(suite)
    tSuite.testCaseList.each 
    { kase ->
        //For each test CASE perform the following action
        //-----------------------------------------------       
        kase.testStepList.each 
        {
            //For each test step perform the following action
            //-----------------------------------------------       
            if(it.metaClass.hasProperty(it,'assertionStatus')){
                def assertions = it.getAssertionList()
                assertions.each
                { assertion ->
                    if(it.assertionStatus == AssertionStatus.VALID)
                    {
                    PassedTestCase += 1
                    }
                    else if(it.assertionStatus == AssertionStatus.FAILED)
                    {
                    FailedTestCase += 1
                    }
                }
            }
            //-----------------------------------------------

        }
        log.info testRunner.testCase["Test_Case_00: Setup"].getPropertyValue("Test_Case_Response_Time")
        log.info testRunner.testCase.testSuite.getTestCaseByName("Test_Case_00: Setup").getPropertyValue("Test_Case_Response_Time")
        //-----------------------------------------------

    } 
    //-----------------------------------------------

}

我试过以下但没有成功:

log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")

第一行给我以下内容

groovy.lang.MissingPropertyException:没有这样的属性:Test_Case_00:类的设置:com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase错误:37行

第二行给出了以下错误:

java.lang.NullPointerException:无法在行对象上调用null对象上的方法getPropertyValue():37

2 回答

  • 0

    以下语句不正确,因为 testCase[kase.name] 为您提供了testcase的属性而不是testcase本身

    系统正在尝试搜索名为“Test_Case_00:Setup”的属性,因此给出错误“No such property:Test_Case_00:Setup”

    log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")
    

    我能够运行以下代码

    log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
    

    在您的实际代码中,您使用了以下行而不是kase.name

    getTestCaseByName("**Test_Case_00: Setup**")
    

    看起来, testcase 名称有误,请复制确切的名称和粘贴,它会起作用 .

    下面的代码对我有用 . 它只是你的代码 .

    def tSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite") // modified to run
    tSuite.testCaseList.each 
    { kase ->
        //For each test CASE perform the following action
        //-----------------------------------------------       
        kase.testStepList.each 
        {
            //For each test step perform the following action
            //-----------------------------------------------       
    
        }
            //-----------------------------------------------
        // log.info kase.name
    
        // log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")  <-- wrong syntax
        log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
     }
    
  • 0

    我相信我正在寻找错误的测试套件 . 使用以下我能够找到正确的属性:

    testRunner.testCase.testSuite.project.getTestSuiteByName(suite).getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
    

相关问题