Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Sunday, April 6, 2014

VERY IMPORTANT UFT/QTP PROGRAMS


VERY IMPORTANT QTP PROGRAMS

'***********************************************************************
' Purpose: Locates the first occurrence of a specified user in the UserList array.
' Inputs: strUserList(): the list of users to be searched.
'         strTargetUser: the name of the user to search for.
' Returns: The index of the first occurrence of the strTargetUser in the strUserList array.
'          If the target user is not found, return -1.
'***********************************************************************
Function intFindUser (strUserList(), strTargetUser)
    Dim i   ' Loop counter.
    Dim blnFound   ' Target found flag
    intFindUser = -1
    i = 0   ' Initialize loop counter
    Do While i <= Ubound(strUserList) and Not blnFound
      If strUserList(i) = strTargetUser Then
         blnFound = True   ' Set flag to True
         intFindUser = i   ' Set return value to loop count
      End If
      i = i + 1   ' Increment loop counter
    Loop
End Function


2)
'With Statement Usage.
With Browser("_______").Page("________")
            .WebEdit("--------")
            .WebEdit("____")
            .WebButton("__")
End With

3)
'VB Window and Java Window Examples
'VbScript
VbWindow("material").VbEdit("Mno").GetRoProperty("text")

'JavaScript
Checkval=JavaWindow("material").JavaEdit("Mno").GetRoProperty("Checked")
If check val="OFF" Then
            JavaWindow("material").JavaCheckBox("Mno").Set "ON"
            else
            JavaWindow("material").JavaCheckBox("Mno").Set "OFF"
    End If
'For items Count and Select every item from Combo Box
Mtypecnt=JavaWindow("material").Javacombobox("Mtype").GetitemsCount
For i=0 to mtypecount-1
'Select a perticular item
JavaWindow("material").JavaCombobox("Mtype").select i
Next
'Sample code to automate the ComboBox
For i=0 to mtypecount-1
mtypeset=Randomno(0,mtypecnt-1)
JavaWindow("material").JavaComboBox("Mno").select Mtypeset
Next

4)
'General DialogBox Script.
Option explicit
Dim x
x=inputbox("Please Enter Password")
Dialog("Login").WinEdit("Agent Name:").Set  "Thirupathi"
Dialog("Login").WinEdit("Password:").SetSecure crypt.Encrypt("x")
Dialog("Login").WinButton("OK").Click

5)
'JavaWindow Script.
JavaWindow("Login").JavaEdit("UserName").Set "Thirupathi"
JavaWindow("Login").JavaEdit("Password").Set Secure "xxxxxxxxxxxxxxxx"
JavaWindow("Login").JavaButton("OK").click
If Javawindow("Flight Reservation").Exist Then
            Reporter.ReportEvent micpass,"Login Step","Login is Successful"
            else
            Reporter.ReportEvent micfail,"Login Step","Login is Unsuccessful"
End If

6)
'Dot Net  Window Script
SwfWindow("Login").SwfEdit("User Name").Set " Thirupathi "
SwfWindow("Login").SwfEdit("Password").Set Secure "xxxxxxxxx"
SwfWindow("Login").SwfButton("OK").click

7)
'VB Window Script
vbwindow("Login").VbEdit("Agent Name:").set " Thirupathi "
Vbwindow("Login").VbEdit("Password:").set "mercury"
vbwindow("Login").VbButton("OK").click

8)
'General Browser Login Script
Browser("Chase Personal Banking").Page("Chase Personal Banking").WebEdit("usr_name").Set ""
Browser("Chase Personal Banking").Page("Chase Personal Banking").WebEdit("usr_password").SetSecure "465fe37e5abb"
Browser("Chase Personal Banking").Page("Chase Personal Banking").Sync
Browser("Chase Personal Banking").Close

9)
'Calling the Reusable Actions.
RunAction "Chase [Invoke]", oneIteration
RunAction "Login [logon]", oneIteration
RunAction "Erase [Erase]", oneIteration

10)
' Handle the Internet Explorer Browser
Set IE=createobject("InternetExplorer.Application")
IE.Visible=True
IE.Navigate2 "F:\ Thirupathi \WEB TESTING Samples\Web Sample\AREVA_V2.12 (G)\contact.htm"
Do
'           DoEvents
Loop While IE.Busy=TRUE
msgbox "Page Loaded.  Now we continue the remaining steps"
IE.GoHome                   'To going for Home Page.
IE.GoSearch                  'To Search the page.
IE.GoBack                      
IE.GoForward
IE.Refresh
IE.Stop
IE.Quit
Set IE=Nothing

11)
'***********************************************************************
'Each description has 3 Properties "Name", "Value" and "Regular Expression".
'Set obj_Desc=description.Create
'obj_Desc("html tag").value="INPUT"
'obj_Desc("name").value="txt.*"
'obj_Desc("name").regularexpression="txt.*"
'***********************************************************************
Set obj_Desc=description.Create
obj_Desc("html tag").value="INPUT"
obj_Desc("name").value="usr_name"
Set obj_Desc1=description.Create
obj_Desc1("html tag").value="INPUT"
obj_Desc1("name").value="usr_password"
Browser("Chase Personal Banking").Page("Chase Personal Banking").WebEdit(obj_Desc).Set "asdf"
Browser("Chase Personal Banking").Page("Chase Personal Banking").WebEdit(obj_Desc1).Setsecure crypt.Encrypt("asdf")

12)
'Find wether the given Number is Even Number or Not.
Option explicit
Dim a
a=inputbox ("Enter the a value ")
If cdbl(a/2)=1 Then
            msgbox a & " is an even number."
else if cdbl(a/2)>1 then
    if cint(a/2)=cdbl(a/2) then
       msgbox a & " is an even number."
else msgbox a & " is an odd number."
     end if
'end if
else 'if cdbl(a/2)<1 then
            msgbox a & " is not an even number."
end if
end If

13)
'Find the Fibonacci Series for a Given Number.
option explicit
dim a,b,f,n,c,d
n=inputbox("Enter a value ")
a=0
b=1
msgbox "The fibonacci series for "& n & " values are "
for f=0 to n-2
c=a+b
msgbox c
reporter.ReportEvent micPass,"result",c
a=b
b=c
next

14)
'Find the Factorial of a Given Number
Dim n
n=inputbox("Provide a number for find the factorial ")
For i=1 to n-1
            n=n*i
Next
msgbox "The factorial of a given number is " & n

15)
'Find Wether the Given Number is Prime or Not
dim a
a=inputbox("Enter a valid number :")
count=1
for i=2 to a-1
if a/i=cint(a/i) then
count=count+1
end if
next
if count>1 then
msgbox a & " is not a prime number."
else
msgbox a & " is a prime number."
end if




16)
'Swap the two Numbers using with & without Third variable.
Dim first,secend,temp
first=inputbox("Enter the first value: ")
secend=inputbox("Enter the secend value: ")
msgbox swap1(first,secend) & "After initial round swapping first and secend numbers are serially: " & first & " and " & secend
Function swap1(first,secend)
   temp=first
   first=secend
   secend=temp
   End Function
  
   Call swap2(first,secend)
Sub swap2(first,secend)
   first=cint(first)+cint(secend)
   secend=cint(first)-cint(secend)
   first=cint(first)-cint(secend)
   msgbox "After secondl round swapping first and secend numbers are serially: " & first & " and " & secend
End Sub

17)
'Program for Find the Sum of a numbers of a given Number.  Eg:Number=156,  Answer=1+5+6=12
Dim numb,i,b,n,c
c=0
i=0
numb=inputbox("Enter a number for sum which is grater than 0")
n=len(numb)
redim a(n)
'numb=randomnumber(1,25)
b=numb
msgbox "The present number is " & b

If b<10 Then
            msgbox "Here we cant devide this number. "
            else
For i=0 to n-1
            'while numb>1
                        numb=numb/10
                        a(i)=cint(numb)-numb
                        numb=numb*10
                        a(i)=a(i)*10
        msgbox "a(" & i & ")=" & a(i)
'                       i=i+1
            '           wend
Next
                        For i=0 to n-1
            c=c+a(i)
                                    'msgbox "a(" & i & ")=" & a(i)
            Next
msgbox "Length of the number is  " & n
msgbox "The sum of a each number in  " & b & " is " & c
end if

18)
'Check The Number of Check Boxes in a Web Page.
Set obj_ChkDesc=Description.Create
obj_ChkDesc("html tag").value="INPUT"
obj_ChkDesc("micclass").value="WebCheckBox"
obj_ChkDesc("type").value="checkbox"

Set allCheckboxes=Browser("Chase Personal Banking").Page("Chase Personal Banking").ChildObjects(obj_ChkDesc)
counting=obj_ChkDesc.count

msgbox counting

For i=1 to counting
            msgbox "i = " & i
  browser("Chase Personal Banking").Page("Chase Personal Banking").webcheckbox(obj_ChkDesc).click
Next


19)
'CHECKING THE LINKS OF A WEB PAGE.
'Check the links which pertaining the html tag property value as "A"
Set oDesc=description.Create()
oDesc("html tag").value="A"
Set chlobj=Browser("MiCOM S1 Support Software").Page("MiCOM S1 Support Software").ChildObjects(oDesc)
links=chlobj.count
msgbox "The no. of links in this page are : "&links
For i=0 to links-1
            mylink=chlobj(i).getroproperty("innertext")
            If mylink<>"Back" Then
                        msgbox "The no. "& cint(i+1) &"  link is: "&mylink
            End If
Next

20)
' Child Object for Image count
set oDesc=description.Create()
oDesc("html tag").value="IMG"
Set chlobj=browser("MiCOM S1 Support Software").Page("MiCOM S1 Support Software").ChildObjects(oDesc)
Elements=chlobj.count
msgbox "The no. of Elements  in this page are : "&Elements
For i=0 to Elements-1
            myElement=chlobj(i).getroproperty("file name")
            If myElement<>"Back" Then
                        msgbox "The no. "&cint(i+1)&" of image  in this page is : "&myElement
            End If
Next

21)
'LINK COUNT CHECKING OF THE WEB PAGE WHICH  CONTAINS  DIFFERENT HTML PROPERTY VALUES
Set oDesc=description.Create()
oDesc("html tag").value="A"
Set objs=description.Create()
objs("innertext").value=""
Set Lists=Browser("MiCOM S1 Support Software").Page("MiCOM S1 Support Software").childobjects(oDesc)
Set List=Browser("MiCOM S1 Support Software").Page("MiCOM S1 Support Software").ChildObjects(objs)
NumberOfLists=Lists.Count()
msgbox "NumberOfLists = "&NumberOfLists
numbers=List.count()
For i=0 to numbers-1
    mylink=List(i).getroproperty("objs")
            msgbox "mylink : "&mylink
Next
msgbox "numbers = "&numbers
totalcount=NumberOfLists+numbers
msgbox totalcount

22)
'HighLight WinButtons Which are Enable.
systemutil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight3a.exe"
dialog("Login").WinEdit("Agent Name:").Set "asdf"
dialog("Login").WinEdit("Agent Name:").Type micTab
dialog("Login").WinEdit("Password:").SetSecure crypt.Encrypt("mercury")
dialog("Login").WinEdit("Password:").Type micReturn

Set oDesc=description.Create()
oDesc("micclass").value="WinButton"
oDesc("enabled").value= -1
'msgbox "oDesc = " & oDesc
Set oDesc1=window("Flight Reservation").ChildObjects(oDesc)
msgbox "oDesc1.count = " & oDesc1.count()

For i=0 to oDesc1.Count-1
            a=oDesc1(i).HighLight
            msgbox "a = " & a
Next
window("Flight Reservation").Activate
'window("Flight Reservation").WinMenu("Menu").Select "File;Exit"


23)
'Select an Item from WebList .
Set IE=createobject("InternetExplorer.Application")
IE.Visible=True
IE.Navigate2 "F:\Santhosh-Testing\saaaaa\From net\ICICI1.htm"
Do
'msgbox "Browser is very busy........."
            Loop while IE.Busy=TRUE

set obj_List=description.create
obj_List("html tag").value="SELECT"
obj_List("name").value="select1"
obj_List("default value").value="Select a Product"
y=Browser("ICICI Bank | Personal").Page("ICICI Bank | Personal").webList(obj_List).GetROProperty("items count")
msgbox "Items in Web List are " & y
For i=1 to y
y=Browser("ICICI Bank | Personal").Page("ICICI Bank | Personal").webList(obj_List).GetItem(i)
Browser("ICICI Bank | Personal").Page("ICICI Bank | Personal").webList(obj_List).Select y
             IE.Visible=True
msgbox "The present item in the WebList (" & i & " )  is " & y
Browser("ICICI Bank | Personal").WinToolbar("ToolbarWindow32").WaitProperty "focused", 0, 20000
             IE.GoBack
   Next
Set IE=Nothing

24)
'Using Regular Expression.
Dim regEx, retVal                            'Create variable.
Set regEx=New RegExp               'Create regular expression.
regEx.Pattern="196[789]"             'Set pattern.
regEx.IgnoreCase=False                                   'Set case sensitivity.
values=datatable.Value(1)
retVal=regEx.Test(values)                                'Execute the search test.
If retval=true Then
            reporter.ReportEvent micpass,"object value checking ","value is correct"
            else
            reporter.ReportEvent micfail,"object value checking ","value is not correct"
End If

25)
'Connect to Oracle Database
Const adOpenStatic=3
Const adLockOptimistic=3
Const adUseClient=3
Set objConnection=createobject("ADODB.Connection")
Set objRecordset=createobject("ADODB.Recordset")
objConnection.Open "DRIVER={Microsoft ODBC for Oracle}; UID=<UID>;PWD=<PWD>"
objRecordset.CursorLocation=adUseClient
objRecordset.CursorType=adopenstatic
objRecordset.LockType=adlockoptimistic
objRecordset.Source="select field1,field2 from testTable"
objRecordset.ActiveConnection=ObjConnection
objRecordset.Open                                   'This will execute your Query
If objRecordset.recordcount>0 Then
            Field1=ObjRecordset("Field1").Value
            Field2=objRecordset("Field2").value
End If

26)
'Check Whether the Logon Image is enabled or not.
chk_passfail=Browser("Chase Personal Banking").Page("Chase Personal Banking").Image("log on").Check(CheckPoint("log on"))
If chk_passfail Then
            msgbox "Check Point passed"
            else
            msgbox "Check Point failed"
End If

27)
'Descriptive for Login first Type
systemutil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight3a.exe"
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").set "asdf"
Dialog("text:=Login").WinEdit("attached text:=Password:").setsecure crypt.encrypt("mercury")
Dialog("text:=Login").WinButton("text:=OK").click

28)
'Descriptive for Open Order in first type.
Window("text:=Flight Reservation").winmenu("menuobjtype:=2").select"File;Open Order..."
Window("text:=Flight Reservation").Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").set"ON"
Window("text:=Flight Reservation").Dialog("text:=Open Order").WinEdit("window id:=1016").set"1"
Window("text:=Flight Reservation").Dialog("text:=Open Order").WinButton("text:=OK").click

29)
'Descriptive for Login in Second Type.
systemutil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

Set oLogin=description.Create
oLogin("regexpwndtitle").value="Login"

Set oEdit1=description.Create
oEdit1("attached text").value="Agent Name:"

Set oEdit2=description.Create
oEdit2("attached text").value="Password:"

Set oButton=description.Create
oButton("regexpwndtitle").value="OK"

systemutil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight3a.exe"
Dialog(oLogin).winEdit(oEdit1).Set "santhubca"
Dialog(oLogin).winEdit(oEdit2).Setsecure crypt.Encrypt("mercury")
Dialog(oLogin).winButton(oButton).Click

if Window("text:=Flight Reservation").exist then
reporter.ReportEvent micpass,"Expected window is ","Existed"
else
reporter.ReportEvent micfail,"Expected window is ","not Existed"
end if

30)
'Descriptive for Open Order in Second Type.
set Window1=description.create()
Window1("text").value="Flight Reservation"
Window1("regexpwndtitle").value="Flight Reservation"

set Menu1=description.create()
Menu1("menuobjtype").value=2

set Dialog1=description.create()
Dialog1("text").value="Open Order"
Dialog1("regexpwndtitle").value="Open Order"

set Checkbox1=description.create()
checkbox1("text").value="&Order No."

set Edit1=description.create()
Edit1("window id").value=1016
Edit1("y").value=188

set Button1=description.create()
Button1("text").value="OK"

Window(window1).Restore
Window(Window1).WinMenu(Menu1).select"File;Open Order..."
Window(Window1).Dialog(Dialog1).WinCheckBox(Checkbox1).set"ON"
Window(Window1).Dialog(Dialog1).WinEdit(Edit1).set"1"
Window(Window1).Dialog(Dialog1).WinButton(Button1).click

31)
'My test fails due to checkpoint failing, Can I validate a checkpoint without my test failing due to checkpoint failure?
'We can validate by using following code.
reporter.Filter=rfDisableAll                       'Disables all the reporting stuff
chk_PassFail=Browser("Chase Personal Banking").Page("Chase Personal Banking").WebEdit("usr_name").Check(CheckPoint("usr_name"))
msgbox "chk_PassFail before Enabled " & chk_PassFail

reporter.Filter=rfEnableAll                        'Enable all the reporting stuff
msgbox "chk_PassFail after Enabled " & chk_PassFail
If chk_PassFail then
            msgbox "Check Point passed"
            else
            msgbox "Check Point failed"
    End If

32)
'By using following statement we can easily skip the run time error here.
On error resume next
val=Datatable("Parameter",1)
If err.number<>0 Then
            'Parameter does not exist
            msgbox "Parameter does not exist : " & val
            else
            msgbox "Parameter existed: " & val
End If

msgbox err.number & " code means " & err.description

33)
'Excel Sheet Creation through COM objective and assign a color here.
Set xlApp=createobject("Excel.Application")
Set xlWorkBook=xlApp.workbooks.add
Set xlWorkSheet=xlWorkbook.worksheets.add
xlWorkSheet.Range("A1:B10").interior.colorindex=20  'Change the color of the cells
xlWorkSheet.Range("A1:A10").value="text"                    'Will set  values of all 10 rows to "text"
xlWorkSheet.Cells(1,1).value="text"                                    'Will set the value of first row and first col
rowsCount=xlWorkSheet.Evaluate("COUNTA(A:A)")     'Will Count the # of rows which have non blank value in the column A
msgbox "The no. of rows that are colored are : " & rowsCount
colsCount=xlWorkSheet.Evaluate("COUNTA(1:1)")        'Will count the # of non blank columns in 1st row
msgbox "The no. oc columns that r counted r:  " & colsCount
xlWorkbook.SaveAs "D:\Documents and Settings\ Thirupathi \Desktop\xl.xls"
xlWorkBOok.close
Set xlworkSheet=Nothing
Set xlWorkBook=Nothing
Set xlApp=Nothing

34)
'Here we add the external library files to the Test\Settings\Recorces
Option explicit
Dim a,b
a=inputbox("Enter a value:")
b=inputbox("Enter b value:")
msgbox "add of "&a&" and "&b&" is "&add(a,b)                'Function Call
call mul(a,b)                                                                                        'Procedure Call

35)
'Here We Call the function in Local.
Option explicit
Dim a,b,user
a=inputbox("Enter a value:")
b=inputbox("Enter b value:")
user=maths(a,b)
msgbox user
Function maths(arg1,arg2)
   maths=arg1*arg2
End Function

36)
'Here we call the Procedure in Local.
Option explicit
Dim c
Call maths(5,7)
Sub maths(arg1,arg2)
  c=arg1*arg2
msgbox c
End Sub

37)
To make Reusable Action: After creating an action Action\Action call properties\Check Reusable
To Call Reusable Action: Open a new page there Insert\Call to Existing Action.

38)
'Find the boundaries of an array.
Option explicit
Dim a
a=array(10,"peers",3.14)
msgbox a(0)
msgbox a(1)
msgbox a(2)
'Boundaries of an array.
msgbox "ubound= "&ubound(a)
msgbox "lbound= "&lbound(a)
'Join:  Simply used to join elements of array.
msgbox join(a)
'With the following statement entire array will be erased.
Erase a

39)
'Initializing the Dimentianal Array.
Dim a(2,2)
a(0,0)=10
a(0,1)="peers"
a(0,2)=3.14
msgbox a(0,0)

40)
'Working with File System Object. sample script to create text log file.
'Const ForReading = 1, ForWriting = 2,ForAppending=8
'TristateTrue ----------Open the file as Unicode.
'TristateFalse------------- Open the file as ASCII.
'TristateUseDefault -------------Open the file using the system default.
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile=fso.createtextfile("F:\ Thirupathi \QTP\Peers\Flat Files\ Thirupathi.txt")
'Set MyFile = fso.OpenTextFile("F:\ Thirupathi \QTP\Peers\Flat Files\ Thirupathi.txt", ForWriting, True)
MyFile.WriteLine "Hello world!"
MyFile.WriteLine "The quick brown fox"
MyFile.WriteLine "The quick brown fox"
MyFile.writeline"Machine Name: "&Environment.Value("LocalHostName")
MyFile.Close
Set MyFile = fso.OpenTextFile("F:\\ Thirupathi \QTP\Peers\Flat Files\ Thirupathi.txt", ForReading)
'Set MyFile = fso.OpenAsTextStream(ForReading, TristateUseDefault)
   TextStreamTest = MyFile.ReadLine
 ReadLineTextFile = MyFile.Readline          ' Returns "Hello world!"
msgbox ReadLineTextFile
   'ReadLineTextFile = MyFile.ReadLine    ' Returns "Hello world!"
   'msgbox ReadLineTextFile
  MyFile.Close

41)
'Importing the External Data to the Current test and Utilize that Data.
datatable.import("D:\Documents and Settings\ Thirupathi \Desktop\A.xls")
rc=datatable.GetRowCount
msgbox rc
For i=1 to rc
            datatable.SetCurrentRow(i)
    window("Window").winobject("edit").set datatable("Num1",dtglobalsheet)
            window("Window").winobject("edit_2").set datatable("Num2",dtglobalsheet)
            window("Window").winbutton("add").click
            expresult=datatable("expresu",dtglobalsheet)
            actresult=window("Window").WinObject("edit_3").getroproperty("text")
            datatable.Value("Actresult",1)=ActResult
            If ExpResult=ActResult  Then
                        datatable.Value("Actresult",1)="pass"
                        else
                        datatable.Value("Actresult",1)="fail"
            End If
Next
datatable.Export("D:\nnr\output.xls")

42)
'The following statements will display the date and time in different formats
msgbox "formatdatetime(date,0)="&formatdatetime(date,0)
msgbox "formatdatetime(date,1)="&formatdatetime(date,1)
msgbox "formatdatetime(date,2)="&formatdatetime(date,2)
msgbox "formatdatetime(date,3)="&formatdatetime(date,3)

43)
'***********************************************************************'
The following four lines are used for flat file declaration of an Environment variable, here the file must be saved with .ini extension.
'[Environment]
'User=asdf     
'Password=mercury
'path="D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight3a.exe"
'***********************************************************************environment.LoadFromFile("D:\Documents and Settings\ Thirupathi \Desktop\a.ini")
systemutil.Run environment.Value("path")
Dialog("Login").WinEdit("Agent Name:").Set environment("User").value
Dialog("Login").WinEdit("Password:").SetSecure environment.Value("Password")
Dialog("Login").WinButton("OK").Click

'***********************************************************************
'The following code for "Check if a environmentvariable exist or not"
'val=Environment("User").Value
'msgbox val
'***********************************************************************

44)
'Here we call the Environment variables from Test\settings\Environment\Export\peers\Login.xml file
SystemUtil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set Environment.Value("AgentName")
Dialog("Login").WinEdit("Password:").SetSecure Environment.Value("Password")
Dialog("Login").WinButton("OK").Click

45)
'Array Declaration and increase the array size in middle.
Dim x,a
x=inputbox("Enter x value:")
a=array(10,"peers",3.14)
msgbox "All the elements of array are: "&join(a)
msgbox "lbound of array is "&lbound(a)
msgbox "ubound of array is "&ubound(a)
ReDim preserve a(5)
a(5)=18
msgbox "After inserting extra element into array than a(5)="&a(5)
msgbox "All the elements of array are: "&join(a)
For i=0 to 2
            msgbox a(i)
Next



46)
'Check the Object Runtime Property.
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
ExpHeight=20
ActHeight=Dialog("Login").WinEdit("Agent Name:").GetROProperty("height")
msgbox "ActHeight="&ActHeight
If ActHeight=ExpHeight Then
            Reporter.ReportEvent micpass,"Login Step","Passed"
            else
            reporter.ReportEvent micfail,"Login Step","Failed"
End If

47)
'Retrieve the Objective Properties from Object Repository.
Set TheTestObject=window("Flight Reservation")
Set Properties=TheTestObject.GetToProperties
PropsCount=Properties.Count
msgbox "PropsCount="&PropsCount
For i=0 to PropsCount-1
            PropName=Properties(i).Name
            PropValue=Properties(i).value
    msgbox "Here No. "&i+1&" Property is "&"                       PropName=  "&PropName&"              PropValue=  "&PropValue
Next

48)
'A simple program for retrieve the Test Object(TO) property.
var=dialog("Login").WinEdit("Agent Name:").GetTOProperties("attached text")
msgbox "Properties of attached text is "&var

49)
'After creating the following program, we make it as Reusable action. Here a, b & c are ‘used for input  and out put variables.
Option explicit
Dim var1,var2
var1=parameter("a")
var2=parameter("b")
msgbox var1
msgbox var2
parameter("c")=15

‘Call the above action from here
RunAction "InputOutput", oneIteration, "20", "30", x
msgbox x






50)
‘The following are Datatable Properties

'This is used to add a new sheet to the datatable.
datatable.AddSheet("sheet1")

'This method is used to delete a sheet from the datatable
datatable.DeleteSheet("action1")

'This method is used to export the content of a data to a specified excelsheet(It will create ‘a file if the file if specified is not available).
datatable.Export("D:\Documents and Settings\ Thirupathi \My Documents\a.xls")

'This method is used to get the current active row number
var=datatable.GetCurrentRow
msgbox var

'This method is used to get total no.of records from the datatable
var=datatable.GetRowCount
msgbox var

'Example
'The following example uses the GetSheet method to return the "MySheet" sheet of the ‘run-time Data Table in order to add a parameter to it.
'MyParam=DataTable.GetSheet ("MySheet").AddParameter("Time", "8:00")
'You can also use this to add a parameter to the "MySheet" local sheet (note that no value ‘is returned).
'DataTable.GetSheet ("MySheet").AddParameter "Time", "8:00"
'This method is used to get the current active sheet
var=datatable.GetSheet("Global").addparameter("add","dfjkljld")
msgbox var
'OR
var=datatable.GetSheet("Action1").addparameter("sub","fkhdh")
msgbox var

'This method is used to set the focus on the no of sheets available in Data table
var=datatable.GetSheetCount
msgbox var

'This method is used to import the contents of an external file into the datatable
datatable.Import("D:\Documents and Settings\ Thirupathi \My Documents\a.xls")

'This method is used to import the contents of a specified sheet of  external file to the ‘specified datatable
'DataTable.ImportSheet "C:\name.xls" ,1 ,"name"
datatable.ImportSheet"D:\Documents and Settings\ Thirupathi \My Documents\a.xls",1,a

'This method is used to set the focus on a specified row in local sheet
datatable.SetCurrentRow(10)



'This method is used to set the focus to the next row of  the current active row
datatable.SetNextRow
DataTable.GetSheet("Action1").SetNextRow

'This method is used to set the focus to the previous row of the current active row.
var=datatable.SetPrevRow
msgbox var

'This method is used to set  or retrieve the value to or from a specified parameter of a ‘specified sheet in the datatable.
datatable.Value("A",1)="pass"
variable=datatable.Value("A",1)

51)
'Program for use the Output Values.
Window("Flight Reservation").WinEdit("Tickets:").Output CheckPoint("Tickets:")
Window("Flight Reservation").WinEdit("Price:").Output CheckPoint("Price:")
Window("Flight Reservation").WinEdit("Total:").Output CheckPoint("Total:")
a=datatable("Tickets",dtglobalsheet)
b=datatable("Price",dtglobalsheet)
b=mid(b,2,len(b)-1)                                              'mid(variable,position,length)
c=datatable("Total",dtglobalsheet)
c=mid(c,2,len(c)-1)
msgbox "a="&a&","&vbnewline&"b="&b&"  and  "&vbnewline&"c="&c
If cdbl(c)=cint(a)*cdbl(b) Then
            reporter.ReportEvent micpass,"Result is ","Pass."
            else
            reporter.ReportEvent micfail,"Result is ","Fail."
End If

52)
'String Comparision method
Option explicit
Dim str1,str2
str1="kdfh"
str2="fhsdfj"
msgbox strcomp(str1,str2)
'Here Ans is 0 for pass or 1 for Fail.

53)
'Program for String Functions
Dim str1,str2
str1="peers"
str2="Technologies"
msgbox "Length of str1 is "&len(str1)
msgbox "Certain left part of str2 is "&left(str2,5)
msgbox "Certain right part of str2 is "&right(str2,5)
'msgbox "middle part of str2 is "&mid(str2,2,len(str2)-2)
'OR
msgbox "middle part of str2 is "&mid(str2,2,6)

msgbox "Comparision of strings is "&stringcomp(str1,str2)
msgbox "Replacing of certain letter in a "&str1&"  is "&replace(str1,"ee","e")

'The following example uses the ToString method to generate a report listing the string ‘representation of the test object.
var=Dialog("Login").WinButton("OK").ToString
msgbox var

'It gives the output as "OK button"

54)
'Program for Utilizing the Insert\Transaction for count the time
Window("Program Manager").WinListView("SysListView32").Activate "Shortcut to flight3a"
Dialog("Login").WinEdit("Agent Name:").Set "asde"
Dialog("Login").WinEdit("Password:").SetSecure "467782762ae98400951b2309a4412d248f91f9f4"
Dialog("Login").WinButton("OK").Click
Services.StartTransaction "T1"
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "6"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Type  micReturn
Services.EndTransaction "T1"
Window("Flight Reservation").WinButton("Button_2").Click
Window("Flight Reservation").Close

55)
'While Loop Utilization.
Option explicit
Dim counter,check
counter=0
While (counter<=10)
            counter=counter+1
            msgbox "counter= "&counter
Wend

'Do While Loop Utilization
check=true
counter=0
Do while counter<20
            counter=counter+1
    If counter=10 Then
                        check=false
                        Exit do
            End If
            msgbox "counter= "&counter
            loop
'loop until check=false


56)
'Utilizing the Data from Datatable.
Window("Program Manager").WinListView("SysListView32").Activate "Shortcut to flight3a"
Dialog("Login").WinEdit("Agent Name:").Set datatable.Value("UserId",dtglobalsheet)
Dialog("Login").WinEdit("Password:").SetSecure datatable.Value("Password",dtglobalsheet)
Dialog("Login").WinButton("OK").Click
If window("Flight Reservation").Exist Then
            reporter.ReportEvent micpass,"Flight Reservation Window ","existed."
            else
            reporter.ReportEvent micfail,"Flight Reservation Window ","not existed."
End If

Window("Flight Reservation").Close

1 comment:

Loading...