Automation Testing

UFT API – How to Get a User’s Input at RunTime using an InputBox

By Test Guild
  • Share:
Join the Guild for FREE

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.

A bearded man with blue glasses and a black-and-white jacket smiles at a microphone in a studio setting.

About Joe Colantonio

Joe Colantonio is the founder of TestGuild, an industry-leading platform for automation testing and software testing tools. With over 25 years of hands-on experience, he has worked with top enterprise companies, helped develop early test automation tools and frameworks, and runs the largest online automation testing conference, Automation Guild.

Joe is also the author of Automation Awesomeness: 260 Actionable Affirmations To Improve Your QA & Automation Testing Skills and the host of the TestGuild podcast, which he has released weekly since 2014, making it the longest-running podcast dedicated to automation testing. Over the years, he has interviewed top thought leaders in DevOps, AI-driven test automation, and software quality, shaping the conversation in the industry.

With a reach of over 400,000 across his YouTube channel, LinkedIn, email list, and other social channels, Joe’s insights impact thousands of testers and engineers worldwide.

He has worked with some of the top companies in software testing and automation, including Tricentis, Keysight, Applitools, and BrowserStack, as sponsors and partners, helping them connect with the right audience in the automation testing space.

Follow him on LinkedIn or check out more at TestGuild.com.

  1. 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.

  2. 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

  3. 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

  4. 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

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

30 AI Terms Every Tester Should Know

Posted on 04/24/2025

Why This AI/ML List Matters to You (and Your Testing Career) AI and ...

5 Top Model Context Protocol Automation Tools (MCP Guide 2025)

Posted on 04/09/2025

What is Model Context Protocol (MCP) Model Context Protocol (MCP) is an open ...

What is TDD (Test Driven Development)

Posted on 04/05/2025

What is Test-Driven Development (TDD)? Test-Driven Development is a software development approach that ...