Wednesday 19 March 2014

How to check and uncheck the perticular check box using QTP script



1) script for check the perticular check box

Browser("OLM Training").Page("Cart").WebCheckBox("WebCheckbox12").Set "ON"


2) script for un check the perticular check box

Browser("OLM Training").Page("Cart").WebCheckBox("WebCheckbox12").Set "OFF"


3) select the perticulat item from check box.


For i=1 to rc
  Table_linkText=Browser("projectCentre QTP:TEST-AT:").Page("projectCentre QTP:TEST-AT:").Frame("RegRegRegFrame").WebTable("...").GetCellData(i,3)
If (Expected_Link=Table_linkText) then
  Browser("projectCentre QTP:TEST-AT:").Page("projectCentre QTP:TEST-AT:").Frame("RegRegRegFrame").WebTable("...").ChildItem(i,1,"WebCheckBox",0).Set "ON"

How to select perticular item from Web list using QTP script


Ex: Web list contains below items.

Facebook
Yahoo
Twitter
Email



1) select item from web list using item index. Item index starts from 0.

Browser("OLM Training").Page("Cart_2").WebList("WebListBox").Select "#2"

o/p  Twitter


2) Select item from web list by using item name directly.


Browser("OLM Training").Page("Cart_2").WebList("WebListBox").Select "Email"

o/p  Email

How to select the second Radio button from Group of Web Radio button using QTP script


Method 1:

Find the "Value" property of the second radio option from web Radio Button Group using Object Spy. Then using below script we can select the perticular radio option from web radio button

Ex: "Value" property of second radio button = "Two"

Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").Select "Two"

Method 2:

 we can find the value property and select the second radio button option using below QTP script


CurrentValue = Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").GetTOProperty("value")

If CurrentValue <> "Two" Then
Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").Select "Two"
End If

QTP Virtual Object



We create the objects virtually in the QTP. Its enable the objects and run the test which is not regonized by QTP.

Its mark the boundary value of the object and saved it as a collection object. That means Objects are stored in object repository, so the virtual objects are stored in collection.

we cannot create virtual object using OR. we can use virtual object manager.


How to create the Virtual object

1) Tools-> Virtual Objects -> New Virtual object.
2) Click "Next"
3) select standared class for mapping the virtual object into the any standared class.
4) Mark the X and Y co-ordinates for virtual object by using "Mark object" button. Then click Next.
5) Select Entire parent hierarchy for save full hierarchy information.
6) Rename the Virtual object name as we want   
7) Rename the collection name as we want
8) click "Finish".


The above virtual object Saved below location in System :

C:\Program Files (x86)\HP\QuickTest Professional\dat\VoTemplate\VoCollection0.vot


how to add virtual object into the object repository

1) copy the VoCollection0.vot file from the location (C:\Program Files (x86)\HP\QuickTest Professional\dat\VoTemplate\VoCollection0.vot).
2) and save with the extention as .tsr file for adding the virtual object in OR. (Ex: VoCollection0.tsr)
3) Then save it. now the  VoCollection0.tsr have the virtual object which was created.



Limitations:


1) QTP doesnot support the virtual object in analog and low-level recording.
2) During the run session, make sure that the application window is same size in the same location as it was in recording. otherwise the co-ordinating of the virtual object relative to the parent may be different and script may get failed.
3) we can use the virtual objects only when recording and running the  test.
4) we cannot use the object spy to view the property of the virtual object.

ADO - Activex Data Object


ADO is a Microsoft technology, and stands for ActiveX Data Objects

ADO can be used to access databases from your ASP web pages.



What is ADO?

    ADO is a Microsoft technology
    ADO stands for ActiveX Data Objects
    ADO is a Microsoft Active-X component
    ADO is automatically installed with Microsoft IIS
    ADO is a programming interface to access data in a database


*********************************************

The common way to access a database from inside an ASP page is to:

    Create an ADO connection to a database
    Open the database connection
    Create an ADO recordset
    Open the recordset
    Extract the data you need from the recordset
    Close the recordset
    Close the connection


********************************************


ADO Database Connection

1) Create a DSN-less Database Connection

The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access database on your web site.

2) If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you can connect to the database with the following ASP code:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>

Note, from the example above, that you have to specify the Microsoft Access database driver (Provider) and the physical path to the database on your computer.


********************************************************


ADO Recordset

To be able to read database data, the data must first be loaded into a recordset.
Create an ADO Table Recordset

After an ADO Database Connection has been created, as demonstrated in the previous chapter, it is possible to create an ADO Recordset. 

Suppose we have a database named "Northwind", we can get access to the "Customers" table inside the database with the following lines:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"

set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Customers", conn
%>



*******************************************************************


objCS.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source ="&varPath&"\Reports.xls;Extended Properties =""Excel 8.0;HDR = YES;"";"



Provider = Microsoft.Jet.OLEDB.4.0; - Connect the database using DSN-less connection. It can be used any microsoft Access database.

Data Source ="&varPath&"\Reports.xls; = This is the path of Excel(Database)

Extended Properties =""Excel 8.0;HDR = YES;"";

1) HDR - yes mean The first column in excel treated as Column name. Not data . if HDR - No mean The first column in excel treated as data.

2) specify Excel 8.0 for XLS and Excel 12.0 for XLSX files, which means you would need to build connection string dynamically. You also need to specify correct extension for you files - if it is xlsx than you should put it instead of xlsx.

The connection string for XLSX files would be something like

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFile.xlsx;Extended Properties=""Excel 12.0 Xml;IMEX=1;HDR=YES;""

and for XLS files

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFile.xls;Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;""


    
**********************************************************************

Recordset.Open Source, ActiveConnection, CursorType, LockType, Options


 CursorType

    Optional. A CursorTypeEnum value that determines the type of cursor that the provider should use when opening the Recordset. The default value is adOpenForwardOnly.
LockType

    Optional. A LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the Recordset. The default value is adLockReadOnly.
Options

    Optional. A Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object, or that the Recordset should be restored from a file where it was previously saved. Can be one or more CommandTypeEnum or ExecuteOptionEnum values, which can be combined with a bitwise OR operator.