Tuesday, December 21, 2010

Running a test set through OTA API

‘Option Explicit

Public Sub RunTestSet(otdc, tsFolderName, tSetName, _
HostName, runWhere)

Dim TSetFact, tsList
Dim theTestSet
Dim tsTreeMgr
Dim tsFolder
Dim Scheduler
Dim nPath
Dim execStatus

‘ Get the test set tree manager from the test set factory
‘tdc is the global TDConnection object.
Set TSetFact = otdc.TestSetFactory
Set tsTreeMgr = otdc.TestSetTreeManager
‘ Get the test set folder passed as an argument to the example code
nPath = “Root\” & Trim(tsFolderName)
Set tsFolder = tsTreeMgr.NodeByPath(nPath)
If tsFolder Is Nothing Then
err.Raise vbObjectError + 1, “RunTestSet”, “Could not find folder ” & nPath
End If

‘ Search for the test set passed as an argument to the example code

Set tsList = tsFolder.FindTestSets(tSetName)

If tsList Is Nothing Then
err.Raise vbObjectError + 1, “RunTestSet”, “Could not find test set in the ” & nPath
End If

If tsList.Count > 1 Then
MsgBox “FindTestSets found more than one test set: refine search”
Exit Sub
ElseIf tsList.Count < 1 Then
MsgBox “FindTestSets: test set not found”
Exit Sub
End If
Set theTestSet = tsList.Item(1)
‘Debug.Print theTestSet.ID

‘Start the scheduler on the local machine
Set Scheduler = theTestSet.StartExecution(HostName)

‘Set up for the run depending on where the test instances
‘ are to execute.

Select Case runWhere
Case “RUN_LOCAL”
‘Run all tests on the local machine
Scheduler.RunAllLocally = True
Case “RUN_REMOTE”
‘Run tests on a specified remote machine
Scheduler.TdHostName = HostName
‘ RunAllLocally must not be set for
‘ remote invocation of tests.
‘ Do not do this:
‘ Scheduler.RunAllLocally = False
Case “RUN_PLANNED_HOST”
‘Run on the hosts as planned in the test set
Dim TSTestFact, TestList
Dim tsFilter
Dim TSTst
‘Get the test instances from the test set
Set TSTestFact = theTestSet.TSTestFactory
Set tsFilter = TSTestFact.Filter
tsFilter.Filter(“TC_CYCLE_ID”) = theTestSet.ID
Set TestList = TSTestFact.NewList(tsFilter.Text)
Scheduler.RunAllLocally = False
End Select

‘Run the tests
Scheduler.run

Set execStatus = Scheduler.ExecutionStatus

While (RunFinished = False)
execStatus.RefreshExecStatusInfo “all”, True
RunFinished = execStatus.Finished
Wend
End Sub

‘================================

Const qcHostName = “”
Const qcDomain = “”
Const qcProject = “” ‘Please define here the name of the project
Const qcUser = “” ‘Please define here the username
Const qcPassword = “” ‘Please define here the password
Dim tdc
Dim qcServer
Dim objArgs
Dim strArg
Dim strTestSet
Dim bRunCode

‘======GETTING ARGUMENTS==============
set objArgs = WScript.Arguments
If WScript.Arguments.Count<1 Or WScript.Arguments.Count>2 Then
WScript.Echo “Please enter the name of the test set”
bRunCode = False
Else
For Each strArg in objArgs
WScript.Echo strArg&” is starting…”
strTestSet = strArg
bRunCode = True
Next
End If
‘===========================================================

If bRunCode Then
qcServer = “http://” & qcHostName
qcServer = qcServer & “/qcbin”
Set tdc = CreateObject(“tdapiole80.tdconnection”)

If (tdc Is Nothing) Then
MsgBox “tdc object is empty”
End If

tdc.InitConnectionEx qcServer
tdc.Login qcUser, qcPassword
tdc.Connect qcDomain, qcProject

RunTestSet tdc, “Insert here path to the test set”, strTestSet , “Insert here the name of the machine”, “RUN_LOCAL”

‘Disconnect from the project
If tdc.Connected Then
tdc.Disconnect
End If
‘Log off the server
If tdc.LoggedIn Then
tdc.Logout
End If
‘Release the TDConnection object.
tdc.ReleaseConnection
”Check status (For illustrative purposes.)
Set tdc = Nothing
End IF

Tuesday, November 9, 2010

editing a registry file with VBScript

Option Explicit
'Declare variables
Dim WSHShell, rr, rr2, MyBox, val, val2, ttl, toggle
Dim jobfunc, itemtype
On Error Resume Next
Set WSHShell = WScript.CreateObject("WScript.Shell")
val = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"
val2 = "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"
itemtype = "REG_DWORD"
jobfunc = "Registry Editing Tools are now "
ttl = "Result"
'reads the registry key value.
rr = WSHShell.RegRead (val)
rr2 = WSHShell.RegRead (val2)
toggle=1
If (rr=1 or rr2=1) Then toggle=0
If toggle = 1 Then
WSHShell.RegWrite val, 1, itemtype
WSHShell.RegWrite val2, 1, itemtype
Mybox = MsgBox(jobfunc & "disabled.", 4096, ttl)
Else
WSHShell.RegDelete val
WSHShell.RegDelete val2
Mybox = MsgBox(jobfunc & "enabled.", 4096, ttl)
End If

Thursday, November 4, 2010

Schedule/execute testset run in Quality Center from Windows (VBScript)

http://the-koala-egg.blogspot.com/2008/02/scheduleexecute-testset-run-in-quality.html
-----------------
VBScript:

Dim QCConnectionSet
QCConnection = CreateObject("TDApiOle80.TDConnection")



QCConnection.InitConnectionEx "server_address" ' <--------------- Fill in server addressQCConnection.login "user", "pwd" '<------------------- FILL in user/pwd

QCConnection.Connect "domain_name", "project_name" '<----------- FILL Domain/Project

Set TSetFact = QCConnection.TestSetFactory
Set tsTreeMgr = QCConnection.TestSetTreeManager
nPath = "Root\test" '<------------- FILL IN PATH TO TESTSET

Set tsFolder = tsTreeMgr.NodeByPath(nPath)
If tsFolder Is Nothing Then
msgbox "error"

End If


Set tsList = tsFolder.FindTestSets("name_of testset") '<------- FILL IN NAME OF TESTSET
If tsList.Count > 1 Then
MsgBox "FindTestSets found more than one test set: refine search"
ElseIf tsList.Count <>
MsgBox "FindTestSets: test set not found"
End If


Set theTestSet = tsList.Item(1)
Set Scheduler = theTestSet.StartExecution("")
Scheduler.RunAllLocally = True
Scheduler.HostTimeOut = 100000
Scheduler.runSet execStatus = Scheduler.ExecutionStatus

RunFinished = False
while RunFinished = False
execStatus.RefreshExecStatusInfo "all", True
RunFinished = execStatus.Finished

wend

QCConnection.Disconnect
QCConnection.Logout
Set QCConnection = Nothing

---------------

Wednesday, October 27, 2010

creating a new database using vbscript

Set oConn = CreateObject( "ADOX.Catalog" )



oConn.Create "Provider = Microsoft.Jet.OLEDB.4.0; " & _

"Data Source = new_db.mdb"

how to retreive data from a database

Dim oConn, oRst, oField

Dim sql



set oConn = CreateObject("ADODB.Connection")

oConn.Open "QT_Flight32"

set oRst = CreateObject("ADODB.recordset")

oRst.Open "Select * from Orders", oConn

Do Until oRst.EOF

For each oField in oRst.Fields

Print oField.Name & " = " & oField.Value

Next

Print String( 20, "-" )

oRst.MoveNext

loop



oRst.close

oConn.close

http://www.advancedqtp.com/knowledge-base/qtips/databases-id44/adodb/display-records/

Tuesday, October 26, 2010

automating google earth using QTP

There is good article mentioned in advancedqtp.com. It says that it can be automated and here is the URL
http://www.advancedqtp.com/knowledge-base/articles/environment-techniques-id15/web-id34/automating-google-earth/

Can we test mobile applications in the mobile phone

The question is discussed in several forums here I am giving the URLs of the respective forums.

http://www.jamosolutions.com/documents/meuxqtp.html

http://experitest.com/support/tutorial/how-to/set-up-new-project/connect-an-external-device-e-g-android/ - advancedqtp.com

Friday, October 15, 2010

Exporting a OR file to an XML file

The below code snippet helps to export TSR file to XML file.
Set obj = CreateObject("Mercury.ObjectRepositoryUtil")
obj.ExportToXML "SourceFile", "TargetFile"
Set obj = Nothing

Wednesday, October 6, 2010

Intellisense quick help

http://www.advancedqtp.com/knowledge-base/articles/qtp-tricks4/qtp-hacks/intellisense-and-com/#
---------------------------------------------------------------------------------------
http://www.sqaforums.com/showthreaded.php?Cat=0&Number=408757&page=0&vc=1

Tuesday, October 5, 2010

Adding Scripting.Disctionary object in registry

Accessing a Scripting.Dictionary object as part of your QTP and can get the intellisense

HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\

There you’ll see many of QTP’s internal object. DO NOT MESS WITH THEM.
Next, create a new key, with the name of the reserved object (e.g. Advanced QTP)


Enter the key "folder", and create these values :
ProgID (string) - Holds the COM program ID we want to create (e.g. Scripting.Dictionary)
VisibleMode (dWord) - Holds the value 2. This controls the auto-complete and intellisense appearance.
UIName (string) - The name that will refer to the reserved object. Make sure this is the same as the key name.

http://www.advancedqtp.com/knowledge-base/articles/qtp-tricks/qtp-hacks/reserved-objects-as-an-env-object-replacement/

Refer the above link for more details. Thanks to Yaron for his help in advanceqtp.com

Monday, October 4, 2010

Retrieving data from an excel through Database connection

FileName = "C:\Book1.xls"
SheetName = "Sheet1"
vValue = "Murali"

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & FileName & ";" & "Extended Properties=""Excel 8.0;HDR=Yes;"";"
strQuery="update [" & SheetName & "$] Set "
strQuery=strQuery & "Country='" & "',"
strQuery=strQuery & "City='" & "'"
strQuery=strQuery & " where Name ='" & vValue &"'"
msgbox strQuery
objRecordset.Open strQuery , objConnection, 3, 3, 1
'Close
objConnection.Close
Set objRecordSet = Nothing

Associating a library file using QTP object model

Dim qApp
Dim qLibs

Set qApp = CreateObject("QuickTest.Application")
qApp.Launch
qApp.Visible = True

qApp.Open "E:\Test1", False, False ' Open a test

Set qLibs = qtApp.Test.Settings.Resources.Libraries ' Get
the libraries collection object
qLibs.Add "C:\Utilities.vbs", 1 ' Add the library to the
collection

qApp.Test.Save
qApp.Quit
Set qLibs = Nothing
Set qApp = Nothing

Retrieving the current time zone information

Here is the simple code snippet to find out the current time zone

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
strValueName = "StandardName"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,strValue
Set oReg=Nothing
Msgbox(strValue)

Sunday, June 6, 2010

Object Repository v/s Descriptive Programming

While automating the application the most common question is Should we use Object Repository or Descriptive Programming.

The answer is, It is completely dependent on the Application nature, size of the automation and the framework followed.

Lets assume there is an application where in around 100 dynamic pages are there. In them there are several GUI elements(objects) are there. But most of the objects(and their properties) are same across multiple pages. Like date fields, input fields and web tables. But page titles are different.

1)To automate this application If we go with OR approach we have to create a huge object repository and which intern occupies lot of memory and maintenance issues.

2)If per action is used huge effort goes in merging the object Repository.

3)If there are lot of dynamic objects for example when user logged in, the user id is displayed as link in the home page.

In the above scenarios Descriptive programming is the right approach.

Problems with Descriptive programming
1)If the descriptive objects are not created in a right approach it may result huge maintenance issue.
2)Script generation would take time as the Object repository is not available.

Some times due to framework limitations Descriptive programming cannot be used at that time the following ways can help to modify the objects in run time.

-> Use regular expression for the objects which are dynamic
-> Use SetToProperty to modify/add object property in run time.

We will discuss more about SetToProperty in another post.

The conclusion what I want to say is Object Repository or Descriptive programming both has their own pros/cons. As per the need one should choose the approach.

And at the same time both approaches can be used in automation of any application.

Using Descriptive Programming

-> Assume there is an object in a page the descriptive approach is
Browser("micClass:=Browser,title:=XXX").page("title:=xxx").webbutton("text:=xyz").set "abc"

The same also can be achieved
set obj_browser = description.create()
obj_browser("title").value = "XXX"

set obj_browser = description.create()
obj_browser("title").value = "xxx"

I will discuss more about descriptive programming in another post.

Feel free to contact me for any kind of queries mura.kunda@gmail.com

Monday, May 10, 2010

Action v/s Function

When developing an automation framework everyone thinks whether they should go for Action based Framework or Function based Framework.

Both of them has their own Pros/Cons. But Function based framework is more robust and flexible and easily maintainable. Depending on the Licensing feasibility and Resource skill set either one can decide Functions or Actions.

Major Differences
Actions
1.Actions are part of Quick Test Professional
2.Actions has their own object Repositories and Data sheets. Handling Object Repositories and Data Sheets are much easier.
3.Parameters to an Action can be passed through only Input parameters and these parameters have to declared in the Action settings.
4.Action always return Boolean. If any custom value needs to be returned then it has to be returned as Output parameter which is again part of Action Setting
5.Well Integrated with QTP. It occupies much more memory compare to Functions
6.Cannot pass the value By Ref or By Val.
7.QTP Intellisense is available
8.QTP Editor is required to write the code.

Functions
1.Purely part of VBScripting
2.No Object Repository or Data Sheets are available
3.Parameters can be passed as Byval or ByRef
4.Only one variable can be returned.
5.Independent to QTP
6.Occupies Less memory intern increases the performance of the Execution
7.Need to be associated with QTP
8.Scripting would be slow as QTP Intellisense is not available
9.QTP License is not required as we can use simple NotePad as an Editor

Monday, May 3, 2010

Sending a mail through QC using API

The below function helps to send mail from QC automatically with attachment

Public function sendMail(toMail,fromMail,subj,body,attachment)
Set qcCon = qcutil.QCConnection
qcCon.sendmail toMail,fromMail,subj,body
Set qcCon = nothing
End Function

Connecting and disconnectingto QC through API

The following function helps to connect QC

public function connectToQC(qcUserName, qcPwd, qcURL, qcDomain, qcProject)
Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx qcURL
tdc.Login qcUsername, qcPwd
tdc.Connect qcDomain, qcProject
if tdc.connected then
connectToQC = 0
else
connectToQC = 1
end if
set tdc = nothing
end function

The following function helps to disconnect from QC

public function disconnectQC()
Set tdc = CreateObject("TDApiOle80.TDConnection")
If tdc.Connected Then
tdc.Disconnect
End If
If tdc.LoggedIn Then
tdc.Logout
End If
set tdc = nothing
end function

Tuesday, April 20, 2010

Diiferent ways accessing data from an excel file

There are mainly 3 ways that we can access data from an excel file. Before using the below methods please create file calles Sample.xls in C:\ Drive

1. Data table
2. Using Excel Application COM methods
3. Using Database Connection methods.

1. Data Table :
Data Table is the quickest way to access data from any excel file and there are couple of methods provided by QTP. I am listing few of the methods.
1. datatable.import
2. datatable.importsheet
3. datatable.addsheet
4. datatable.getSheet
QTP has comprehensive help on the above topic

2. Excel Application COM methods
The second of accessing data from an excel file is by creating a Excel instance and with the help of that we can access the data of an excel.
Creating a excel file and sheet
Set xlObj= CreateObject("Excel.Application")
Set xlBook = xlObj.Workbooks.Add
set xlSheet = xlBook.worksheets.Add
xlObj.worksheets(4).name = "SampleSheet"
xlBook.SaveAs("C:\sample.xls")
set xlObj = nothing
set xlBook = nothing
set xlSheet = nothing

3. Excel application with Database connection
Const varStatic = 3
Const varLock = 3
Const varCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\sample.xls; Extended Properties=""Excel 8.0;HDR=Yes;"";"

objRecordset.Open "Select * FROM [Sheet1$]", objConnection, varStatic, varLock, varCmdText

Do Until objRecordset.EOF
print objRecordset.Fields.Item("ColumnName1")

objRecordset.MoveNext
Loop

Set objConnection = nothing
Set objRecordSet = nothing

Thursday, April 8, 2010

Creating custom dll file and using the same in QTP

Hi

Here I am discussing how to create a custom dll files using C#.

Pre requisites: Install Visual studio 2005 or 2008


  1. Create Class library file

  2. Create a class and their methods

  3. Make the class as COM visible

  4. Save it and build the file

  5. Register the DLL with Registry using RegASM

  6. Use the DLL in the QTP code.

Let's see the explanation of each step

1. Create Class library file :

Goto File->Add->New Project and select Class library file
Enter the Library File name
I am giving a class library name as "Framework"

2.Create a class and their methods
Write the code as below in the Library file

public class Utilitiess
{
public int i;
public int add(int a, int b)
{
return a+b;
}
public int subtract(int a, int b)
{
return a - b;
}
}

3. Make the class as COM visible
3.1 Right click on the Class Libray name.
3.2 In our case Right click on "Framework"
3.3 Click on Applications tab and Clcik on Assembly Information button
3.4 Select making com visible check box
3.5 Clck Save all button
4. Build the project
5. Registering the DLL with Registry
5.1 The DLL file would be stored in the Visual Studio Debug folder
5.2 Copy the DLL files to .NET framework tool kit folder
5.3 Open SDK Command prompt by selecting Start->Programs->Microsfot .net Framework
5.4 Entet the command RegAsm
6.Using the DLL in QTP
6.1 Use the following code to use the code in the code
set obj = createobject("Framework.Utilities")
i = obj.Add(2,3)
print i