Search code examples
vbscriptautomated-testsqtphp-uft

UFT API-test execution via vbScript


I am trying to run my API test via a vbscript file based on Automation Object Model. I am able to launch, open and run my GUI tests but for API tests I get an Error "cannot open test" code: 800A03EE. I have read somewhere that my testcase is probably corrupted, so I saved the test as a new one but still doesn't work.


Following is my vbscript:

testPath = "absolute address to my API-test folder"
Set objUFTapp = CreateObject("QuickTest.Application")
objUFTapp.Launch
objUFTapp.Visible = TRUE
objUFTapp.Open testPath, TRUE     '------> throws the error
Set pDefColl = qtApp.Test.ParameterDefinitions
Set rtParams = pDefColl.GetParameters()
Set rtParam = rtParams.Item("param1")
rtParam.Value = "value1"

objUFTapp.Test.Run uftResultsOpt,True, rtParams 

objUFTapp.Test.Close
objUFTapp.Quit

Solution

  • By time of UFT installation we can opt for an additional automation tool, LeanFT.

    As the main feature of LeanFT, we can have the test environment right next to our development environment, either in Java(Eclipse) or C#.net(Visual Studio). Also we are provided with an object identification tool (GUI spy) which makes it possible to develop GUI test not in VBScript anymore but in one of the most powerful modern languages (Java or C#). With this very short summary, let's have a look at how actually we can execute API tests outside of UFT IDE. After a successful installation of LeanFT tool, we can create a LeanFT project in our Eclipse or Visual Studio. Create a new LeanFT project

    C# code:

    using HP.LFT.SDK;
    using HP.LFT.SDK.APITesting.UFT;
    
    ......
    [TestMethod]
    public void TestMethod1()
        {
            Dictionary<string, object> InputParameters = new Dictionary<string, object>();
            InputParameters.Add("environment", "TEST");
            APITestResult ExecutionResult = APITestRunner.Run("UFT Test Path" , InputParameters);
            MessageBox.Show(ExecutionResult.Status.ToString());
    .....
    }
    

    For sure above code is just to give you an insight although it works pretty fine. For better diagnistic, we can take advantage of other libraries like "HP.LFT.Verifications" for checking the result Important: You cannot use UFT and LeanFT at the same time as your runtime engine!