Wednesday, May 27, 2009

General Tips

1. How to put focus on a particular Object?

Window(" Window Name"). winEdit("EditBox Name"). Object.focus

2. Can we merge two or more lines lenght of text into one variable?

Myvar="first line of text"&_
" Second Line of Text"&_
" third Line of Text"&_
" 4th Line of Text"&_
----
----
" Nth Line of text"

msgbox Myvar

Output:- "first line of text Second Line of Text third Line of Text 4th Line of Text ---- ----Nth Line of text"

3. How to capture check Point Result Or Run Action Result?
For check Point:-
CheckPointRunResult=Browser("BrowserName").Page("Page name").WebButton("Name").Check (CheckPoint("Checkpoint Name"))
Msbgox CheckPointRunResult

For Run Action:-
strRunActionResult=RunAction ("ActionName", oneIteration)

4. How to send mail from QC?

Set QCconn = QCUtil.TDConnection
QCconn.SendMail ToList,From,Subject,Body,"", "html"

5. How to Reboot a windows system with QTP code ?

Plese find the code in below Link. http://haripotter.wordpress.com/2008/08/06/how-to-reboot-a-windows-system-using-wmi/

6. how to change default synchronization timeout value with code?

Default Timeout (Test Settings for Object):- Sets or retrieves the delay for finding objects. DefaultTimeOut is a per-test setting

Setting("DefaultTimeout") = 24000 ' Milliseconds

Maximum time in milliseconds to wait before it is determined that an object cannot be found.

Page Load time:-Sets or retrieves the setting for the add to load time option. DefaultLoadTime is a global testing setting. Changes to this setting will be maintained for the remainder of the current testing session.

Setting("DefaultLoadTime") = seconds

'Indicates the time to add, in seconds, to the load time during recording. This option is a safeguard that prevents the test from failing in the event that the amount of time it takes for a page to load during the run session is higher than the amount of time it took during the record session.

Screenshot:- Determines when QuickTest captures and saves images of the application during the test run to display them in the test results.

Setting("SnapshotReportMode") = CaptureValue

' Indicates when the images are captured. The value can be one of the following:
0 - always captures images.
1 - captures images only if an error occurs on the page.
2 - captures images if an error or warning occurs on the page.
3 - never captures images.
Default = 1.

Web Timeout:- Sets or retrieves the delay for navigating to a URL address. WebTimeOut is a per-test setting.

Setting("WebTimeout") = Seconds ' Maximum time in seconds to wait before it is determined that a URL address cannot be found.

WEbPackage :- Configures how to run mouse operations—using browser events or using the mouse. ReplayType is a global testing setting.

Setting.WebPackage("ReplayType") = Setting

Indicates how mouse operations should be run. The value can be one of the following:
1 - Runs mouse operations using browser events.
2 - Runs mouse operations using the mouse.

Convert DATE Format from any Format to Required Format

With below tow ways we can convert date fromat from current format to required date data type format.
way 1:-
Code :-
Dim xlsCurrentDate
Set xlsCurrentDate=GetObject("","Excel.Application")
MsgBox xlsCurrentDate.Text("5/27/2009", "YYYY-MM-DD")
Set xlsCurrentDate=Nothing

OUTPUT :- 2009-05-27

way 2:-
dim Val, DateConvert, formatDate
Val="5/27/2009"
DateConvert=Cdate(Val)
formatDate=Year(DateConvert)&"-"&Month(DateConvert)&"-"& day(DateConvert)
msgbox formatDate

OUTPUT :- 2009-05-27

Tuesday, May 12, 2009

How to get Test parameter value?

I got the information in the below site for Test parameter creation and get value.
syntax for Test paramter value retrive: TestArgs ("Test Parameter Name")

http://qtp.blogspot.com/2007/11/qtp-test-parameters_11.html

Sunday, May 10, 2009

How to "Save As" a existing Script with QTP code?

We can "SaveAs" saved script in Local machine and in Quality Centre with below code.

Dim QTPApp 'As QuickTest.Application ' Declare the Application object variable
Set QTPApp = CreateObject("QuickTest.Application") ' Create the Application object
QTPApp.Launch ' Start QuickTest (if not launched)
QTPApp.Visible = True ' Make it visible
QTPApp.Open “C:\Test1”,True ' Open the test in Edit mode
QTPApp.Test.SaveAs “C:\SaveAsTest” 'Save it with a temporary name (override existing temporary test)
Set QTPApp = Nothing ' Release the Application object

Import file with Pathfinder command.

We can import files (Excel, VBS, XML, etc.) from Local machine and Quality Center to QTP.

First we have to do settings in QTP with below navigation
Tools --> Options --> Folders and click on “+” and add specified folder path.

In code wherever we are using “Import” command there use below code.


Dim QTPApp, SearchPath
Set QTPApp = CreateObject("QuickTest.Application") ' Create the Application Object
QTPApp.Launch ' Start QTP

QTPApp.Folders.Add(“C:\FolderNmae")' Add the folder for Search list

SearchPath=pathfinder.Locate("FileName.xls") ' Locate the folder Path
datatable.ImportSheet SearchPath,1,1
set QTPApp =nothing 'Release the Application Object

Get specific node value from XML file.

We can get parent and child node values with below code.

Val=GetNodeValue ( “C:\XMLfile.XML”,"ParentNodeName","ChildNodeName")
msgbox UBound(Val)

Function GetNodeValue(XMLFilePath,ParentNode,ChildNode)
Dim Obj_Xml,str_ParentNode,list_childs
Dim i,j,str_ParentNodeCnt,str_result()

set Obj_Xml=createobject("MSXml2.DOMDocument.3.0")
Obj_Xml.load XMLFilePath
set str_ParentNode=Obj_Xml.getElementsByTagName(ParentNode)
str_ParentNodeCnt=str_ParentNode.length
ReDim str_result(str_ParentNodeCnt)
msgbox str_ParentNodeCnt
For i=0 to str_ParentNodeCnt-1
set list_childs=str_ParentNode(i).childnodes
for j=0 to list_childs.length-1
If list_childs.item(j).nodename=ChildNode then
str_result(i)=list_childs.item(j).text
Exit for
end if
next
Next
GetNodeValue=str_result
End Function