qtpscripts

'invoke notepad
test wordpad font
'add n multiply
'arrays
'checkpoint
'child objects
'data driven
'get number of records
''datadriven write

'create descriptive programme
'Excercise1 Array of foods
''excercise2 array into file
'printf
'str compare
''''Ui-vbs
batch
case
'OpenTextFile example
'shell
excell
exitt
''food

''get text
''loading in memory
load properties in to memory-localisation
'get number of records
'''localisation
'''register
spreadsheet
string
'''translation
'get number of records
'''data drivenn get property

'invoke notepad

SystemUtil.Run "c:\windows\notepad.exe"
With Window("Notepad")
.WinEditor("Edit").SetCaretPos 0,0
.Resize 555,487
.Move 616,112
.Move 436,186
End With

'notepad main
RunAction "Start Notepad [InvokeNotepad]", oneIteration
'enter text'
With Window("Notepad")
.WinEditor("TextArea").SetCaretPos 0,0
.WinEditor("TextArea").Type "portnov computer school"
.WinEditor("TextArea").Type micHome
RunAction "Test Find dialog [NotepadFind]", oneIteration
End With
'notepad find
With Window("Notepad")
.WinMenu("Menu").Select "Edit;Find... Ctrl+F"
With .Dialog("Find")
.WinButton("Find Next").Click
.Close
End With
End With

test wordpad font
With Window("WordPad")
.WinMenu("Menu").Select "Format;Font..."
With .Dialog("Font")
.WinComboBox("Font:").Select Parameter("fontName")
.WinButton("OK").Click
End With
End With

Window("WordPad").Close






'add n multiply

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function

Private Const ADD_NUMBERS =0
Private Const MULTIPLY_NUMBERS = 1
Function calculateNumbers (num1, num2, MODE)
Dim result
If (MODE = ADD_NUMBERS) Then
result = num1+ num2
elseif MODE = MULTIPLY_NUMBERS Then
result = num1 * num2
End If
calculateNumbers =result
End Function

Dim A,B

A = calculateNumbers(5,4, ADD_NUMBERS)
B = calculateNumbers(5,4, MULTIPLY_NUMBERS)
Printf (A)
Printf (B)
f1.close








'arrays
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function

'initialize array
Dim profile(3)
'Dim profile
' profile = Array("", "", "")
profile(0) = "Portnov"
profile(1) = "El Camino"
profile(2) = "Mountain View"

Dim array
Dim y
For y = 0 To 3
printf profile(y)
Next





'checkpoint

Window("Notepad").WinEditor("Edit").SetCaretPos 0,0
Window("Notepad").WinEditor("Edit").Type "Helloworld"
Window("Notepad").WinMenu("Menu").Select "Edit;Find... Ctrl+F"
Window("Notepad").Dialog("Find").Check CheckPoint("Find_2")
Window("Notepad").Dialog("Find").WinEdit("Find what:").Set "world"




'child objects

Set MyDescription = Description.Create()
MyDescription("nativeclass").value = "Button"
MyDescription("checked").value = "OFF"

Window("WordPad").Activate

Window("WordPad").WinObject("RichEdit20W").Type "fdfd"
Window("WordPad").WinMenu("Menu").Select "Edit;Replace... Ctrl+H"


'Window("WordPad").Activate
'Window("WordPad").WinObject("fdfd").Type "fdfd"
'Window("WordPad").WinMenu("Menu").Select "Edit;Replace... Ctrl+H"

Set checkboxes = Window("WordPad").Dialog("Replace").ChildObjects(MyDescription)
numcheckboxes = checkboxes.count
For counter = 0 to numcheckboxes
checkboxes(counter).Set "ON"
Next









'data driven


Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function

Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablePath = "c:\users.xls"

'DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)


for x = 0 to numRows
DataTable.SetCurrentRow( x+1)
username = DataTable.Value("USER_NAME")
company = DataTable.Value("COMPANY")
first = DataTable.Value("FIRST_NAME")
last = DataTable.Value("LAST_NAME")
address = DataTable.Value("ADDRESS")
printf(username)
printf(company)
printf(first)
printf(last)
printf(address)
next


' login(username, "password")


SystemUtil.Run "c:\qtp_test.txt"









''datadriven write

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function

Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablePath = "c:\users.xls"

'DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)


for x = 0 to numRows
DataTable.SetCurrentRow( x+1)
username = DataTable.Value("USER_NAME")
company = DataTable.Value("COMPANY")
first = DataTable.Value("FIRST_NAME")
last = DataTable.Value("LAST_NAME")
address = DataTable.Value("ADDRESS")
printf(username)
printf(company)
printf(first)
printf(last)
printf(address)
next


' login(username, "password")


SystemUtil.Run "c:\qtp_test.txt"





'descriptive programme

Set MyDescription = Description.Create()
MyDescription("text").value = "Cancel"
'MyDescription("Class Name").value = "WinButtton"


With Window("Notepad")
.Activate
.WinMenu("Menu").Select "Edit;Replace... Ctrl+H"
.Dialog("Replace").WinButton(MyDescription).Click

.Activate
End With



'Excercise1

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function



Dim Categories
Categories = Array("Food(10)", "Health & Beauty(20)", "Household(12)")

Function printCategoryNames()
Dim x, Element, firstparen, rslt
For x= 0 To 2
Element = Categories(x)
firstparen = Instr (1, Element, "(")
rslt = Mid (Element, 1, firstparen -1)
' printcategoryNames=rslt
printf ( rslt)
Next
End Function
printcategoryNames

SystemUtil.Run "C:\qtp_test.txt"


''excercise2

Private Const outputPath="c:\qtp_test11.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile(outputPath)

Function printf(data)
Dim val
val = data
f1.writeline val
End Function


'Dim profile(3)
Dim Categories
Categories = Array("Food(10)", "Health & Beauty(20)", "Household(12)")
'profile(0) = "Portnov"
' profile(1) = "El Camino"
'profile(2) = "Mountain View"
Function printCategoryNames()
'g=Len(Categories(x))
Dim x,c,d,g,rslt,bracpoint
For x= 0 To 2
' g=Len(Categories(x))
' c=printf Categories(x)
bracpoint=Instr(1,Categories(x),"( ")
rslt=Mid(Categories(x),1,bracpoint)
' printf ( rslt)
' printCategoryNames=h
' Element = Categories(x)
' firstparen = Instr (1, Element, "(")
' rslt = Mid (Element, 1, firstparen -1)
' printcategoryNames=rslt
printCategoryNames=rslt
Next
printf printCategoryNames
End Function
'printcategoryNames

SystemUtil.Run outputPath




'printf

ExecuteFile "C:\printf.vbs"
Set printer = new printf
printer.print"Test the class"
'code here


Set printer = nothing





'str compare

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function

Function teststrings(str1)
teststrings = len (str1)

End Function

printf ( teststrings("http://www.yahoo.com"))
'printf ( teststrings("http://www.yahoo.com","Yahoo"))

SystemUtil.run("C:\qtp_test.txt")
wait (5)
'SystemUtil.CloseProcessByName "(""C:\qtp_test.txt"")"

SystemUtil.CloseProcessByWndTitle "(""C:\qtp_test.txt"")"





''''Ui

ExecuteFile "C:\raj_QTP\printf.vbs"
Set printer = new printf
printer.print"Test the class"
'code here


SystemUtil.Run "notepad.exe"
Window("Notepad").WinEditor("Edit").SetCaretPos 0,0
Window("Notepad").WinMenu("Menu").Select "Edit;Replace... Ctrl+H"
Window("Notepad").Dialog("Replace").WinEdit("Find what:").Set "test"
setDialog("Replace")
setCheckBox "Match &case", "ON"
a = checkBoxExists("Match &case")
printer.print a

'setWindow("Document - Wordpad")
'a = getComboBoxByID("165")
'printer.print a




'batch
Dim oShell
Set oShell = CreateObject ("WScript.shell")
msgbox oShell.run ("cmd /K mkdir c:\meer")
Set oShell = Nothing




''case



set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function
Function testSwitch (day)
Select Case (day)
Case "Sunday"
printf ("Today is Sunday")
Case "Monday"
printf ("Today is Monday")
Case Else
printf ("take a day off")

End Select
End Function

testSwitch ("Sunday")
testSwitch ("Monday")
testSwitch ("Tuesday")

SystemUtil.Run "C:\qtp_test.txt"




'code sample


Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function


'OpenTextFile example
Dim filePath, fileObject
filePath = "c:\user_interface_en.properties"
Set fso = CreateObject("Scripting.FileSystemObject")

If (fso.FileExists(filePath)) Then
Set fileObject = fso.OpenTextFile(filePath, 1, True)
aLine = fileObject.readLine()
printf aLine
fileObject.close
Else
printf("Could not open file " & filePath)
End if





''shell

'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f1= fso.CreateTextFile("C:\qtp_test.txt")

'Function printf(data)
' Dim val
' val = data
'f1.writeline val
'End Function

Dim oShell
Set oShell = CreateObject ("WScript.shell")
oShell.run "c:\ test.bat"
'Set oShell = nothing



''excell

Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablepath = "c:\users.xls"
DataTable.Import(tablePath)
'printf("Opened excel file for reading and writing)

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
'printf(numRows)
'set the cursor on the next available row
DataTable.SetCurrentRow(numRows + 1)

'set the column values
DataTable.Value ("USER_NAME") = "ssmith"
DataTable.Value ("COMPANY") = "ABC Networks"
DataTable.Value ("FIRST_NAME") = "Sally"
DataTable.Value ("LAST_NAME") = "Smith"
DataTable.Value ("ADDRESS") = "101 smith Lane"
DataTAble.Export(tablePath)





''exitt

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function
For x = 0 to 10
If (x =5) Then
Exit For
End If
printf("Count+" & x)
Next
systemUtil.Run "C:\qtp_test.txt"
f1.close




''food

Private Const outputPath="c:\qtp_test11.txt"
Set fso=CreateObject("Scripting.FileSystemObject")
Set fl = fso.CreateTextFile(outputPath)

Function printf(data)
Dim val
val = data
fl.writeline val
End Function


Dim category,ittem,rslt,colon
category=Array("Food(10)","Health &Food(20)","Household(17)")

For x=0 to 2

ittem=Category(x)

colon=Instr(1,ittem,"(")
rslt=Mid(ittem,1,colon-1)
printf(rslt)

Next

fl.close
SystemUtil.Run outputPath





''get text


'setWindow"Document- wordpad"
'setComboBoxByID "207', "Greek"

'setDialog "Find'

'setAllCheckBoxes()

setDialog "Find"

setTextField "Fi&nd what:", "Cool"
a = getTextField("Fi&nd what:")

b = 1





''loading in memory

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function


' load properties in to memory

Dim filePath
Dim fileObject
Dim propFile
Dim aLine
Dim lenth
Dim equalPos
Dim array_size
Dim language
Dim localeKeys(10)
Dim localeValues(10)


filePath = "c:\raj_QTP\"
array_size = 0
language = "English"

if (StrComp(language, "English") = 0) then
propFile = filePath & "user_interface_en.properties"
elseif (StrComp(language, "Spanish") = 0) then
propFile = filePath & "user_interface_es.properties"
elseif (StrComp(language, "French") = 0) then
propFile = filePath & "user_interface_fr.properties"
end if
If (fso.FileExists(propFile)) then
Set fileObject = fso.OpenTextFile(propFile, 1, false)

do while(fileObject.AtEndOfStream <> True)
aline = fileObject.readline
lenth = len(aLine)
equalPos = instr(1, aLine, "=")
localekeys(array_size) = mid(aLine, 1, equalPos-1)
printf("keyStr:" & localekeys(array_size))
localeValues(array_size) = mid(aLine, equalPos + 1, lenth)
printf("value:" & localeValues(array_size))
array_size = array_size + 1
loop

printf("Array size = " & array_size)
fileObject.close
else
printf("Could not open file " & propFile)
end if
'get property function
function getProperty(keyStr)
Dim x

for x = 0 to (array_size + 1)
if (strcomp( localekeys(x), keyStr) = 0) then
Exit for
end if
next
getProperty = localeValues(x)
End function

printf(getProperty("Cancel"))




Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablePath = "c:\users.xls"

DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records

numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)


for x = 0 to numRows
DataTable.SetCurrentRow( x+1)
username = DataTable.Value("USER_NAME")
company = DataTable.Value("COMPANY")
first = DataTable.Value("FIRST_NAME")
last = DataTable.Value("LAST_NAME")
address = DataTable.Value("ADDRESS")
printf(username)
printf(company)
printf(first)
printf(last)
printf(address)
next


' login(username, "password")


SystemUtil.Run "c:\qtp_test.txt"







'''localisation

set language
language = "English" ' Spanish or French
' read from file 1 time
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.CreateTextFile("c:\qtp_test.txt")
Function printf(data)
Dim val
val = data
fl.writeline Val
End Function

Dim tablePath
Dim numRows
Dim username, company, first, last, address
Dim Rows(2,5)

tablePath = "c:\jp\users.xls"
DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)

For x = 0 to numRows-1
printf vbCrLf
DataTable.SetCurrentRow( x+1)
printf "Extracting data from row " & x

Rows(x,0) = DataTable.Value("USER_NAME")
Rows(x,1) = DataTable.Value("COMPANY")
Rows(x,2) = DataTable.Value("FIRST_NAME")
Rows(x,3) = DataTable.Value("LAST_NAME")
Rows(x,4) = DataTable.Value("ADDRESS")
next
For y = 0 to numRows-1
printf Rows(y,0)
printf Rows(y,1)
printf Rows(y,2)
printf Rows(y,3)
printf Rows(y,4)
next

' login(username, "password")



fl.close

SystemUtil.Run "c:\qtp_test.txt"




''''localisation


'set language
language = "English" ' Spanish or French
' read from file 1 time
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.CreateTextFile("c:\qtp_test.txt")
Function printf(data)
Dim val
val = data
fl.writeline Val
End Function

' load properties in to memory
Dim filePath
Dim fileObject
Dim propFile
Dim aLine
Dim lenth
Dim equalPos
Dim array_size
Dim language
Dim localeKeys(10)
Dim localeValues(10)
array_size = 0

' set property file path depending on language
filePath = "c:\jp\locale\"
if (StrComp(language, "English") = 0) then
propFile = filePath & "user_interface_en.properties"
elseif (StrComp(language, "Spanish") = 0) then
propFile = filePath & "user_interface_es.properties"
elseif (StrComp(language, "French") = 0) then
propFile = filePath & "user_interface_fr.properties"
End if
if (fso.FileExists(propFile)) then
Set tso = fso.OpenTextFile(propFile, 1, false)
' read all the lines in entire file
' loads into array
do while(tso.AtEndOfStream <> True)
aline = tso.readline
lenth = len(aLine)
equalPos = instr(1, aLine, "=")
localekeys(array_size) = mid(aLine, 1, equalPos-1)
localeValues(array_size) = mid(aLine, equalPos + 1, lenth)
array_size = array_size + 1
loop
'printf("Array size = " & array_size)
tso.close
else
printf("Could not open file " & propFile)
end if
' get translation from memory
function getTranslation(keyStr) ' Cancel
Dim x
for x = 0 to (array_size + 1)
if (strcomp( localekeys(x), keyStr) = 0) then
Exit for
end if
next

getTranslation = localeValues(x)
End function

trans = getTranslation("Delete")
printf trans

fl.close

SystemUtil.Run "c:\qtp_test.txt"







'notepad script

Set myDescription =Description.CreateCreate()
myDescription("text").value="cancel"

Window("Notepad").Activate
Window("Notepad").WinMenu("Menu").Select "Edit;Find... Ctrl+F"
Window("Notepad").Dialog("Find").WinButton("text:=Cancel","nativeclass:=Button"").Click

Window("Notepad").Activate





'''print

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Sub printf(data)
Dim val
val = data
f1.writeline val
End Sub

Function addNumbers(num1, num2)
rslt = num1 * num2/4
addNumbers = rslt
End Function
xlt = addNumbers(5,4)
printf xlt

Function is3oclock ()
is3oclock = false
End Function
rlt = is3oclock
printf rlt
'donot modify above'

name = "portnov " & """computer """ & "School"
printf name
For x =1 to 10
printf "Loop" & x
Next

printf 2+3
rslt = ((2 + 8) * 8) /4
printf rslt
printf 1<2

a = true

If (a =true) Then
printf "a=true"
else printf "a = false"
End If
f1.close
SystemUtil.Run "C:\qtp_test.txt"






'printf class

ExecuteFile "printf.vbs"


Set printer = getPrintf

printer.print "Test the class"


Set printer = nothing





'''register
private const IGNORE_FAILURE = 0
private const FAILURE1 = 1
private const FAILURE2 = 2
private const FAILURE3 = 3
private const FAILURE4 = 4
private const FAILURE5 = 5
private const FAILURE6 = 6
private const NO_ENTER_BUTTON = false
private const USE_ENTER_BUTTON = true

userArray = null

function registerUser(userArray, failureType, useEnterKey)
' contains steps to fill our registration for
' and successsfully register user

' required field section
if (failureType = FAILURE1) then
testFailure1()
'else if (failureType == FAILURE2)
'testFailure2()
end if

' deal with submit button
If useEnterKey = true Then
' use keyboard
else
' use mouse
End If
end function

function testFailure1() ' thru 6
' contains steps to test failure 1
end function

function verifyLoginAfterRegistration(userArray)
' take new user info and login
end function

function verifyProfile(userArray)
' verify profile is correct
end function

function getUserDataFromDataTable()
' read excel spreadsheet and return in array
'getUserData = userArray
end function

registerUser userArray, IGNORE_FAILURE, NO_ENTER_BUTTON ' success scenario
registerUser userArray, IGNORE_FAILURE, USE_ENTER_BUTTON '' variation 2
registerUser userArray, FAILURE1, NO_ENTER_BUTTON ' test failure 1
registerUser userArray, FAILURE2, NO_ENTER_BUTTON 'test failure 2
registerUser userArray, FAILURE3, NO_ENTER_BUTTON
registerUser userArray, FAILURE4, NO_ENTER_BUTTON
registerUser userArray, FAILURE5, NO_ENTER_BUTTON
registerUser userArray, FAILURE6, NO_ENTER_BUTTON




'''
spreadsheet


' set language
language = "English" ' Spanish or French
' read from file 1 time
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.CreateTextFile("c:\qtp_test.txt")
Function printf(data)
Dim val
val = data
fl.writeline Val
End Function

Dim tablePath
Dim numRows
Dim username, company, first, last, address
Dim Rows(2,5)

tablePath = "c:\jp\users.xls"
DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)

For x = 0 to numRows-1
printf vbCrLf
DataTable.SetCurrentRow( x+1)
printf "Extracting data from row " & x

Rows(x,0) = DataTable.Value("USER_NAME")
Rows(x,1) = DataTable.Value("COMPANY")
Rows(x,2) = DataTable.Value("FIRST_NAME")
Rows(x,3) = DataTable.Value("LAST_NAME")
Rows(x,4) = DataTable.Value("ADDRESS")
next
For y = 0 to numRows-1
printf Rows(y,0)
printf Rows(y,1)
printf Rows(y,2)
printf Rows(y,3)
printf Rows(y,4)
next

' login(username, "password")



fl.close

SystemUtil.Run "c:\qtp_test.txt"



\





'string

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function


Function getDomainName( str1)
Dim rslt, lenth, firstDot, x, oneChar
rslt = " "
lenth = Len(str1)
firstDot = Instr(1, str1, ".")
For x= (firstDot +1) To lenth
oneChar = Mid (str1, x, 1)
If (strComp (oneChar, ".") = 0 ) Then
Exit For
Else
rslt = rslt & oneChar
End If
Next
getDomainName = rslt
End Function

printf(getDomainName ("http//:www.yahoo.com"))
printf(getDomainName ("http//:www.portnov.com"))
printf(getDomainName ("http//:www.microsoft.com"))






'''translation

set language
language = "English" ' Spanish or French
' read from file 1 time
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.CreateTextFile("c:\qtp_test.txt")
Function printf(data)
Dim val
val = data
fl.writeline Val
End Function

' load properties in to memory
Dim filePath
Dim fileObject
Dim propFile
Dim aLine
Dim lenth
Dim equalPos
Dim array_size
Dim language
Dim localeKeys(10)
Dim localeValues(10)
array_size = 0

' set property file path depending on language
filePath = "c:\"
if (StrComp(language, "English") = 0) then
propFile = filePath & "user_interface_en.properties"
elseif (StrComp(language, "Spanish") = 0) then
propFile = filePath & "user_interface_es.properties"
elseif (StrComp(language, "French") = 0) then
propFile = filePath & "user_interface_fr.properties"
End if
if (fso.FileExists(propFile)) then
Set tso = fso.OpenTextFile(propFile, 1, false)
' read all the lines in entire file
' loads into array
do while(tso.AtEndOfStream <> True)
aline = tso.readline
lenth = len(aLine)
equalPos = instr(1, aLine, "=")
localekeys(array_size) = mid(aLine, 1, equalPos-1)
localeValues(array_size) = mid(aLine, equalPos + 1, lenth)
array_size = array_size + 1
loop
'printf("Array size = " & array_size)
tso.close
else
printf("Could not open file " & propFile)
end if
fl.close
SystemUtil.Run "c:\qtp_test.txt"





''translations

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function

Dim filePath
Dim fileObject
Dim propFile
Dim aLine
Dim lenth
Dim equalPos
Dim array_size
Dim language
Dim localeKeys(10)
Dim localeValues(10)


filePath = "c:\raj_QTP\"
array_size = 0
language = "English"

if (StrComp(language, "English") = 0) then
propFile = filePath & "errors_it.properties"
elseif (StrComp(language, "Spanish") = 0) then
propFile = filePath & "errors_it.properties"
elseif (StrComp(language, "French") = 0) then
propFile = filePath & "errors_it.properties"
end if
If (fso.FileExists(propFile)) then
Set fileObject = fso.OpenTextFile(propFile, 1, false)

do while(fileObject.AtEndOfStream <> True)
aline = fileObject.readline
lenth = len(aLine)
equalPos = instr(1, aLine, "=")
localekeys(array_size) = mid(aLine, 1, equalPos-1)
printf("keyStr:" & localekeys(array_size))
localeValues(array_size) = mid(aLine, equalPos + 1, lenth)
printf("value:" & localeValues(array_size))
array_size = array_size + 1
loop

printf("Array size = " & array_size)
fileObject.close
else
printf("Could not open file " & propFile)
end if
'get property function
function getProperty(keyStr)
Dim x

for x = 0 to (array_size + 1)
if (strcomp( localekeys(x), keyStr) = 0) then
Exit for
end if
next
getProperty = localeValues(x)
End function

printf(getProperty("Cancel"))




Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablePath = "c:\users.xls"

DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)


for x = 0 to numRows
DataTable.SetCurrentRow( x+1)
username = DataTable.Value("USER_NAME")
company = DataTable.Value("COMPANY")
first = DataTable.Value("FIRST_NAME")
last = DataTable.Value("LAST_NAME")
address = DataTable.Value("ADDRESS")
printf(username)
printf(company)
printf(first)
printf(last)
printf(address)
next


' login(username, "password")


SystemUtil.Run "c:\qtp_test.txt"






'translation2

Set fo = CreateObject("Scripting.FileSystemObject")
Set f1= fo.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function




Dim filePath, fStream,fso, colonPos
filePath = "c:\raj_QTP\errors_it.properties"
Set fso = CreateObject("Scripting.FileSystemObject")

If (fso.FileExists(filePath)) Then
Set fStream = fso.OpenTextFile(filePath, 1, false)

Do while (fStream.AtEndOfStream <> True)
aLine = fStream.readLine()
lenth = len(aLine)
If((instr(1,aLine,"#") = 0) AND (lenth <>0)) Then
colonPos = instr(1, aLine, ".")
aLine = mid(aLine, colonPos + 1, lenth)

printf aLine

End if
loop

Else
printf("Could not open file " & filePath)
End if






'''while


Set fso = CreateObject("Scripting.FileSystemObject")
Set f1= fso.CreateTextFile("C:\qtp_test.txt")

Function printf(data)
Dim val
val = data
f1.writeline val
End Function
x = 0
While (x < 5)
printf("count =" & x)
x = x + 1
Wend





''excel to write



Set fso=CreateObject("Scripting.FileSystemObject")
Set fl=fso.CreateTextFile ("c:\qtp_test.txt")
Function printf(data)
Dim val
data=val
fl.writeline val
End Function



Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablepath = "c:\users.xls"
DataTable.Import(tablePath)
'printf("Opened excel file for reading and writing)

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
'printf(numRows)
'set the cursor on the next available row
DataTable.SetCurrentRow(numRows + 1)

'set the column values
DataTable.Value ("USER_NAME") = "meer"
DataTable.Value ("COMPANY") = "bbc network"
DataTable.Value ("FIRST_NAME") = "ram"
DataTable.Value ("LAST_NAME") = "sri"
DataTable.Value ("ADDRESS") = "care terrace"
DataTAble.Export(tablePath)


For x = 0 to numRows-1
'printf vbCrLf
DataTable.SetCurrentRow( x+1)
printf "Extracting data from row " & x

Rows(x,0) = DataTable.Value("USER_NAME")
Rows(x,1) = DataTable.Value("COMPANY")
Rows(x,2) = DataTable.Value("FIRST_NAME")
Rows(x,3) = DataTable.Value("LAST_NAME")
Rows(x,4) = DataTable.Value("ADDRESS")
next
'For y = 0 to numRows-1
'printf Rows(y,0)
'printf Rows(y,1)
'printf Rows(y,2)
'printf Rows(y,3)
'printf Rows(y,4)
'next

'login(username, "password")
For x = 0 to numRows-1
printf Rows(x,0)
printf Rows(x,1)
printf Rows(x,2)
printf Rows(x,3)
printf Rows(x,4)
next




SystemUtil.Run "c:\qtp_test.txt"







'''data drivenn get property

get property function
function getProperty(keyStr)
Dim x

for x = 0 to (array_size + 1)
if (strcomp( localekeys(x), keyStr) = 0) then
Exit for
end if
next
getProperty = localeValues(x)
End function

printf(getProperty("Cancel"))




Dim tablePath
Dim numRows
Dim username, company, first, last, address

tablePath = "c:\users.xls"

DataTable.Import(tablePath)
printf("Opened excel file for reading and writing")

'get number of records
numRows = DataTable.GlobalSheet.GetRowCount
printf(numRows)


for x = 0 to numRows
DataTable.SetCurrentRow( x+1)
username = DataTable.Value("USER_NAME")
company = DataTable.Value("COMPANY")
first = DataTable.Value("FIRST_NAME")
last = DataTable.Value("LAST_NAME")
address = DataTable.Value("ADDRESS")
printf(username)
printf(company)
printf(first)
printf(last)
printf(address)
next


' login(username, "password")


SystemUtil.Run "c:\qtp_test.txt"


Function CheckLinks (BrowserObject, BrowserPage)
CheckLinks = True
sPage = "micclass:=Page"
Dim s_URL, i_CreationTime
Dim s_LinkOuterText, s_LinkInnerText, s_Linkhref
s_URL = BrowserPage.GetROProperty("url")
i_CreationTime = 1
i_LinkCount = BrowserPage.Object.links.Length - 1

Dim i_Link

For i_Link = 0 To i_LinkCount
If Trim(BrowserPage.Object.links(i_Link).target) = "" Then
'Set the link to open i a new window so that we dont
'have any change in current window
BrowserPage.Object.links(i_Link).target = "_blank"
End If

BrowserPage.Object.links(i_Link).click
On Error Resume Next
Browser("CreationTime:=" & i_CreationTime).sync
Browser("CreationTime:=" & i_CreationTime).Page(sPage).sync
On Error GoTo 0
Dim s_LinkDetails

IHTML = Browser("CreationTime:=" & i_CreationTime).Page(sPage).Object.Body.innerHTML
'Check if page was not able to be displayed
If (InStr(IHTML, "HTTP 404") <> 0) Or (InStr(IHTML, "cannot be displayed") <> 0) Then
s_LinkDetails = "Link Broken" + vbCrLf + "Link Details:" + vbCrLf
s_LinkDetails = s_LinkDetails + "OuterText: " + s_LinkOuterText + vbCrLf
s_LinkDetails = s_LinkDetails + "InnerText: " + s_LinkInnerText + vbCrLf
s_LinkDetails = s_LinkDetails + "href: " + s_Linkhref + vbCrLf
s_LinkDetails = s_LinkDetails + "Links Open in New Browse: " & bNewBrowser & vbCrLf
Reporter.ReportEvent micWarning, "Check Link(" & i_Link & ") -> " & s_LinkOuterText , s_LinkDetails
CheckLinks = FALSE
Else
s_LinkDetails = "Link Working" + vbCrLf + "Link Details:" + vbCrLf
s_LinkDetails = s_LinkDetails + "OuterText: " + s_LinkOuterText + vbCrLf
s_LinkDetails = s_LinkDetails + "InnerText: " + s_LinkInnerText + vbCrLf
s_LinkDetails = s_LinkDetails + "href: " + s_Linkhref + vbCrLf
s_LinkDetails = s_LinkDetails + "Links Open in New Browse: " & bNewBrowser & vbCrLf
Reporter.ReportEvent micPass, "Check Link(" & i_Link & ") -> " & s_LinkOuterText , s_LinkDetails
End If

Browser("CreationTime:=1").Close ' Close the link open.
Next
End Function



Subject: Notepad Custom Wrapper Library

private m_mainWindow
private m_dialog
public function setWindow(caption)
Set m_mainWindow = Window("nativeclass:=Notepad", "text:=" & caption)
end function
public function setDocument(text)
m_mainWindow.WinEditor("nativeclass:=Edit").Type text
end function
public function setDialog(caption)
Set m_dialog = m_mainWindow.Dialog("nativeclass:=#32770",
"text:=" & getTranslation(caption))
end function
public function setTextField(attachedText, text)
m_dialog.WinEdit("nativeclass:=Edit", "attached text:=" & attachedText).Set text
end function



script layout
Subject: Script Layout


' initial conditions will take us to registration page
setWebPage "Register: Mercury Tours", "Register: Mercury Tours"
maximizeBrowser()
Private const SUCCESS_SCENARIO = 0
Private const VALIDATE_USERNAME = 1
Private const VALIDATE_PASSWORDS = 2
Private const VALIDATE_GENERAL = 3
Private const VALIDATE_EMAIL = 4
Private const VALIDATE_ZIP = 5
Private const VALIDATE_PHONE = 6
Private const RE_REGISTRATION = 7

Function registerUser(testType, submitType)
' code calls lib function to populate form and submit
End Function
Function verifyLogin()
' verify registered user can login
End Function
Function verifyProfile()
' verify user profile
End Function

registerUser SUCCESS_SCENARIO, TRUE
registerUser VALIDATE_USERNAME, TRUE
registerUser VALIDATE_PASSWORDS, TRUE
registerUser VALIDATE_GENERAL, FALSE
registerUser VALIDATE_EMAIL, TRUE
registerUser VALIDATE_ZIP, TRUE
registerUser VALIDATE_PHONE, TRUE
registerUser RE_REGISTRATION, TRUE




private m_webBrowser
private m_webPage
function setWebPage(browserTitle, pageTitle)
Set m_webBrowser = Browser("Title:=" & browserTitle)
Set m_webPage = m_webBrowser.Page("Title:=" & pageTitle)
end function
function maximizeBrowser()
If (IsObject(m_webBrowser)) Then
m_webBrowser.FullScreen
else
MsgBox "Browser is not set"
End If
end function

No comments: