This blog post on QTP scripting discusses how to clean the browser and remove cookies, and how to minimize QTP during test execution so you can see the application in action.

QTP Scripting – Cleaning the Browser

When using QTP to automate tests with a browser, we want to have a clean browser without any cookies. Rather than record the action as select tools-Internet Options, there is a much more elegant way. QTP has the delete cookie function itself.

Using an object in QTP named WebUtil, we can add a method;WebUtil.DeleteCookies.When we use it in a script, we need to add three commands:

  1. Set oWebUtil = CreateObject(“Mercury.GUI_WebUtil”)
  2. oWebUtil.DeleteCookies
  3. Set oWebUtil = Nothing

This ensures that the cookie has been cleared, sometimes a mandatory condition depending on the types of tests you are executing.

QTP Scripting – Minimizing QTP During Execution

When we execute a QTP script, sometimes we want to observe the application, but QTP always occupies the screen. This makes examining the application during script execution impossible. We tackle this problem with one of two methods:

Method 1 is to add these three commands that deem the QTP application as an object.
Set qtp = CreateObject( “QuickTest.Application” )
qtp.WindowState = “Minimized”
Set qtp = Nothing

Method 2 is to control the QTP window anddeem the QTP window as an object.
Set qtpWindow = Window(“title:=QuickTest.*”)
qtpWindow.highlight
qtpWindow.Minimize

This enables us to observe the tested application on the screen while QTP is minimized in the task bar.

For other tips and guidelines on software test automation, check out our white papers in our website knowledge center.