Wednesday, 13 July 2016

Working with child objects - QTP

What is child object?

Child object is the method provided by the QTP to extract the collection of object define by you using dynamic descriptive programming .

When programmer define any of the object(like button, link), they define certain properties like html tag, innerHTML,outerHTML,value etc, we are using these properties in our dynamic DP and get the collection of similar objects.


here is the example:
In this example, I am trying ;to find out how many webtable is present in one of our most popular site.

systemutil.Run"iexplore"."http://newtours.demoaut.com/mercuryregister.php"
Set A=description.Create
A("micclass")="WebTable"
A("html tag")="TABLE"

'Setting the object collection
Set ObjDesc=browser("opentitle:=Register: Mercury Tours").page("title:=Register: Mercury Tours").ChildObjects(A)

'Count number of similar objects we found
TabCnt=ObjDesc.count
print TabCnt

'traverse every object

For i=0 to Tabcnt-1 step 1
ObjName=Objdesc(i).getroproperty("name")
msgbox ObjName
   ObjRwCnt=ObjDesc.rowcount
   ObjClmnCnt=Obdesc.columncount(ObjRwCnt)
   print ObrwCnt
   Print ObjClmnCnt
Next



Descriptive Programming

What is Descriptive Programming(DP)?
-Entering Objects Information directly into the test script is called descriptive programming.In DP, we will be "manually" specifying the properties and values by which the relevant object will be identified. This way QTP won’t search for the properties data in the Object Repository, but will take it from the DP statement.

-Object Spy is used to get the properties and their values to uniquely identify the objects in the application. If we know such
   properties and their unique values that can identify the required object without ambiguity, we need not use Object Spy.

What is the Need of DP?
During the automation, we always encountered with the objects whose properties are frequently changing(Dynamic in nature). To handle all these objects QTP provide a unique way of handling these kind of object which is DP.

Types of DP:
There are two types of DP Static DP and Dynamic DP

Static DP:
We provide the set of properties and values that describe the object directly in a VBScript statement.

Example-
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com" 

'Wait till browser loads
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync 
' Enter  Email id in Username Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set  "vb-excel.blogspot.in/" 
'Enter password in Passowrd Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:= Passwd").Set  "qtp" 
'Cick on the Sign In Button
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click

Dynamic DP:
We add a collection of properties and values to a Description object, and then enter the 
Description object name in the statement

Example-
Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google" 
'Descriptive object to identify  Web page with a particular title
Set  Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google" 
'Descriptive object to identify a  particular Web Button
Set  Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in" 
'Descriptive object to identify  Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"
Dedit("name").value="Email" 
'wait till browser loads
Browser(Dbrowser).Page(Dpage).Sync 
' Enter  Email id in Username Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "vb-excel.blogspot.in/" 
Dedit("name").value="Passwd" 
'Enter password in Passowrd Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "qtp" 
'Cick on the Sign In Button
Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click


Sunday, 10 July 2016

QTP - Working with webtables

During your journey to the automation of web based application, you have encountered with a situation in which you have to click on a object and when you spy that object, you found that the object is embedded in webtable.

So to click on the object, you have to traverse to the webtable and reach that object and perform the action.

Below are the example to ON the checkbox inside webtable.

Browser("Google").Page("Google").Sync
Browser("Google").Navigate "http://www.nucleation.in/function-check-uncheck-web-checkbox/"


Browser("QTP Function to Check").Page("QTP Function to Check").Sync
Set A= description.Create
A("micclass").value = "WebTable"
A("html tag").value = "TABLE"
A("name").value = "Passenger 1"
Set B = Browser("QTP Function to Check").Page("QTP Function to Check").ChildObjects(A)
MSGBOX b.COUNT
For I = 0 TO B.COUNT-1
'MSGBOX B(I).ROWCOUNT

For J= 1 TO B(I).ROWCOUNT
'MSGBOX B(I).COLUMNCOUNT(J)
For K = 1 TO  B(I).COLUMNCOUNT(J)
x=B(I).GETCELLDATA(J,K)
' MSGBOX x
If UCASE(x)="PASSENGER 2"  Then
msgbox j
msgbox k
set c = B(i).childitem (j,3,"WebCheckBox",0)
c.set "ON"


End If

Next



Next

Next

Thursday, 30 June 2016

Commonly asked interview question - QTP/VbScript

QTP - Vbscript interview questions and answers


Q1 What are Virtual Objects?

Your application may contain objects that behave like standard objects but are not recognized by QTP. You can define these objects as virtual objects and map them to standard classes, such as a button or a check box. QTP emulates the user's action on the virtual object during the run session. In the test results, the virtual object is displayed as though it is a standard class object.

For example, suppose you want to record a test on a Web page containing a bitmap that the user clicks. The bitmap contains several different hyperlink areas, and each area opens a different destination page. When you record a test, the Web site matches the coordinates of the click on the bitmap and opens the destination page.

To enable QTP to click at the required coordinates during a run session, you can define a virtual object for an area of the bitmap, which includes those coordinates, and map it to the button class. When you run a test, QTP clicks the bitmap in the area defined as a virtual object so that the Web site opens the correct destination page.

Q2. How to find the length of string in QTP?

Answer -You can find the length of the string using one vb script function called len.

Suppose you want to find the length of "salunke" then you will have the below statement which will print the length of string .

print len("salunke")


Q3. How to find the current system time in QTP?

Answer - You can find the current system time using Time function in vbscript.

Print time

Q4. How to remove all spaces from given string in QTP?

Answer - We can use replace function in vbscript to remove all spaces in string.

e.g. newstring = replace(stringwithspaces," ","")


Q5. How to find the modulus of a number in QTP?

Answer - We can find the modulus of given number using MOD operator.

a = 10 mod 5

print a

Q6. How to find the size of array in QTP?

Answer - To find the size of array, we can use ubound function in QTP.

print ubound(arr) - 'prints upper bound of array.

Q7. What is the difference between byref and byval in QTP?

Answer - You can pass the parameters to function or procedure using byref or byval method.

byref will pass the address of variable but byval will pass the copy of variable. So when you want the passed value to change, you can pass the value using byref method. Otherwise you can pass it using byval method.

Q8. How to find the difference between 2 dates in QTP?

Answer - You can find the difference between 2 dates using datediff function. You can get the difference in terms of minutes, seconds, hours, months or years.

Q9. How to generate the random number in given range in QTP?

Answer:
Min = 1
Max = 10
Randomize
RandomNumber = (Int((max-min+1)*Rnd+min))

Q10. How to create an array of dictionaries in QTP?

Answer - We can create the array of dictionary like how we create array of scalar variables.
Syntax is shown below –
'Declare Array with 5 elements
Dim myArray(5)
'Make first element in array as a dictionary object
Set myArray(0) = createobject("scripting.dictionary")
'Once we have a dictionary object, We can use its methods like add, remove, removeall etc
myArray(0).Add"mykey","myvalue"
'display item value of mykey in dictionary myArray(0)
print myArray(0)("mykey")
myArray(0).removeall

Q 11.  What are the types object Repositories in QTP.

QTP Supports 2 types of Object Repository

1) Shared Object Repository (also called Global)


2) Per-Action Object Repository, (also called Local)

Per-Action Object Repository is used by default. The extension for Per-Action repository is ".mtr" .

Shared Object Repository is preferable while dealing with dynamic objects which are called in multiple tests. The extension is ".tsr"

Can we call QTP test from another test using scripting. Suppose there are 4 tests and I want to call these tests in a main script. Is this possible in QTP?

Yes.  You can call 4 or even more scripts in your tests.For this, first you will need to make the Actions in the corresponding scripts re-usable.Then from the destination script you can make calls to these re-usable actions.


Q 12) What is action split and the purpose of using this in QTP?

Action split is to divide an existing action into two parts.The purpose is to divide actions based on their functionality to improve code re-use.

Q 13) How will you handle Java tree in QTP ?

Foremost you will select Java Add - In and launch QTP. Next step record operations on the Java Tree. If you face an issue while recording, you can select Tools > Object Identification > Java, tree object and make changes in mandatory and assistive properties to enable identification.

Tip: You can base you answer on similar lines for any other object of any environment. For example : If the question is how will check SAP checkbox , You say , first I will select SAP Add in ... and so on.

Q 14) Explain how QTP identifies object ?

QTP identifies any GUI Object based on its corresponding properties.  While recording, QTP will identify and store peculiar properties (as defined in the Object Identification settings) in the object repository of the GUI object . At run-time, QTP will compare the stored property values with the on-screen properties, to uniquely identify the GUI object.

Learn more about Object Identification

Q 15) How many types of recording modes in QTP? Which will be used when ?

QTP supports 3 types of recording modes


1. Normal mode also called Contextual

2. Low-level recording mode

3.Analog mode

Normal Mode: It is the default recording mode and takes full advantage of QTP's Test Object Model. It recognizes objects regardless of their position on -screen. This is the preferred mode of recoding and is used for most of the automation activities.

Low-level recording mode: This mode records the exact x,y co-ordinates of your mouse operations. It is helpful in testing hashmaps. It is useful for recording objects not identified by normal mode of QTP.

Analog mode: This mode records exact mouse and keyboard "movements" you perform in relation to the screen / application window. This mode is useful for the operation such as drawing a picture, recording signature., drag and drop operations.

Learn more about Recording Modes in QTP

Q 16) How will you  call from one action to another action ?

We can call an action in 2 ways

1) Call to copy of Action. - In this ,the Action Object Repository , Script and Datable will be copied to the destination Test Script.
2) Call to Existing Action. - In this,  Object Repository , Script and Datable  will NOT be copied but a call (reference) would be made to the Action in the source script.

Working with registry key!!!

During our journey of automation, Most of the thing that we often encountered that required the update/modification of registry key.

For Example - Need to disable the auto lock functionality during execution or suppose you need to disable popup in Internet Explorer

In such scenario's working with the registry key help us to provide smooth execution-

To do this automatically using QTP, there is only one requirement: we just have to find out the registry setting that affects the feature that you want to change..

We will take the example of pop up blocker in this case

So, to disable pop up blocker, we just need to change the following registry key to No

“HKCU\Software\Microsoft\Internet Explorer\New Windows\PopupMgr”

We have to create “Windows Shell” object and then access its inbuilt RegRead and RegWrite functions.

As the name suggests, RegRead method allows you to read the value of the specified Registry path and RegWrite allows you to modify the value of the specified registry.

Now, lets do some action:


Dim objShell, RegLocate
<blockquote>'create windows shell object
 Set objshell =CreateObject("WScript.Shell")

'disable pop up blocker in IE if enabled
 RegLocate ="HKCU\Software\Microsoft\Internet Explorer\New Windows\PopupMgr"
 msgbox objshell.RegRead (RegLocate)
 If Lcase(objshell.RegRead (RegLocate))=Lcase("Yes") Then
 objShell.RegWrite RegLocate,"No","REG_SZ"
 End If

Set objshell = Nothing

As you see in the above example, value of the specified registry is displayed using RegRead function and then if pop up blocker is enabled, then it is disabled by modifying the value of corresponding registry key.


Thursday, 23 June 2016

Appium - Selenium Java - Launching a URL

*****************For Beginners*****************

This post help you to understand how to set the capabilities to the automation test.

Capabilities have the power to mold the execution i a way that you want.

here are huge number of capibilities that appium offer to us, obviously the capabilities are different depend upon the OS that you are using.

Below are the simple code to open browser in the virtual device(Assuming Virtual device are already configure and connected)

DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName","Browser");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("automationName","selendroid");
    capabilities.setCapability("deviceName","Custom Phone - 4.1.1 - API 16 - 768x1280");
  
   
WebDriver Driver1 =  new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    Driver1.get("http://www.google.com");
    Driver1.Quit;