【问题标题】:SoapUI: Have a separate Test Suite that runs a GroovyScript TestStep that checks all other Test Cases In other Test Suites?SoapUI:有一个单独的测试套件,它运行一个检查其他测试套件中所有其他测试用例的 GroovyScript TestStep?
【发布时间】:2016-10-25 20:52:51
【问题描述】:

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

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

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

此测试套件的唯一目的是运行常规测试步骤,该步骤读取所有其他测试套件和测试用例、测试步骤并记录失败的测试步骤。

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 中是否可行。

【问题讨论】:

    标签: groovy soapui


    【解决方案1】:

    这里是Groovy Script,它会遍历除当前套件之外的所有套件,因为您的情况不需要它。
    请遵循在线 cmets。

    /**
     * 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
            }       
        }   
    }
    

    【讨论】:

    • 我收到一个错误:groovy.lang.MissingPropertyException: No such property:testCaseList for class: java.lang.String error at line:17
    • @Ross,请检查更新后的答案。你是真的,有一些东西丢失了,并修复了它。感谢您的尝试。
    • 很高兴知道这很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 2016-11-07
    相关资源
    最近更新 更多