Forum Discussion

venkateshAousul's avatar
venkateshAousul
New Contributor
8 years ago

How to set the resource path at run time while creating a test case using groovy script ?

  • nmrao's avatar
    nmrao
    Champion Level 3
    More details would be helpful on what exactly you would be needed?
    • venkateshAousul's avatar
      venkateshAousul
      New Contributor

      Hi Rao,

       

      our project had a requirement, where we need to create the testsuite and test cases using groovy script.

      In that case we have created 2 interfaces one for the old API and other for the new API. each test case contains the first API and second api rest steps and followed by a groovy script to compare.

       

      Now the problem is we need set the resource path dynamically by reading it from excel.When I try with the below code which has been suggested by you,  then following error message has been thrown: "ERROR:groovy.lang.MissingPropertyException: No such property: submit for class".

       

      Please help me in setting the resource path and query parameters dynamically. Do I need to place any jars ??

       

       

      Code for reference:

       

      RestRequestStepFactory rest = new RestRequestStepFactory()
      def restServiceConfig = RestServiceConfig.Factory.newInstance()

      restServiceConfig.setType("restrequest")
      RestService restService = project.getInterfaceList()[0]

      RestResource resource = restService.getOperationAt( 0 );

      RestRequest request = resource.getRequestAt( 0 );
      submit.request.setPath(uri1)
      TestStepConfig testStepConfig = RestRequestStepFactory.createConfig(request, d[3] );
      def teststep = tc.addTestStep(testStepConfig)
      teststep.setDisabled(true)

       

      Note Here d[3] is the cell value which reads from the excel sheet, similarly uri1 is assigned by the cell value d[0]

       

      Regards,

      Venkatesh