SoapUI:有一个运行GroovyScript TestStep的独立测试套件,可以检查其他测试套件中的所有其他测试用例吗?

时间:2016-10-25 11:56:34

标签: groovy soapui

我有一个Groovy脚本,它读取在当前测试用例中运行的测试步骤的断言验证和错误消息。

我目前有4个测试套件,8个测试用例,全部有大约400个测试步骤。

是否可以拥有一个单独的Test Suite,其中包含一个测试用例和一个包含groovy脚本的测试步骤?

此测试套件的唯一目的是运行groovy测试步骤,该步骤读取所有其他Test Suite以及测试用例,测试步骤并记录失败的测试步骤。

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus

def TestSuite = testRunner.getTestCase()
def StepList = TestSuite.getTestStepList()

Failed = 0
Total = 0

log.info "_____Start of Log_____"

// psuedo code
// SuiteList.each
// CaseList.each

StepList.each
    {
        if(it.metaClass.hasProperty(it,'assertionStatus')){
            Total = Total + 1
            def assertions = it.getAssertionList()
            assertions.each
            { assertion ->
                if(it.assertionStatus == AssertionStatus.FAILED)
                {
                    assertion.getErrors().each
                    { error ->
                        log.error "${it.name}: [FAILED] ${error.getMessage()}"
                    }
                    Failed = Failed + 1
                }
            }               
        }   
    }
log.info " Script Run: " + Total
log.info " Scripts Failed: " + Failed
log.info "_____End of Log_____"

目前我的输出是:

Tue Oct 25 12:55:20 BST 2016:ERROR:TestStep_0299: [FAILED] Expected Result: 49.401 or 52.002 or 54.602 Actual Result: 41.60164055168. Expression: node.toString().matches((49.401|52.002|54.602)\d*)
Tue Oct 25 12:55:20 BST 2016:ERROR:TestStep_0300: [FAILED] Expected Result: 61.752 or 65.002 or 68.252 Actual Result: 52.0020506896. Expression: node.toString().matches((61.752|65.002|68.252)\d*)
Tue Oct 25 12:55:20 BST 2016:INFO: Script Run: 300
Tue Oct 25 12:55:20 BST 2016:INFO: Scripts Failed: 205
Tue Oct 25 12:55:20 BST 2016:INFO:_____End of Log_____

是否可以为所有测试套件和测试用例运行此操作。所以我有一个所有测试步骤的大日志。

这在SoapUI中是否可行。

1 个答案:

答案 0 :(得分:1)

这是Groovy Script循环通过除当前套件之外的所有套件,因为在您的情况下不需要它。
请按照在线评论进行操作。

/**
 * This script gets all the suites and 
 * removes current suite name from total list
 * and loopes thru the test cases of each suite
 **/

//Get the project object
def project = context.testCase.testSuite.project

//Get the current suite name
def currentSuite = context.testCase.testSuite.name

//Get the suites to process (except the current suite)
def suites = project.testSuiteList.findAll {it}*.name - currentSuite

//Loop thru the suites, followed by cases in each suite
suites.each { suite ->
    def tSuite = project.getTestSuiteByName(suite)
    tSuite.testCaseList.each { kase ->
        kase.testStepList.each {
            //Have your code here
        }       
    }   
}