My Blog List

Monday, May 11, 2015

QTP - Object Identification - Prerequesties

While starting a new project or proof of concept or after new QTP installation, we would face the issue in identifying objects as QTP built objects like WinList, WebEdit, etc.; instead everything will be identified as WinObject.

Here are some steps to ensure you did the environment setup RIGHT before start automating.
  • Did you enabled required Add-ins only while launching
  • Did you selected "Record >> Record and Run Settings" - This should be based on what type of application you are working with

Windows app - Windows >> Record and run test on any windows applications.
Web app - Web >> Record and run test on any open browser.

  • Did you tried to launch UFT/QTP and then AUT.
  • If its web, ensure browser zoom level set to 100%
  • Try disabling the protected mode in IE for web.
  • Launch UFT and AUT using RUN AS ADMINISTRATOR
Also see the Object Identification Methods if you are interested.

Monday, May 4, 2015

Handling auto populate, delayed masking and auto select fields

While doing automation, we could have come across the fields which will do the functionality like,
1. While entering some text, it will auto populate the matching values
2. While entering the text, it will mask the values i.e. convert to xxx.. or ....

To simulate the functionality many of us could have faced problems while entering the values on the field;

  • The value entered is not converting as masking text as it is doing while manual flow
  • The form not accepting the entered values
  • The entered/selected value not persists in the field after the simulation, etc.

How to handle such controls effectively. Here we go;
1. WScript.Sendkeys

Set shell = CreateObject("Script.Shell")
Window("hwnd:=" & Browser("myApp").GetROProperty("hwnd")).Activate  'if it's Browser
obj.Set ""
Wait 1
obj.FireEvent "OnFocus"
Wait 1   
shell.SendKeys "your value", 1000
Wait 1
shell.SendKeys "{TAB}"

The important thing here, always have focus on the current window before passing sendkeys.

2. BLUR
 You can call the blur event after entering the values in the field like;

Set shell = CreateObject("Script.Shell")
Window("hwnd:=" & Browser("myApp").GetROProperty("hwnd")).Activate  'if it's Browser
obj.Set ""
Wait 1
obj.FireEvent "OnFocus"
Wait 1   
shell.SendKeys "your value", 1000
Wait 1
obj.Object.blur 'OR obj.FireEvent "OnBlur"

May be both the approaches will fail or should be better approaches out there, please feel free to share with us.

Error Handling in UFT - Contd...

See the basic post if you didn't.

Now you wonder, is there a way to implement inside our code.
Here we go;

Browser("myapp").Page("myPage").WebEdit("mytext1").Set "someText1"
If Err.Number <> 0 Then
  Reporter.ReportEvent micFail, "some step", "some description"
  Err.Clear
End If
'after handling the error, continue to next step
Browser("myapp").Page("myPage").WebEdit("mytext2").Set "someText2"
If Err.Number <> 0 Then
  Reporter.ReportEvent micFail, "some step", "some description"
  Err.Clear
End If

So the complexity is, we need to add the error check block after each step which is not good.So what can we do better is;

Function CheckForError
  Environment.Value("IsError") = False

  If Err.Number <> 0 Then
    Reporter.ReportEvent micFail, "some step", "some description"
    Environment.Value("IsError") = True
  End If

  CheckError = Environment.Value("IsError")

End Function

'##########################################################
' ---------------- COMPONENTS ----------------------------
'##########################################################

Function COMPONENT_1
   Browser("myapp").Page("myPage").WebEdit("mytext1").Set "someText1"
   If CheckForError Then Exit Function

   Browser("myapp").Page("myPage").WebEdit("mytext2").Set "someText2"

   If CheckForError Then Exit Function
End Function

From your Driver Script, you can check for Environment.Value("IsError") after executing each keyword and take decision. What else we can do still to avoid even these calls but need this error handling.

Using Recovery Scenario:
You can create a Recovery Scenario with the event "Test Run Error" and add this CheckError function as part of recovery function. Now it should call and check for errors, do the recovery steps described as part of your function whenever an error happens.

Also you can write some common function to do all events with error handling like this and use.


Function Simulate(objUICtrl, strValue)
    On Error Resume Next

    Select UCase(objUICtrl.GetROProperty("micClass"))
           Case "WEBEDIT":
                     objUICtrl.Set Trim(strValue)
           Case "WEBLIST":
                     objUICtrl.Select Trim(strValue)
           Case "WEBELEMENT":
                     objUICtrl.Type Trim(strValue)
    End Select

   If Err.Number <> 0 Then
        'Your recovery steps...
   End If
   Err.Clear 'always safety
End Function
RegisterUserFunc "WebEdit", "Set", "Simulate", True
RegisterUserFunc "WebList", "Select", "Simulate", True
RegisterUserFunc "WebElement", "Type", "Simulate", True
Usage:
Browser("myApp").Page("myPage").WebEdit("someText").Simulate "someValue"
Browser("myApp").Page("myPage").WebList("someList").Simulate "someValue"

Friday, May 1, 2015

Handling objects not visible on screen

Nowadays most of the web applications are built with different WEB 2.0 technologies and controls are loaded in different ways. While automating those pages, test developers normally will face the problems like;

Object not Visible
Not able to simulate the event on the object
etc.

If we debug the object, UFT's Exist or Selenium's elementPresent will return TRUE always but actually the control will not be in the screen. SO what is the deal here?

Let us discuss how developers are loading the controls.

1. Basically developers will use Style property to make a control visible on screen or to hide like;

control.Style.Display = "block" or "inline" or "" or "null"

But the control will be always available in the source XML structure and thus UFT's Exist will always returns TRUE.

2. Sometimes, the source XML itself not available in the code and dynamically they form the HTML structure using JQuery, JavaScript, etc. and display in the screen.
In this scenario, no need to worry as Exist itself will return FALSE as it is not in the source XML.

Here are some ways to handle the first scenario.
1. You can check using Style property
If obj.Exist(0) Then
  If oLink.Object.Style.Display <> Empty Then
     'your operations
  End If
End If

2. You can check using height as If the control is not presented in screen, it will not have height,
width, etc. values.
If obj.Exist(0) Then
  If oLink.Object.offsetHeight <> Empty Then
     'your operations
  End If
End If