Forum Discussion

stman's avatar
stman
New Contributor
2 years ago

Brackets in scripting in soapui.

Hi,

I'm following a series of lessons in SoapUI. I'm in scripting for automation and what I miss are the brackets. The instructor uses brackets and square brackets. I have no clue when to use which. Does anyone know more specifically where I can look for information?

 

Thanks

  • Hi,

    Would you mind giving a little more detail or at least a specific example?

     

    When there are brackets, it typically indicates a method on a class.  E.g. myObj,toString() where toString is a parameter-less method.  You may also need to pass in parameters to a method.  For example log.info() expects you to 'pass' in a message.  E.g. log.info("Hello World")

    Where there are square brackets, that typically indicates an element within an list, array, collection.

    You tend to put a number inside the square brackets which says which row you're interested in.  E.g.

     

    var animal = animals[0];  // Gives the animal in the first (first because lists are zero-index based) row.

     

    Typically, you'd actually put a variable inside the square brackets...

    Note, the below is purely for illustration and probably won't be syntactically correct.

     

    for (i = 0; i < animals.size; i++) {

        var currentAnimal = animals[i];  // Get the animal at position i based on our loop.

        log.info(currentAnimal);

    }

     

     

     

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

    Would you mind giving a little more detail or at least a specific example?

     

    When there are brackets, it typically indicates a method on a class.  E.g. myObj,toString() where toString is a parameter-less method.  You may also need to pass in parameters to a method.  For example log.info() expects you to 'pass' in a message.  E.g. log.info("Hello World")

    Where there are square brackets, that typically indicates an element within an list, array, collection.

    You tend to put a number inside the square brackets which says which row you're interested in.  E.g.

     

    var animal = animals[0];  // Gives the animal in the first (first because lists are zero-index based) row.

     

    Typically, you'd actually put a variable inside the square brackets...

    Note, the below is purely for illustration and probably won't be syntactically correct.

     

    for (i = 0; i < animals.size; i++) {

        var currentAnimal = animals[i];  // Get the animal at position i based on our loop.

        log.info(currentAnimal);

    }

     

     

     

    • stman's avatar
      stman
      New Contributor

      In the example below there is one scenario with aquare bracket and in the getPropertyValue there is normal bracket.

      testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"].getPropertyValue("Request")

       

      • ChrisAdams's avatar
        ChrisAdams
        Champion Level 3

        This references a test case by name.  In this case, the test case is called GetEmployee

        testRunner.testCase.testSuite.testCases["GetEmployee"]

         I'm assuming the GetEmployee test case has a test step called "get".

        .testSteps["get"]

        So far, we've 'grabbed' a hold of the test step called "get"

        testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"]

        The square brackets so far have been used to get an element in the array by name.  My early note mentioned square brackets indicate a list of some sort and my example used a number to reference the element of interest.  Here, SmartBear are doing the same, but by name.  If you think about the GetEmployee test case, there will be a series of steps that you could reference by number, but this is 'by name'.

        The test step class has lots of methods.  One being 'getPropertyValue'.  This method requires a parameter passed-in.  In this case, the example is aiming to get the test steps property value named "Request".