How to pass UFT test parameter values from Jenkins

In this post we will discuss about passing the UFT test parameters from Jenkins jobs.

Introduction

UFT test parameters are used to pass the useful information required for executing the tests, when running the UFT using different technologies like .Net or VBA. Jenkins plugin “HP automation tools”, uses the same automation object model for executing the tests. Some times it’s required to pass dynamic information to the tests to execute the same test with different parameters. One of the easy examples is user id/password for executing the tests. Most of the applications require Login and we will have to pass user id and password for it. Now this can be stored directly into the test, but if you have several hundred tests it will be very had to update these passwords every couple of months.

One of the ways to resolve this issue is to create the parameters in UFT.

In this article we will discuss in detail about how to create the parameters in UFT, how to use parameters and how to pass these parameters from Jenkins.

Creating test parameters in UFT

For creating the test parameters in UFT, open any test and click on view->Test flow.

Once the test flow is open, click on Start and open the properties window from view->properties.

Click on parameters tab and add one sample parameter.


Once test parameter is created you can access the test parameter by using

TestArgs(“”WhatToSearch)

Now, I don’t like to use it as test parameters, but what I do with my tests is, create the action parameters and map the values to the action parameters. This will give me more segregation about what parameters are for what actions.

So let’s see how to create action parameters and map them to test parameters.

Creating action parameters in UFT

Its, very similar to creating test parameters, the only difference is that we click on the particular action instead of start.

Once you have the action parameters created, now right click on the action and select Action call properties.

Select parameter values tab and click on configure the values tab.


In the value configuration window, select the parameter radio button, then select test/action parameter in the dropdown, then select test parameters radio button and select the test parameter(in this case “WhatToSearch”). Click ok.


Once you have this setup complete, your values will flow down from test parameters to the action parameters and you can use the values in the test as follows

Parameter.Item(“GoogleTest”)

I have the following code in the UFT test for searching on google, by using the parameter values from action

SystemUtil.Run “iexplore.exe”, “http://www.google.com”

Browser(“Google”).Page(“Google”).WebEdit(“Search”).Submit

Browser(“Google”).Page(“Google”).WebEdit(“Search”).Set Parameter.Item(“GoogleTest”)

Browser(“Google”).Close

Now you have the completed setup in UFT, we can proceed with the Jenkins configuration.


Steps for passing the parameters to Jenkins

  1. Create the MTBX file (this is different from mtb file used by test batch runner), and define the sequence of tests to be executed.
  2. Update the test path to MTBX file path.
  3. Execute the Jenkins jobs.

How to create MTBX file and execute tests with parameters

MTBX file is an XML file, where we have to provide the path for the tests and test parameters. The structure of the MTBX file is as follows

<Mtbx>
<Test name="test1" path="c:\test1\test1foldername">
<Parameter name="Param1" value="value1" type="string"/>
</Test>
<Test name="test2" path="${WORKSPACE}\test2">
<Parameter name="param1" value="12345" type="int"/>
<Parameter name="param2" value="123.45" type="float"/>
</Test>
</Mtbx>

In the above MTBX file, we are instructing the Jenkins to execute two tests.

First test is having the path “C:\test1\testfoldername” and it has one test parameter value to be passed. Test parameter name defined in UFT is “Param1” and the value we are passing is “Value1”. We also have to define the type of the parameter which should also be defined in UFT.

Second test is stored in the Jenkins workspace path and test folder name within the workspace is test2. We have two parameters defined in UFT test parameters as “param1” and “param2” and we are passing values 12345 and 123.45 to the test parameters.

Note: Remember path should have the complete path of the test. If you open the path in the windows folder you should directly see the Action0 folder of the test.

MTBX file for the above example will look like this

<Mtbx>
    <Test name="GUITest1" path="C:\Users\kushwah_s\Desktop\TEST\GUITest1">
    <Parameter name="WhatToSearch" value="This is jenkins test 1" type="string"/>
    </Test>
    <Test name="GUITest1" path="C:\Users\kushwah_s\Desktop\TEST\GUITest1">
    <Parameter name="WhatToSearch" value="This is jenkins test 2" type="string"/>
    </Test>
</Mtbx>

I am calling the same test with different parameter values.

Once you have the MTBX file created, you can replace the test case path with the MTBX file path in the Jenkins job.

Once, we have this setup complete you can execute the test and the parameters will be available in UFT. You will see the below results in Jenkins

Let me know, if you have any questions.

Thanks,
Sumeet Singh Kushwah

Advertisements

30 responses to “How to pass UFT test parameter values from Jenkins

  1. Sumeet,
    Hopefully I can call upon you again.

    I have a UFT test, and it has one Action parameter defined -> “PLIenv”.

    I have a Jenkins job that invokes an MTBX.
    C:\PLI_UFT_Smoke_Test_v2\MTBX\QA1.mtbx

    The script is located under:
    C:\PLI_UFT_Smoke_Test_v2

    The MTBX files is located under
    C:\PLI_UFT_Smoke_Test_v2\MTBX\QA1.mtbx

    The MTBX file is as follows:

    But when I run the test, the parameter value from the MTBX is not being passed. For example, a simple MsgBox at the front of the script confirms that the PLIenv parameter is empty.

    MsgBox Parameter(“PLIenv”).

    Whereas, if I run the test directly within UFT and provide default parameter value at runtime, then this default value does come into the script.

    The MTBX file looks to be in order, and the UFT action parameter is correctly defined.

    Do you have any idea why this is not working?

    Thank You.

    Jim

    Like

  2. Sumeet,

    I’m also facing the same problem that is addressed by Jim. I see the build parameters in the props####.txt file but not able to fetch the values to input parameters. Below is my mtbx looks like. I tried replacing envVar with actual value that also didn’t work. Wondering if you guys able to fix this.

    TIA
    Kamal

    Like

  3. Can I use parameter in MTBX file? it not works for me, but replace the ‘$URL’ with string value, it works. e.g:
    Parameter name=”URL” value=”$URL” type=”string” — Not work
    Parameter name=”URL” value=”http://www.baidu.com” type=”string” — works well

    Liked by 1 person

  4. Hi Sumeet,

    You have a very nice blog here.

    I have been trying to execute a .mtbx file from jenkins. However it doesn’t seem to know what to do with the file.

    Currently when I build the jenkins job, it runs and open the .mtbx file which just sits there with the mtbx file opened in notepad.

    Jenkins console reads:
    [EnvInject] – Loading node environment variables.
    Building remotely on UFT_Test_VM41 in workspace C:\Jenkins\workspace\archive\Test_Folder\Test_Alpha
    [Test_Alpha] $ cmd /c call C:\Users\ADMINI~1\AppData\Local\Temp\2\hudson6441668918970821737.bat

    C:\Jenkins\workspace\archive\Test_Folder\Test_Alpha>C:\driver.mtbx
    C:\Jenkins\workspace\archive\Test_Folder\Test_Alpha>exit 0

    My mtbx file is called driver.mtbx and the content is:

    ….

    ….

    What am i doing wrong?

    Thank you in advance

    Like

    • I have attempted this on another VM and Jenkins is running and on the tests machine has opened the file which displays a “Windows can’t open this file” dialog box.

      Seems like it doesn’t recognize this file extention :s

      Like

      • Hi Ajay

        Mtbx will not be recognized by Windows by default. If you open it once in a notepad. Windows will start using notepad as the program to open it.

        Under which option u are giving the path of the mtbx file in the Jenkins job ??

        Thanks,
        Sumeet

        Like

      • Hi Sumeet,

        That was with “Execute with Windows batch command” option

        I’ve also tried with “Execute HP test from file system” option – for this option it fails immediately and the console output reads:

        Started by user anonymous
        [EnvInject] – Loading node environment variables.
        Building remotely on UFT_Test_VM41 in workspace C:\Jenkins\workspace\archive\Test_Folder\Test_Alpha
        [Test_Alpha] $ C:\Jenkins\workspace\…\Test_Alpha\HpToolsLauncher.exe -paramfile props16012017183210502.txt
        “Started…”
        Launcher timeout is 10675199::02:48:05
        reading PerScenarioTimeout: 10
        PerScenarioTimeout: 00:10:00 minutes
        PerScenarioTimeout: 00::00:10:00 minutes
        >>>> File/Folder not found: ‘C:\driver.mtbx’
        No valid tests were found. Fix the test paths.
        Build step ‘Execute HP tests from file system’ changed build result to FAILURE
        Notifying upstream projects of job completion
        Finished: FAILURE

        Thanks,

        Ajay

        Like

      • Windows Batch command will not work. You must use the option to run the mtbx file with “execute hp tests with file system” try to put the file inside a folder within your documents or desktop folder.

        What is the content of your mtbx file ??

        Like

      • Hi Sumeet

        The content of the mtbx file:

        ….

        ….

        </Mtbx

        I have moved the mtbx file into a folder now and run it with option Execute HP test with file system. I get the following console output:

        Started by user anonymous
        [EnvInject] – Loading node environment variables.
        Building remotely on Test_VM in workspace C:\Jenkins\workspace\…\…\TestA
        [Test_Alpha] $ C:\Jenkins\workspace\…\…\TestA\HpToolsLauncher.exe -paramfile props17012017095716289.txt
        "Started…"
        Launcher timeout is 10675199::02:48:05
        reading PerScenarioTimeout: 10
        PerScenarioTimeout: 00:10:00 minutes
        PerScenarioTimeout: 00::00:10:00 minutes
        FileSystemTestRunner timeout is 10675199.02:48:05.4775807
        ===============================
        There are no valid tests to run!
        ===============================
        Build step 'Execute HP tests from file system' changed build result to FAILURE
        Notifying upstream projects of job completion
        Finished: FAILURE

        Thanks

        Ajay

        Like

      • Repost as the content of mtbx file is not displayed above.

        Test name=”U01″ path=”C:\Automation\Profile_Creation”
        Parameter name=”IterationID”” value=”4″ type=”string”/
        ….
        /Test
        Test name=”U02″ path=”C:\Automation\ Profile_Creation”
        Parameter name=”IterationID” value=”5″ type=”int”/
        ….
        /Test

        Wrapped in Mtbx

        Removed all the

        Like

      • Thanks!

        That example works but it shows up yellow on jenkins and the log attached below states “failures: 1”. I have tried adding few other lines of code in the test with a wait statement which gives me enough time to click OK on the msgbox but jenkin assumes the test is complete before its actually complete. :S

        Log File
        ====================================

        Started by user anonymous
        [EnvInject] – Loading node environment variables.
        Building remotely on VM in workspace C:\Jenkins\workspace\..\..\MTBXExample
        [WS-CLEANUP] Deleting project workspace…
        [WS-CLEANUP] Done
        [MTBXExample] $ C:\Jenkins\workspace\…\..\MTBXExample\HpToolsLauncher.exe -paramfile props24012017100514444.txt
        “Started…”
        Launcher timeout is 10675199::02:48:05
        Controller Polling Interval: 30 seconds
        PerScenarioTimeout: 00::00:10:00 minutes
        FileSystemTestRunner timeout is 10675199.02:48:05.4775807
        Mc connection info is – Mc HostAddress: , McPort: ****, Username: , UseSSL: 0, UseProxy: 0, ProxyType: 0, ProxyAddress: , ProxyPort: 0, ProxyAuth: 0, ProxyUser:
        1 tests found:
        test1
        ============================================================================
        24/01/2017 10:05:13 Running: C:\MTBXEXAMPLE\MTBXExample
        Running test: C:\MTBXEXAMPLE\MTBXExample
        Test result: Failed
        24/01/2017 10:05:18 Test complete: C:\MTBXEXAMPLE\MTBXExample
        ——————————————————————————————————-
        ================================================
        Run status: Job unstable (Passed with failed tests), total tests: 1, succeeded: 0, failures: 1, errors: 0

        Liked by 1 person

      • Hi Sumeet,
        I did create Jenkins project “Execute HP functional tests from HP ALM” and its working fine, scripts running on planned hosts through ALM as expected, but not able to pass the parameter in this project.

        So I tried your method “HP Test from file system” but it runs the script on local machine and not on remote machine.
        I would like pass the parameter and also run the script on planned host machine, How can it be achieved?
        Please help me out. Thank You.

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s