Forum Discussion

viswaguru3's avatar
viswaguru3
New Contributor
11 years ago

[R]Resource Rest TestRequest Properties using groovy script

Hi

Any one could please help me How to update Resource property in Rest TestRequest Properties using groovy script

Resource Path has aa/bb/dd
update to aa/bb/cc/dd


for Custom properties we have below one (for Tab Rest TestRequest Properties using groovy script how can we can update Resource path )


String[] PropertyNames = testCase.getTestStepAt(i).getPropertyNames()
for( int a=0; a<PropertyNames.length;a++){
alert.showInfoMessage("Hello World.... !"+PropertyNames[a]);

thanks
ven

4 Replies

  • viswaguru3's avatar
    viswaguru3
    New Contributor
    Hi ,

    All Here is solution for changing Resource path

    import com.eviware.soapui.impl.rest.RestResource
    import java.io.*;
    def project = testRunner.testCase.testSuite.getProject()
    String restServiceName = "web-rs-v1.wadl"
    List<RestResource> ops = project.getInterfaces()[restServiceName].getOperationList()
    log.info("ops ::"+ops);

    log.info("ops size ::"+ops.size());

    for (RestResource restResource : ops) {
    String pathStr = restResource.getFullPath();
    log.info("pathStr first-->"+restResource.getFullPath());

    if (!pathStr.contains("AA01"))
    {

    restResource.setPath(pathStr.replace("/web-rs-v1", "/AA01"));

    }
    else if(pathStr.contains("AA01"))
    {

    restResource.setPath(pathStr.replace("/web-rs-v1/AA01", ""));
    }

    log.info("pathStr After-->"+restResource.getFullPath());

    pathStr=null;

    }
    • ktmrock's avatar
      ktmrock
      Occasional Contributor

      This worked for me. Thank you!

  • viswaguru3's avatar
    viswaguru3
    New Contributor
    I tried with below logic to update resource path , value of path gets updated value /web-rs-v1/A01/B01in alert gives me updated value
    but when i run test case/test step it taking old path of resoure=/web-rs-v1/B01" from wadl Any suggestions or views

    String pathStr= testCaseStep.getResourcePath();
    Pathstr="/web-rs-v1/B01"

    alert.showErrorMessage("pathStr-->"+pathStr);
    if (!pathStr.contains("/web-rs-v1/AP01"))
    {
    pathStr=pathStr.replace("web-rs-v1", "web-rs-v1/A01");

    testCaseStep.getRequestStepConfig().setResourcePath(pathStr);
    alert.showErrorMessage("pathStr inside-->"+testCase.getTestStepAt(i).getResourcePath());

    //alert will be /web-rs-v1/A01/B01
    }
  • Any one could please help me How to update Resource property in Rest TestRequest Properties using groovy script