Showing posts with label QTP. Show all posts
Showing posts with label QTP. Show all posts

Friday, March 1, 2013

QTP :command in QTP to invoke IE Brow

command in QTP to invoke IE Brow



1. InvokeApplication "E:\Program Files\Plus!\Microsoft Internet\IEXPLORE.EXE"

2. Set IE=createobject("internetExplorer.application")
    IE.visible=true
     IE.navigate "www.gmail.com"

3. systemutil.Run "iexplore.exe",”www.gmail.com”

4. oShell = CreateObject ("Wscript.shell")
 oShell.Run Chr(34) & "C:Program FilesInternet ExplorerIEXPLORE.EXE" & Chr(34)






QTP :Run alternate iterations from the data table

Run alternate iterations from the data table


Click File –> Settings –> Run –> Select Run  once


currow = 1
Do Until currow =DataTable.GetSheet("dtGlobalSheet").GetRowCount

  currow = DataTable.GetCurrentRow
  msgbox Datatable("A",Global)
  currow = currow + 2
  DataTable.SetCurrentRow(currow)

Loop

QTP : DataTables

QTP Datables


Data Table Basics

Run -Time VS Design Time Datatables


1) The values of the Run Time Data table does not reflect in the QTP's DataTable window after run.

2) If you like to see the values of that DataTable after Run you can see it by openning QTP's result window,  then expanding the trees in the left pane of that window, there you will see Run Time DataTable Icon just below the Test Summary. If you click that you can see the runtime's content of that DataTable.

3) If you want to store runtime values, please, export it to some location (see below code):
DataTable.Export ("D:\XYZ.xls")





Thursday, February 28, 2013

VB & QTP : Fetching Data from DB and putting it into a 2D array

Fetching Data from DB and putting it into a 2D array






Public Function Func_GetQueryResult(sQuery)

Dim con,rs ,loopCounter,var,counter
counter=0
Dim resArr()

Set con=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.recordset")

con.open"provider=SQLOLEDB;Server=servername;Databae=dbname;Userid= ;Password= :"
rs.open sQuery,con

While not rs.EOF 'Count no of rows in your result
 loopCounter=loopCounter+1
 rs.MoveNext
Wend

If loopCounter = 0 Then
 Reporter.ReportEvent micWarning,"Empty Result Set","Query is: " & sQuery
 Func_GetQueryResult=False
 Exit Function
End If

rs.MoveFirst 'move the recordset object to first row again

ReDim resArr(loopCounter,rs.fields.count-1)

Do until rs.EOF 'Rows
  For var=0 to rs.fields.count-1 'cols
    If counter=0 Then
     resArr(counter,var) =rs.fields(var).name
     else
     resArr(counter,var) =rs.fields(var).value
    end if
  Next
 rs.MoveNext
 counter=counter+1
Loop

rs.Close
con.Close

Func_GetQueryResult=resArr

End Function



'////Connection string can also be -"DRIVER=SQL Server; DATABASE=" & DBName & ";APP=QuickTest Professional;SERVER=" & DBServer &";Description=Testconnection"

VBS :Ubound

Ubound


ubound method is used to count the length of array. It returns the highest index number of the array.
But remember, the actual size of the array is highest index number plus one!! 

Eg : Dim myArray(4)
       msgbox ubound(myArray)   '4
       msgbox "size="&ubound(myArray)+1      'size=5


Eg: Dim myArray(4,6)
msgbox ubound(myArray, 1) ' highest index of the first dimension - 4
msgbox ubound(myArray, 2) ' highest index of the second dimension - 6

Wednesday, February 27, 2013

QTP :Schema of Framework by Actions

Schema of Framework by Operations performed by various Actions


1. Action 0
  •    excel open     //Action of test case given by QC
2. Calling_action
  •  Clean up 
  • Open Fresh app
  • Timer 

3. Start_execution
  • Create Time stamp folder
  • Create a duplicate Test_Data.xls file.
  • (In our case we will have our "local excel open" to be commented )   
  • Create QTP object -to grab the path of the Testcase name from the environment variable  and compare it with the name given as input ,this to avoid multiple excel use when test case has similar name in QC.
  • Traversing to find matching test case name in excel with that of env varible or check whether "execute " is YES.
  •  Extract the Keyword sheet.
  • Goto 2nd Sheet get the corresponding data of that keyword
  • Put the data in global sheet
  • Rest of the Actions are nothing but representation of modules of application.We use Select-Case inside a for loop to go to the particular action where actual execution takesplace. 
 Example:
Keyword_A---TestCase1
Keyword_B---TestCase2
Keyword_C---TestCase3
Keyword_D---TestCase4

For i=1 to end_of_excelsheet

if testcasename_Excel =Testcase_from_environment variable OR "yes" then
Grab_keyword=Corresponding_keyword_from_excel;
end if

Grab_Data=Corresponding_data of Grab_keyword in sheet2 of inputsheet;
global_sheet=grab_data;

Select Case grab_keyword
Case Keyword_A ,Keyword_C
goto action"gui_db";

Case Keyword_B ,Keyword_D
goto action"Some othe action";
end select
Next

---------------------------Action gui_db---------------------------
Option explicit
variables here

Select Case grab_keyword
Case Keyword_A
do these ;
reporter
set obj=nothing;
return pass or fail status to start execution
exitAction;

Case Keyword_C
do these;
reporter
set obj=nothing;
return pass or fail status to start execution
exitAction;
End select
--------------------------------------------------------------------------
To update status of the test case executed into the excel sheet.




QTP : Adding Recovery Scenario

Recovery Scenario

 [http://www.qualitycenterstepbystep.com/2012/dcefining-a-recovery-scenario/]

To associate a Recovery Scenario to a test:
  1. Select File ==> Settings. The Setting Dialog opens.
  2. Select the Recovery node on the left.
  3. Click the “+” sign in the scenario frame at the top right. The ADD RECOVERY SCENARIO dialog opens.
  4. Browse to the location of the .qrs file.
  5. Click the Add Scenario button. The ADD RECOVERY SCENARIO dialog closes.
  6. Click the OK button in. The TEST SETTINGS dialog closes.

QTP :Associating a Function Library

Associating a Function Library

[http://www.qualitycenterstepbystep.com/2012/associating-a-function-library-with-qtp-test/]

After creating the function library, it can be saved as a .txt file. The next step is to associate that file and procedure it contains to the test. This is done in the Test Setting.
 To associate a Function Library to a test:
  1. Select File ==> Settings. The Setting Dialog opens.
  2. Select the Resource node on the left.
  3. Click the “+” sign in the Associated Function Libraries at the top right. The ASSOCIATE FUNCTION LIBRARY dialog opens.
  4. Browse to the location of the Function Library file.
  5. Click the Open button. The ASSOCIATE FUNCTION LIBRARY dialog closes.
  6. Click the OK button in. The TEST SETTINGS dialog closes.

QTP :Reusable Actions in a QTP Test

Reusable Actions in a QTP Test


Actions that are market as reusable in QTP may be called by multiple tests

Viewing a Reusable Action

Select Edit > Action > Action Properties…

alternatively you can do right click on the Login Action to open Action Properties window.

In Action Properties windows check Reusable Action in the button left corner.


QTP :Global and Local Sheet

Global and Local Sheet

Defining the QTP Data Table – Global

The Global Data Sheet can be used to supply or store data used by the entire test, regardless of the action. By default, the global sheet will iterate the entire test once for each row. The number of iterations id defined in the Test Settings.

Defining the QTP Data Table – Local

A Local data sheet exists for each action in a test. The tab name of the local data sheet is the same name as the action name. By default, the local data table iterates once. This is defined in the Action Call Properties

QC :Connecting QTP to Quality Center

Connecting QTP with QC 


Note :QC plugin should be installed to QTP corresponding to the version.
Similarly for QC ,QTP addin should be installed .Which can be found in the help button at the extreme right side inside QC.

When you are connected from QC from QTP, there are several advantages:

1. You can utilize the QCUtil object in your test and function libraries. This provides you with full functionality of the OTA.
2. Check whether integration between QC and QTP is working.

Connecting QTP to QC – Server URL

To connect QTP to QC:
1. Select File –> Quality Center Connection…

A Quality Center Connection – Server Connection Dialog box opens.

2. Enter the QC Server URL in the Server URL field.
3. Check the Reconnect To Server On StartUp checkbox to connect QTP to QC each time

4. Click the Connect Button. The QC Connection Dialog opens.

Connecting QTP to QC – Authentication


5. Enter your QC User Name and password in Step2: Authenticate User Information section.
6. Click the AUTHENTICATE button.
7. Check the Authenticate on StartUp checkbox, if available, to automatically authenticate to QC Server when you invoke QTP.

Connecting QTP to QC – project


8. Select the desired Domain and Project in Step 3: Login to Project section.
9. Click the Login button.
10. Check the Login to Project on StartUp checkbox, if available, to automatically log into the selected project when you invoke QTP.
11. Click the Close button. The QC Connection dialog closes.
Note: Verify that you are connected to QC by viewing the QTP status bar. A QC icon will appear. Hoover over the icon to display the tooltip, which displays the server and the project to which QTP is connected.


QC : Running QTP Automated test cases inside QC

Running QTP Test Cases in QC














The Test Lab module in QC enables you to control the execution of the tests.

1. Select the Test Lab tab in QC
2. Right click on the folder tree and Create New Test set
2. Click on "Select Test" button
3. On the left hand side list of test scripts appear
4. Drag and drop each of the test script of each scenario into the test set
5. Select all of them from the test set
6. Click on Run button
7. Another dialog box opens, Click on "Run All" button in that dialog box

QC : Converting manual Test Case into QTP test Case

Converting manual Test Case into QTP test Case



Note : QC -QTP addin should have been installed in QC .If you have not installed then go to QC>Help>Addins and Select the version of QTP you are working on .




1. In the test plan tree, select the manual test that you want to automate.
2. Click the Design Steps tab > click the Generate Script button.

3. Choose an automated test type to : QUICKTEST_TEST  . Now the manual test case is converted into QTP test .

4. Click on tab Test Script, any text that appeared in the steps of the manual test is listed as comments in the generated test script. (If the manual test has parameters, they are also listed as comment text)

5. Launch QTP tool by clicking QTP icon, it will launch QTP and open current test script in expert view.
6. Write and save test script, changes would be saved in QC in Test Plan module.

Or we can export test Script from QTP to QC. For that you need to first establish QTP-QC connection

1. In QTP, Open the File you want to save > Quality Center Connection (QC connection setup should be installed ,the QC connection  setup can be found in QTP setup folder ).
2. Enter QC URL project name/domain/username/password and click on Login. QTP is now connected to QC.


3. Next you can select the save the QTP Script in QC.
4. In QTP, Select File Menu > Save As > Save in QC
5. Select the Folder in QC where you want to save the QTP Script
6. Click OK to Save.

Friday, January 25, 2013

Mercury Timer -- Code from (http://jiteshsojitra.blogspot.in/)

Mercury Timer -- Code from (http://jiteshsojitra.blogspot.in/)

StartTime = MercuryTimers("Timer").Start / 1000
' Operation 1
' Operation 2
EndTime = MercuryTimers("Timer").Stop() / 1000
TotalTime = EndTime - StartTime
Msgbox ""&TotalTime

Wednesday, January 23, 2013

Running Test Cases in QC using QTP

Sometimes it might be required to match the data provided say in an excel with Test case name as in QC while running Automated Test Cases using QTP.Then QTP allows user to create QTP object inside QTP and killing of QTP object or deallocation of QTP object will not affect currently opened QTP.

Function tc_check(TCName)
Set oQTP=createobject("quicktest.application")
QC_Loc=oQTP.Test.Location
bStatus=instr(1,lCase(QC_Loc),trim(lcase(TCName) ) )
if bStatus>0 then
msgbox "matching TC found"
else
msgbox "TC does not match"
end if
oQTP=nothing
End Function

Clean Up for QTP

Sometimes there is a need to kill applications initially which might hamper the current work in hand , every time you run your automation script .

This piece of code in QTP might be helpful :-

SystemUtil.CloseProcessByName "Application Name as in Task Manager.Extension"

Monday, January 21, 2013

Converting Decimal to Whole Number 2 methods : -

1)

x=inputbox("enter a number with decimal")
whole=mid(x,1,instr(1,x,".")-1)
deci=mid(x,instr(1,x,".")+1,len(x))
if mid(deci,1,1) >=5 then whole=whole+1
msgbox whole


2)

x=inputbox("enter a decimal no with 1 digit after the decimal point")
whole=x*10
deci=whole mod 10
whole=whole-deci
whole=whole/10
if deci>=5 then
  whole=whole+1
end if
msgbox whole

Excel Creation using VBS

Example


set xl=createobject("excel.application")
sPath=InputBox("enter path where you want to save the file")

set wb=xl.workbooks.Add
Set ws=wb.worksheets(1) 'sheetname
ws.Name="New Name"

ws.cells(1,1).value="Completed creation of new excel file"

wb.saveas (sPath)
wb.close
xl.quit
Set xl=nothing

Text File Operations in Vbs

Example :

Dim sPath
set fso=createobject("scripting.filesystemobject")
sPath=inputbox("enter path where you want to save the file")

fso.createtextfile sPath
set ctrl=fso.getfile("1.txt")
set mode=ctrl.openastextstream(8)
'1-read
'2-write
'8-append
mode.writeline "hi"
mode.writeblanklines 5
mode.writeline "end"
msgbox "over"
set fso=nothing

Sorting using built in Function

Example :

set a =createobject("system.collections.arraylist")
a.add "5"
a.add "1"
a.add "2"
a.sort
for each i in a
 b=b&i&vbnewline
next
msgbox b