Once in a while you might have to create a UFT API test that needs some user input at runtime. Ideally this should be rare, since normally the whole point of automating most tests is to be able to run them overnight unattended.
But, as I've mentioned in the past, sometimes even just automating something halfway to save someone lots of times might make sense. In these instances you need a way to capture a user's input at runtime. One option is to create a popup input dialog to accept user data.
Let's take a look at a quick example.
How to create a InputBox in UFT API
- Create a new UFT API test named UserInput
- Under Toolbox, drag a Miscellaneous>Custom Code method onto the main canvas area.
- From the UFT menu click on the Solution Explorer icon
- Right click on the References options from the Solution Explorer and select Add Reference…
- Under the Add References Dialog select the GAC tab
- Find and click on the reference named Microsoft.VisualBasic
- Click the Select button
- Under the Custom Code's Properties>Events (lightning bold icon) section, select the Create a default handler from the ExecuteEvent handler dropdown field.
- This will bring up the code editor for UFT API. (Tip: Before writing any code make sure to save the test first, because there's a known issue with the auto completion drop down in UFT API's user event code; it often does not reflect changes on the canvas until you perform a Save operation.)
- Place your cursor into the public void CodeActivity#_OnExecuteEvent method and type the following code:
String yourName; yourName = Microsoft.VisualBasic.Interaction.InputBox("Enter Your Name","Name","JOE",-1,-1);
The Input method expects the following info:
(string Prompt, string Title,string DefaultReponse,int XPos, int yPos)
- Save and run the UserInput test – you should see a Name input dialog appear. Cool!
Now What?
There are a few ways you can now work with the user's input value. One way is to create an output value for the Custom Code activity and assign it the input value.
To learn how to do this checkout my Simple Custom Code Example in my wicked affordable book the UFT API Test Manifesto
More UFT API Automation Awesomeness
For more UFT API Automation Awesomeness, tips, tricks and more, check out my new book, The UFT API Testing Manifesto – A step-by-step, hands-on testing guide for the masses, available on Amazon.com!
Don't own a Kindle? No Problem — you can still read my UFT API book!
I'm aware that some of you have had trouble accessing my books in the past. The truth is that you don't need a Kindle! There are a variety of free ways you can read a Kindle eBook:
- Read it on your PC or Mac (Kindle Cloud Reader)
- Read it on your iPhone or iPad (iTunes App)
- Read it on your Android (Kindle for Android)
- Read it on your Blackberry (Kindle for Blackberry)
In short, it's really simple to read Amazon Kindle books, no matter what type of device you use to access the Internet.
The latest version of HP UFT is 12. is there a HP Service Test Standalone version 12, or the latest HP ST Standalone version is the 11.50? Thanks.
Hi Segi – that is a good question. I don’t see ST 12 listed under HP software updates product list. I will ask HP and get back to you. thanks
Hi Joe ,
I have purchased your kindle ediiton , thats awesome book to work on UFT . I got one issue , can you please advice .
I am using UFT 11.5 and ALM 11.52 . When I try to run the test in ALM , we are getting the below error. UFT is installed on the controller .
Error messages from controller are pasted below.
****************************BEGIN ERROR MESSAGE LOG*************************
Error: Failed to compile virtual user.
Error: Checkpoints.cs(17,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(18,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(19,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(20,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(21,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(22,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(23,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(24,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(25,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(26,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Error: Checkpoints.cs(27,11): error CS0246: The type or namespace name ‘HP’ could not be found (are you missing a using directive or an assembly reference?)
Thanks
Praveen
Hi Praveen,
Glad you like this book (a reviews on Amazon would be appreciated :)
I’ve not seen this error before. I did a quick check in HP’s Knowledge base and only found an article with this error for Loadrunner. Looks like the issue was caused by missing folders not being in ALM?
Problem
Error: Failed to compile virtual user
Cause
The script is using some project files(.cs) located in a folder and extra folders are not copied by default when scripts are transferred to Lgens. Thats why script failed to compile