7.4 Generic Actions Connector

The Generic Actions Connector provides some general purpose tools that can be used within tests. These include the ability to evaluate XPath and Javascript expressions, as well as a date calculator and converter.

See the Generic Connector Starter test for samples.

  • Javascript - Executing Javascript in an action consists of two parts:

    1. Javascript Library - (Optional) Specify your own Javascript functions.

    2. Under the Test Suite tab, create your own Javascript Library with any function you wish touse in your tests.

      NOTE:To assist in debugging the script, use console.log() to output messages to the Identity Validator console.

      Using custom Java libraries:

      For non-static methods: In the Javascript Library create a function to instantiate the class and call your custom method:

      function myFunc() {var myObj = new MyCustomClass();return myObj.myMethod();}

      Then use the directive to call the library function:

      js:{myFunc()}

    3. Use a Javascript directive in any text field in an action.

      A JavaScript directive is in the form: js:{expression} and can be used in any text field within an action.

      NOTE:Javascript directives cannot be used in Variable values defined in the Variables editor, nor can they be used when defining connection properties. They can only be used in test Actions.

      The result value of the directive will replace the directive itself. In other words if you do the following in an attribute value field:

      js:{"${User Last Name}".substring(0,2)} 

      it will first replace the variable “User Last Name” with the value of the variable.

      js:("Johnson".substring(0,2)}

      It will then evaluate the Javascript expression and replace the directive with the result, which is the first two characters of the variable value.

      IMPORTANT:The variable replacement process in the parameters to a Javascript function is similar to a text replace function. This means you must use quotes around the variable tokens if you need them treated as strings as shown in the ${User Last Name} example above. If the variable value is a string and quotes are not used a typical error might be: “missing ; before statement”

      Example:

        js:{ myFunc("${User Last Name}") }

      Quotation mark (“) need not be used if the value needs to be treated as a number or a Json object.

      Examples:

      js:{ myFunc(${Json Object})  }
      js:{ myFunc(${My Number}) }
  • JSON - Parsing JSON variables can be done in Javascript (see the Javascript section above), or by using the Parse JSON and Set Variable action in the Generic Actions connector.

    The JSON Expression is Javascript syntax to access data in a JSON variable.

    For example, consider the following JSON which is in a variable:

    {
      "person": {
    
        "first_name":"John",
    
        "last_name":"Smith"
    
      }
    
    }

    To access the person’s first name the JSON expression would be:

    person.first_name

    Or

    person["first_name"]

  • XPath - You can use XPath to parse XML documents such as entitlement values, etc.

    For example, you have a variable that contains an XML document and you want to retrieve the text value of the “name” element somewhere within the document. The XPath expression would be: //name

    NOTE:The leading // means to traverse the document until you find an element called “name”.

    If you want to retrieve an attribute of an element (e.g. age), the XPath statement would be something like: //person/@age

    Default Namespace Issues

    When an XML document has a default namespace (xmlns=...), XPath statements in the Linux version will not work if you are referencing nodes within that default namespace.

    Consider the following XML:

    <mydoc xmlns="http://mydefaultnamespace">
      <person>
        <name>Bob</name>
      </person>
    </mydoc>

    Note that a default namespace (a namespace without a suffix) has been defined in the “mydoc” element and affects all elements below mydoc. One would expect the following XPath expression to access “name”:

      //person/name

This will work on Windows but will not work on Linux because of differences in the Java XML libraries. To make this work on Linux you must modify your XPath statement to the following:

  //*[local-name()="person"]/*[local-name()="name"]

This statement forces the XPath processor to examine the element name without considering the namespace.

  • Calculate Variable - Append and manipulate a counter at the end of a variable

    Oftentimes you may want to increment a counter at the end of a username to create unique CN’s for objects. This action allows you to do just that.

    Let’s say you have a username of “TestUser” and you want a counter appended to it. You would use the Calculate Variable action and provide a counter Value of 1. The first time it is called it will return the value of “TestUser1”. The next time you call it, the return value would be “TestUser2”, etc. You can provide a positive or negative Value to add or subtract to/from the appended number.

  • Calculate Date - Provides a date calculator and date format converter

    This action allows you to get todays date or use a variable that contains a date, perform math on it (add or subtract minutes, hours, days, months, etc.) then place the result in a variable in any form you wish.