如何以编程方式创建重新请求步骤?

How to create a restrequest step programmatically?

我目前正在尝试以编程方式构建测试用例。

来自输入 swagger 的每个新资源都必须有对应的测试用例。

我设法检测到哪个资源没有 testCase,我可以创建 testCase,但是当它要创建 testStep 时我遇到了问题。

我目前正在进行以下流程:

import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory

 // create the test case
 tc = current_suite.addNewTestCase(resource) 
 // add a restrequest step
 log.info tc.getClass()
 
 tc.addTestStep(RestRequestStepFactory.RESTREQUEST_TYPE , "Request 1" )

这几乎行得通!但是当它到达 testStep 创建时,我在 readyAPI 中弹出 "New RestRequest" 打开要求我 'select existing request or REST method, or create a new request'.

如何以编程方式执行此步骤?

感谢您的帮助

亚历克斯

我找到了如何进行。事实上,我想自动创建一个带有 testStep 的 testCase,该 testCase 是从使用我的 swagger 输入文件的新版本更新的资源中自动创建的。我进行如下: 我得到了资源列表:

restServiceList = testRunner.testCase.testSuite.project.getInterfaceList()

从每个资源中,我得到它包含的 API 个列表:

    restServiceList.each{
    inter -> 
    inter.each{
        // pour chaque bloc de ressources, on va recuperer la liste des API exposees
        ops = it.getOperationList()
        found = false
        ops.find(){
            // on compare le nom de l'API on nom du test - si ca matche, on sort
            //log.info it.getName()

            if(it.getName() == tc.getName())
            {
                // API trouvee, on recupere la liste des requetes
                reqList = it.getRequestList()
                found = true
            }
        }
    }
}

对于每个 API 请求,我创建相应的 testStep

    reqList.each{
    restRequest ->
    testStepConfig = RestRequestStepFactory.createConfig( restRequest, tc.getName() );
    testStepConfig.setName("Request 1") // Attention, voir ce que ca donne sur une resource multiple !

    // log.info "testStepConfig = " + testStepConfig.toString()
    // ajout du step dans le testCase
    tc.addTestStep( testStepConfig )}

此外,我创建了与请求参数相关的自定义属性(因为我的 API 具有通用参数)

def requestParameters = testStepConfig.config.restRequest.parameters.entryList ...

这个效果很好。