How to Create Custom Code Using Service Test

API Testing Published on:
UFT API Cover

Overview of Creating Service Test Custom Code:

In a previous post (How I cracked HP Service Test’s custom code functionality), I demonstrated the use of the custom code feature in Service Test 11. Due to the recent release of Service Test 11.10, however, this functionality has changed. It seems to be due to some enhancements HP has made in the ST core.

The Custom Code Change:

As a result, the Event Handler code that was used in ST 11.00 is not supported in version 11.10. So, if you have existing custom code in ST 11.00 scripts you’ll need to open them in ST 11.10 and save them. This will modify the code as required and automatically compile it to the correct syntax. If you’re creating new code in ST 11.10, the process of creating input and output variables is still the same; however, the syntax needed to assign a value to the input and output variables has changed.

For example:

Let’s say you wish to create an input variable named joeInput.

To assign a value to an input variable you would use:
Args.Input.joeInput = “Hello”;

But in Service Test 11.10, the proper syntax would be:
This.CodeActivity.Input.joeInput = “Hello”;

The same would apply to output variables as well.

11 responses to “How to Create Custom Code Using Service Test”

    • How I cracked HP Service Test’s custom code functionality — Joe Colantonio — Test Automation Geek | Bibliomaniac | Software Imagineer » Hi Asheena – Sorry I need to update this post to mention that HP changed the syntax for calling input and output parameters. Check out my post UPDATE: Service Test 11.10: How to Create Custom Code using Service Test 11.10 for more info. Basically you need to change the syntax from

      myCounter = args.Input.inCounter;

      To:

      This.CodeActivity.Input.inCounter;

      Let me know if you need more info. Cheers~Joe

  1. Hello Joe,

    Loved your code…
    Is there any way to put auto generated date field for eg,
    I want the code to retrieve current system date and then add 20 days for check in date.

    I just want to know how to add this kinda code.

    Thanks,
    Irfan

  2. The information provided is very useful.

    I have a question. Can we set the value (NIL or Not NIL) of any input parameter of a web service request using the custom code?

    Thanks and Regards,

    Sushil

  3. Hi’

    Can u please explain me the steps to create a reusable custom code in HP Service test.

    I have already tried the steps what u have given u in ur book but it throws error at open Visual Studio Step. Error is Could not able to find denve.exe file”.

    Thanks in advance

  4. Hi Joe,

    Do you have any updates on this for UFT 11.5+? It looks like it’s slightly different now. I never used Service Test previously.

    When I drag over the Custom Code tool to my test area and setup the Input Property it will not let me link to the Read from File. It does not show as an available step.

    Any ideas?

    Thanks!

  5. Hi Joe,

    Do you have any updates on this for UFT 11.5+? It looks like it’s slightly different now. I never used Service Test previously.

    When I drag over the Custom Code tool to my test area and setup the Input Property it will not let me link to the Read from File. It does not show as an available step.

    I think I can just link it to a test input param but not sure if that will work either.

    Any ideas?

    Thanks!

    • I tried to repo — I created a new api test, added Read From File on the main canvas, added a Custom Code activity under it on the main canvas. I clicked on the Custom Code properties and added a Input property.I click on the Input value’s Link to data source. In the Select Link Source for ‘Input’ I’m able to select the Read from File’s Content property. Am I doing anything different then you? I am using UFT 12.01 Build 1112 which is the latest and greatest version

  6. Hi Joe ,

    Your Blog is great. Thank you.

    I am trying to import excel sheet using custem code.How to import excel sheet in HP service test using custom code?

    Regards,
    Anusha

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

UFT API Cover