• Home  / 
  • ST
  •  /  How I cracked HP Service Test’s custom code functionality

How I cracked HP Service Test’s custom code functionality

UPDATE: HP has changed the syntax for input and output variables in ST 11.10. Check out UPDATE: Service Test 11.10: How to Create Custom Code using Service Test 11.10 for more info.

HP’s documentation on Service Test custom code functionality is pretty slight. Reading the user guide I was unable to find an exact example of how to pass data to and from my custom code. The key to cracking the custom code feature is to become familiar with the args object, as well as two of its properties: Input and Output.

These two properties are what you need to use in order to pass value to and from ST’s custom code. So — to assign a value to a input variable that you created, you need to use the following statement:

args.Input.theNameOfYourInputVariable;

And to assign a value to a variable for later use in your script, you would use:

args.Output.theNameOfYourOutputVariable;

The easiest way for me to learn something is to do it. The following is a small example I came up with to help me understand how to use Service Test’s custom code Feature:

1. Create a text file on your local drive called myCounter.txt

2. Open the text file and add the value of 100. Save and Close.

3. Open Service Test 11

4. Under ST’s ToolBar, navigate to the File System folder. Drag the ‘Read from File” objects onto your test’s main canvas area.

ST11 read from file

 

 

 

 

 

 

 

 

 

5. Go to the Custom Code’s property sheet and click on the “test input parameters” button (The Step Icon).

6. Point your File path to the location of the myCounter.txt file. Set “Encoding” to Automatic

7. Go to the Miscellaneous folder under ST’s Toolbox section, and drag the Custom Code on to your test’s canvas area.
Service Test Custom Code Menu

 

 

 

 

 

8. Go to the Custom Code’s property sheet and click on the “test input parameters” button (The Step Icon).

9. Click on the “Add Property” button (The + icon) and select the “Add Input Property” option from the menu

10. In the Add Input Property, enter the following:

Type = int<br /> Name = inCounter<br /> Description = counter example

In Counter in Service Test

 

 

 

 

 

11. Click OK (You should now have a value called inCounter located under the Input\Properties section).

12. For the inCounter value, point the Read From File’s ‘Content’ value (this will contain the value that is read from the myCounter.txt file)

13. Click on the Add Property button (The + icon) and select “Add
Output Property” option from the menu.

14. In the Add Output Property fill out the following:

 Type = int<br /> Name = outCount<br /> Description = Adds 1 to the current count<br />

Out Property Service Test 11

 

 

 

 

 

15. Click OK (your Custom Code’s property sheet should now have the following:

 

Service Test Param

 

 

 

 

 

 

 

 

 

16. In the Custom Code’s property sheet, click on the “Events”
(thunderbolt) button.

17. Click on “ExecuteEvent” and select Create a
default handler.

18. A SharedUserCode window should appears in ST. Click on it, then
navigate to the CodeActivity_OnExecuteEvent section and add the following code:

<br /> into myCounter:<br /> myCounter = args.Input.inCounter;<br /> myCounter = myCounter + 1;<br /> args.Output.outCounter = myCounter;

Service Test Custom Code Menu

 

 

 

 

 

19. Go to the “String Manipulation” folder under ST’s Toolbox section
and drag the ‘Concatenate Strings’ object onto your test’s canvas area
under the Custom Code.

20. Go to the “Concatenate Strings” property sheet and click on the
“test input parameters” button (the Step Icon), and fill out the following info:

 Prefix = The current counter number<br /> Suffix = click on ‘link to data source’ and point to the Previous<br /> Step Custom Code’s outCounter

21. Run the script.

22. The test should pass with the following Output:

Step 'Concatenate Strings6': Output Parameter 'Result', Value: 'The<br /> current counter number=101'<br /> Step 'Concatenate Strings6' ended successfully

ST11 results

 

 

 

I know this example was simplistic, but by using these same steps, you should be well on your way to creating your own Custom Code script masterpiece.

Succeeding with Automation Awesomeness. I’ll show you how!

Test automation, like all development efforts, is difficult. Most projects don't succeed. You can do better! Sign up and receive exclusive content like my free 10 Proven Actionable Steps for Automation Awesomeness from some of the biggest testing leaders in the industry. Let me help YOU succeed with Test Automation! Sign up now:

28 comments
Click here to add a comment

Optin Architect