My Blog List

Monday, June 8, 2015

Handling Objects not recognized as standard type

While doing automation on UI, we will face lot of scenarios like Object not identified as expected type and will scratch our head how to simulate such object set, click, etc.

We have some options to simulate actions on such controls using WScript.Shell or Mercury.DeviceReplay
The only thing, we need to instruct the those APIs at whichposition exactly it need to perform the actions.

You can do with absolute poistion:
x = yourObject.GetROProperty("abs_x") + (yourObject.GetROProperty("width") / 2)
y = yourObject.GetROProperty("abs_y") + (yourObject.GetROProperty("height") / 2)
Set MerRply = CreateObject("Mercury.DeviceReplay")
MerRply.MouseClick x + 5, y, LEFT_MOUSE_BUTTON

You can use relative position:
x = yourObject.GetROProperty("width") / 2
y = yourObject.GetROProperty("height") / 2
yourObject.Click x, y, LEFT_MOUSE_BUTTON

If you want to type on the controls, simulate the type using SendKeys followed by click action.

UFT - Take full page screenshot by scrolling the page


'########################################################################################
'This is navigate through the full page and taking individual screenshot of visible area
'########################################################################################
Function TakeScreenshot
 Dim intScrolls, intScroll, strScrollPos
 Set pgApp = Browser("").Page("")

 intScrolls = Round(pgApp.RunScript("document.documentElement.scrollHeight / (screen.height)"), 2)
 If intScrolls < 1 Then intScrolls = -1

 pgApp.RunScript "window.scrollTo(0, 0);"
 Wait 1
 Browser("").CaptureBitmap "C:\screenshot0.png", True
 For intScroll = 0 To intScrolls
  If Environment.Value("Browser") = "CHROME" Then
   strScrollPos = "scrollY"
  Else
   strScrollPos = "document.documentElement.scrollTop"
  End If
  If pgApp.RunScript("document.documentElement.scrollHeight - " & strScrollPos) > pgApp.RunScript("screen.height") Then  
   intY = pgApp.RunScript(strScrollPos & " + screen.height - 168;")
   pgApp.RunScript "window.scrollTo(0, " & intY & ");"
   Wait 1  
   Browser("").CaptureBitmap "screenshot" & (intScroll + 1) & ".png", True
  End If          
 Next
 
 'To merge the images to generate full page screenshot
 Call MergeImages
End Function

'########################################################################################
'This is to merge all individual images to one full page screenshot
'########################################################################################
Function MergeImages   
    Dim drawImage, grapImage, imgFormat, imgLayer, imgPT
    Set drawImage = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", 1920, 1050)
    drawImage.SetResolution 50, 45
    Set grapImage = DotNetFactory.CreateInstance("System.Drawing.Graphics").FromImage(drawImage)
   
    Set imgLayer = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", "C:\screenshot0.png")
    Set imgPT = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", 0, 0)
    grapImage.DrawImage Layer1, pt1
   
    Set imgLayer = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", "C:\screenshot1.png")
    Set imgPT = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", 0, 540)
    grapImage.DrawImageUnScaled Layer2, pt2
   
    Set imgFormat = DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat", "System.Drawing", Nothing)
    drawImage.Save "finalScreenshot.png", format.PNG
End Function


This code is for UFT/VBScript and you can use the same logic by applying different APIs available for SELENIUM or any other tools.

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 CheckError
  If Err.Number <> 0 Then
    Reporter.ReportEvent micFail, "some step", "some description"
    Err.Clear
  End If
End Function
Browser("myapp").Page("myPage").WebEdit("mytext1").Set "someText1"
Call CheckError
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

Wednesday, April 1, 2015

Why Automation? Why Tools? Where is it useful?

Nowadays everywhere automation, automation, automation...

Most of the QA people talking about or willing to learn about UFT, Selenium, Webdriver, Appium, Perfecto, BDD, Cucumber, Specflow, etc...

Lot of common questions keep on asked by us...
1. Is manual testing replaced with AUTOMATION CODE?
2. Most of the recruiters asking Do you any tools in today's market? 
3. Is everything can be achieved by automation?
    and so on...

Let's discuss with the information we have and feel free to post your comments as well.

FACT:
Manual testing never replaced with automation code

UNDERSTANDING:
We cannot implement or code whatever a human tester will think or his intuitions: how a requirement should work.
Automation will be useful where;
1. Bulk set of repeated tests to be executed for each release
2. Test should be executed for multiple set of inputs
3. Validation or comparison kind of task with huge set of data
4. Data generation, etc.

Doing repeated tasks should be considered for automation and human tester should use his/her skill set to think about the ideas, solutions or suggestions for betterment of the application.

FACT:
Yes. Every tester should know some tools and coding stuffs.

UNDERSTANDING:
For example, you are executing some set of test cases which includes; UI navigation, UI values validation against database, some calculation and validation against some UI values, DB to DB comparison, web service response XML validation, etc.

Now think, if you know only pure manual execution but not VBscript or some excel macros or some DB queries. You will take 1 hour to complete first test and may be 50 mins for further tests based on your experience with the application.
What if you know some coding stuffs: you can compare the DB values using vbscript/macros with in mins and your execution time will be in 5-10 mins.
The same way if you know some basic automation frameworks like UFT or Selenium, you can write your own code (may not be with high level framework because you are going to use it locally) and execute it. Parallel you can think about the requirements and real-time scenarios on how the application should behave, how it is improved, what kind of possibilities end user will try, etc.

FIND PRODUCT FOR YOUR CUSTOMER INSTEAD OF FINDING CUSTOMER FOR YOUR PRODUCT - said by CEO of some company.

Also today's world providing lot of platforms and opportunities to work with and consumers are always interested in getting their job done ON THE GO through various channels. So by default testing with multiple browsers in desktop and mobile, testing with multiple mobile devices with different resolutions, manufactures, tablets and with different type of applications like Native, Hybrid, etc.
So automation is the only best solution to provide coverage for all type of possibilities without quality compromise.

And today's AGILE world willing to accept only the people who are trying to utilize the best possible ways for each and every type of tasks instead of doing it in traditional way. Sometimes pure manual testing will be best choice, sometimes different small unit testing frameworks and somewhere good framework tool set.

So utilize the technology to maximum and have fun !!!