Wednesday, May 25, 2011

QTP-File Extensions

Hi Folks,

Following are type of file extensions used in QTP.
  1. function library files = .vbs, .qfl and .txt
  2. local object repository file = .mtr
  3. shared object repository file = .tsr
  4. recovery scenory file = .qrs
  5. Default.cfg :- "Microsoft Office Outlook Configuration File"
  6. Default.xls :- "This is the copy of the internal datatable which is there by default. 1 sheet is Global, other sheets are as per the Action names"
  7. Login.usr :- "It is a kind of default constant file where all the inbuilt vaialbles are assigned some values or otherwise"
  8. Script.mts :- "This is just the scripts as per each action. Whatever you write in each action will be saved here"
  9. thick_usr.dat :- "It is a kind of default constant file where all the inbuilt vaialbles are assigned some values or otherwise"
  10. thin_usr.dat :- "It is a kind of default constant file where all the inbuilt vaialbles are assigned some values or otherwise. It consists of less no. is variables than thick_usr.dat"

Wednesday, May 18, 2011

QTP-How to use Parameter using QC

How to use Parameter in QTP

To use parameter in QTP, first we need to declare it in QC under parameter tab. If you want to define Input parameter then, you have to define it in input section. If you want to define output parameter then you have to define it in output section. Parameter name should be same in QC and QTP script.

Steps
  1. Create first component
  2. Define input and output parameter in QC
  3. Declare parameter value in QTP script
  4. Assign value for input parameter in QTP, example parameter(“SearchStr”)=”string for search value”
  5. Use the input parameter in control
  6. Use run time value and assign it to output parameter for use in QTP, example parameter(“outurl”)=”www.google.com”
  7. Now, make second component
  8. Use first component’s output parameter as input value in second parameter.
  9. Follow same steps as mentioned in first component.
  10. Now to run the QC and use parameter create test case in test plan module.
  11. Pull the first and second component in test case.
  12. Give input value in first component for run.
  13. Check use output value of previous component checkbox in second component.
  14. Integrate test case with test lab.
  15. Run the test case from QC.
  16. It will take input search string from first component and output value of first component is used as input of second component and execute whole test combine.
 Sample script1

Dim browsernm,pagenm
browsernm="Google"
pagenm="Google"
URL=http://www.google.com/
SystemUtil.Run "iexplore.exe",URL
reporter.ReportEvent micPass,"IEopen","Google open"

‘code for debug and error handling purpose
On Error Resume Next
Err.Clear
Dim testset, n
Set testset = QCUtil.CurrentTestSet
n = testset.name
If Err.Number <> 0 Then
Errr.Clear
End If

'Debug Declaration

If n = "" Then
Parameter("Searchstr")="Parameter Test in QTP"
End If
Parameter("OutURL")=""
Set Currobj=Browser("title:="&browsernm,"CreationTime:=0").Page("title:="&pagenm)

If parameter("Searchstr")<>"" Then
If Currobj.WebEdit("name:=q").exist Then
Currobj.WebEdit("name:=q").Set Parameter("Searchstr")
reporter.ReportEvent micPass,"searchvalue","search value set successfully"

Parameter("OutURL")=Currobj.WebElement("innertext:=qtp.blogspot.com/2007/11/qtp-test-parameters_11.html").GetROProperty("innertext")
reporter.ReportEvent micPass,"linkvalue","Link value set properly"
else
reporter.ReportEvent micFail, "searchvalue","search value not set successfully"
End If
End If

Sample Script2

Dim browsernm,pagenm
On Error Resume Next
Err.Clear
Dim testset, n
Set testset = QCUtil.CurrentTestSet
n = testset.name
If Err.Number <> 0 Then
Errr.Clear
End If

'Debug Declaration
If n = "" Then
Parameter("InURL")=""
end if

If parameter("InURL")<>"" Then
SystemUtil.Run "iexplore.exe",Parameter("InURL") reporter.ReportEvent micPass,"IEopen","Google open"
End If

QTP-Parameter Types

What is Parameter and Types of Parameters in QTP?

Parameters facilitate re-usability of an Action or a Test. By using parameters, you can record a test once and use it several times. Parameters enable you to run multiple sets of data.

Note: An input Parameter is a placeholder for a value that is passed to the test during the test run.

Parameter Types: By default, a test runs once for the recorded values. To run a test for multiple values,parametrize the test. The types of parameters in QuickTest are:

1. Input parameter: Enables you to run a test using different sets of input values.

For example, you can use input parameter to select different destinations for the same source in the Flight Reservation Application .

2. Output parameter : Enables you to use output to capture values from the application at run-time. You can get a value from the application and store it in the QuickTest test Results. You can later use this value as an input to a variable.

3. Random Number parameter: A system-generated number that is generated during a test run.

4. Environment parameter : A variable that describes a software or hardware object in the application under test environment. Examples are operating system version or Local host name.

Monday, May 16, 2011

SQL Queries

SQL Queries


Query for find n th highest salary

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 3 salary
FROM dbo.empsalary
ORDER BY salary DESC) a
ORDER BY salary

To find the size of database

SELECT * FROM SYSFILE
USE URDBNAME
EXEC SP_HELPDB
EXEC SP_SPACEUSED

Create table from existing table

CREATE TABLE tblname (colnm) AS SELECT colnm FROM existingtblname

Precondition: table should already exist in select clause, number of column should be same and data type should be same.

To copy only structure of table not data

CREATE TABLE tblname AS SELECT *FROM existingtblnm WHERE (any false condition)
Example: Create table tblname as select * from existingtblnm where 1=2

To insert record into table from existing table

Precondition: both the table exist and data type must same
INSERT INTO table1 AS SELECT * FROM table2

Rename table

RENAME oldtblnm TO newtblnm

Drop table

DROP tablenm

To identify how many tables are there

SELECT *FROM TAB

To see the fields of table

DESC tablename

DUAL

In build table in oracle, only 1 row and 1 column,for getting output on screen of operations or system date
Example: select 2*2 from dual, select sysdate from dual

For viewing tables, views, SP,function from database

SELECT name,xtype FROM sysobjects WHERE xtype in (‘u’,’v’,’p’,’fn’) AND name NOT LIKE ‘dt%’ ORDER BY xtype

Wednesday, May 11, 2011

Testing Cheat sheet & Tips

Hi Friends,

Please find below some tips on Testing with cheat sheet.

Test Heuristics Cheat Sheet by Elisabeth Hendrickson - This is one of the best cheat sheat that you could find for testing. 

Heuristic Test Strategy Model by James Bach - Again, a must read.

Heuristic Risk-Based Testing by James Bach - A must read for all testers.



Thanks,

Test your application in Different Browser

Hey Readers,

Many times you have to test your website look and feel in different browser with different version having different OS. Right? So, what are you doing? Here, I have come across very good link, which can help you in your work.

http://www.browsershots.org/

This site can give you different appearance of your web page in different browswer and you can test it. Hope this will help you.

Tuesday, May 10, 2011

QTP-Database connection example

Hey folks,

I would like to give example of how database connection works in QTP. Following example takes DNS name as parameter and open ADODB connection with database. It fetch value from tables and compare it with UI elements. Hope this will helpful to you.
Following are the steps for the same with below example.
1. Either through parameter/varaible give DSN name.
ConnectionString="filedsn="&systemdnsnm
2. Create adodb.connection object
3. create execonnection object
Execonn.Connectionstring=Cstr(Connectionstring)
.connectiontimeout=10
.open
4. create recordset adobd.recordset
5. check connection state
if execonn.state=1 then
6. write query
sqlquery=select * from table
7. execute query by set dbresultset=execonn.execute(sqlquery)
8. read data from UI and store in variable or take data in variable.
if webtable used then use getcelldata(1,2) like method
9. Read dbresult till EOF n store value in DBtemp variable.
using DBResult.Fields.Item(query col name)
10. compare variable and dbvar and verify result.

Example

'parameter name for database connection
Parameter("DNS_Name")="DNSFilename.dsn"

'code for connecting database
Systemdatasourcenm=Parameter("DNS_Name") 'give DSN name
ConnStr="filedsn="&Systemdatasourcenm

Set ExtConn=CreateObject("ADODB.Connection") 'create connection object for database

With ExtConn
.ConnectionString=ConnStr
.ConnectionTimeout=10
.OPEN
End with

'create recordset object

Set DBResult=CreateObject("ADODB.Recordset")

'check for the connection state

If ExtConn.State=1 Then
reporter.ReportEvent micPass,"DBConn","DB connect successfully"
Else
reporter.ReportEvent micFail,"DBConn","DB Connection fail"
End If

'write query for fetching record and store the query in variable

SQLQuery="SELECT col1, col2, col3, convert(varchar(10),col4,101) As Submitted FROM table1 WHERE col1='04162BM00001'"

'set result set value by executing query with using connection object

Set DBResult=ExtConn.Execute(SQLQuery)

'go to first record in database

DBResult.MoveFirst

'do looping till the end of file to get results

While Not DBResult.EOF
DB_ClaimID=Trim(DBResult.Fields.Item("col1")) ' col1
msgbox DB_col1
DB_ClaimStatus=DBResult.Fields.Item("col3") ' col3
msgbox DB_col2
DB_Submitted=DBResult.Fields.Item("Submitted") ' col4
msgbox DB_col3
DB_ClaimType=Trim(DBResult.Fields.Item("col2")) ' col2
msgbox DB_col4
DBResult.MoveNext
Wend

Dim date1,id,STS,cltype
date1="06/10/2004"
id="04162BM00001"
STS="04"
cltype="F"

'compare two values of records

If ucase(id)= ucase(DB_ClaimID) Then
reporter.ReportEvent micPass,"id ","id same"
else
reporter.ReportEvent micFail,"id ","id not same"
End If

If STS= DB_ClaimStatus Then
reporter.ReportEvent micPass,"STS "," STS same"
else
reporter.ReportEvent micFail,"STS","STS not same"
End If

If cltype= DB_ClaimType Then
reporter.ReportEvent micPass,"cltype ","cltype same"
else
reporter.ReportEvent micFail,"cltype","cltype not same"
End If

If date1= DB_Submitted Then
reporter.ReportEvent micPass," date1"," date1 same"
else
reporter.ReportEvent micFail,"date1",date1 not same"
End If



'close database connection

ExtConn.Close
Set DbResult2 = Nothing
Set ExtConn = Nothing

Wednesday, May 4, 2011

QTP-Working with Export data to Excel from dropdown using Excel object

Hi Readers,


I have try to write code for getting data from dropdown and split it and enter it in excel sheet using Excel Application object without using data table.In this example, Book2.xls should be already created in c: drive.Browser name and page name should be according to your test site. Weblist name proeprty should be according to your test page. Capture it using Object Spy on you page.

Hope this will helpful to you.


URL=www.google.com

Systemutil.Run "iexplore.exe",URL
browsernm="Google"
Pagenm="Google"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)
'CurrObj.WebList("name:=Type").Click


Dim typeitem
typeitem=CurrObj.WebList("name:=Type").GetROProperty("items count") ' count number of items in dropdown
msgbox typeitem


Dim oexcel
Dim obook
Dim osheet
sSampleFolder="C:\"
sSampleFile="Book2.xls"
Set oexcel=CreateObject("Excel.Application")
Set obook=oexcel.Workbooks.Add
Set osheet=obook.Worksheets(1)
osheet.Range("A1").value="Type"
For i=1 to typeitem
a=CurrObj.WebList("name:=Type").GetItem(i)
osheet.Range("A2").value=a
Next
obook.SaveAs(sSampleFolder & sSampleFile )
Set osheet = Nothing
Set obook = Nothing
oexcel.Quit()
Set oexcel = Nothing

QTP-Import Data from Excel using Excel Object in QTP without using datatable

Hi Folks,

I try to write article on how to use Import Excel Data using QTP with Excel object.(Without using Data table).
Hope this will helpful to you.

URL=http://www.google.com/

Systemutil.Run "iexplore.exe",URL
browsernm=".*Google.*"
Pagenm=".*Google.*"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)

Dim oexcel
Dim obook
Dim osheet
sSampleFolder="C:\"
sSampleFile="Book2.xls"

Set oexcel=CreateObject("Excel.Application")'run excel application
Set obook=oexcel.Workbooks.Open("c:\Book2.xls") 'open work book from specified location
Set osheet=obook.Worksheets(1)'open worksheet with name or index specified

rowcnt=osheet.usedrange.rows.count ' get row count in excel sheet
msgbox rowcnt

For i=1 to rowcnt
temp=osheet.cells(i,1).value
CurrObj.WebEdit("name:=q").Set temp
CurrObj.WebButton("name:=Google Search").Click
Browser("title:=.*Google.*").Back
wait(3)
Next

colcnt=osheet.usedrange.columns.count 'get column count in excel sheet
msgbox colcnt

Set osheet = Nothing
Set obook = Nothing
oexcel.Quit()
Set oexcel = Nothing