strFile= "C:\Users\Venu\Desktop\QTP_ex\ImportData.xls"
sheetNM="strData"
Dim arrColumns()
intCols=0
testCase= "Gmail Login"
intRow=0
Set Exl= CreateObject("Excel.Application")
Exl.Application.Visible = False
Exl.Workbooks.Open(strFile)
'' Search whether work sheet is available or not..
blnSheet= False
For j=1 to Exl.Worksheets.Count
If Exl.Worksheets(j).Name=sheetNM Then
blnSheet= True
Exit For
End If
Next
'' Set the sheet reference here
Set Ws= Exl.Sheets(sheetNM)
RowCnt= Ws.UsedRange.Rows.Count
ColCnt= Ws.UsedRange.Columns.Count
For i=2 to RowCnt
If instr(1, ws.Cells(i, 1), testCase, 1)>0 Then
intRow=i
Exit For
End If
Next
If intRow=0 Then
'' "Data Not found in excel sheet.."
ExitTest
End If
'' Get the Header values into an array
For i=1 to ColCnt
If ws.Cells(1, i)<>"" Then
Redim Preserve arrColumns(i)
arrColumns(i-1)= ws.Cells(1, i)
intCols= i
else
Exit For
End If
Next
'' Set the header values
Set thdGlobal=DataTable.GlobalSheet
For each head in arrColumns
thdGlobal.AddParameter head, ""
Next
''First import header data from excel into DataTable
TextFound=0
For i=intRow to RowCnt
If instr(1, ws.Cells(i, 1), testCase, 1)>0 Then
TextFound= TextFound+1
thdGlobal.SetCurrentRow TextFound
For j=1 to intCols
DataTable(j, "Global")= ws.Cells(i, j)
Next
End If
Next
'parameterCnt= thdGlobal.GetParameterCount
'For i=1 to parameterCnt
' msgbox thdGlobal.GetParameter(i).Name
'Next
Exl.Quit
Set Exl= Nothing
-------------------------------------------------------
'' Action 1
SystemUtil.CloseProcessByName "iexplore.exe"
SystemUtil.Run "iexplore.exe", "gmail.com"
Environment("intIteration")=1
If Browser("creationTime:=0").exist(10) Then
Browser("creationTime:=0").Sync
End If
rCount= DataTable.GlobalSheet.GetRowCount
If rCount=0 OR Environment("intIteration")> rCount Then
Reporter.ReportEvent micFail, "Import test data into data table", "Test data for test name: '"& Environment("TestName") & "' not found."
ExitTest
End If
For i=1 to rCount
DataTable.GlobalSheet.SetCurrentRow (i)
If i <= Environment("intIteration") Then
RunAction "testingAction1", oneIteration
msgbox "Iteration: "& i & " of total: "& rCount
End If
' If Environment("intIteration")=1 Then
' Exit For
' End If
Next
msgbox "done"
===============================
Action Name: testingAction1
Browser("creationTime:=0").Sync
Browser("creationTime:=0").Page("creationTime:=0").Sync
Browser("creationTime:=0").Page("creationTime:=0").Link("html tag:= A", "innerText:= More information").Highlight
Browser("creationTime:=0").Page("creationTime:=0").Link("html tag:= A", "innerText:= More information").Click
==================================================
'systemutil.Run "iexplore.exe", "google.com"
Set o=Browser("CreationTime:=0").Page("creationtime:=0")
t= o.ExecuteActionOnObj("lnk", "name=Punjabi", "click", "", "")
Public Function ExecuteActionOnObj(ByRef objRef, strClass, strObjProp, strAction, strData, strAddtional)
ExecuteActionOnObj= False
Dim blnFlag: blnFlag=False
strPropValues=getChildObjProperties(strClass)
' If strObjProp <> "" Then
' strPropValues = strPropValues & "<>" & strObjProp
' End If
If instr(1, strPropValues, "<>")>0 Then
arrObjProperties=Split(strPropValues, "<>")
else
Dim arrObjProperties(0): arrObjProperties(0)= strPropValues
End If
Set objChd=Description.Create
objChd("micClass").Value=arrObjProperties(0)
For i=1 to UBound(arrObjProperties)
arrPropValue=Split( arrObjProperties(i), "=")
objChd(Trim(arrPropValue(0))).Value= Trim(arrPropValue(1))
Next
If instr(1, strObjProp, "<>")>0 Then
arrScreen=Split(strObjProp, "<>")
else
Dim arrScreen(0): arrScreen(0)= strObjProp
End If
For i=0 to UBound(arrScreen)
arrScrProp=Split( arrScreen(i), "=")
objChd(Trim(arrScrProp(0))).Value= Trim(arrScrProp(1))
Next
Set refChdObj=objRef.ChildObjects(objChd)
If refChdObj.Count=0 Then
Reporter.ReportEvent micFail, "Object not found", "Object is not found"
Exit Function
End If
For j=0 to refChdObj.Count-1
intX=refChdObj(j).getROProperty("x")
intY=refChdObj(j).getROProperty("y")
intHeight= refChdObj(j).getROProperty("height")
If intX<> 0 And intHeight<>0 Then
Set ChildObj= refChdObj(j)
Exit For
End If
Next
Select Case LCase(strAction)
Case "click"
childObj.Click
blnFlag=True
Case "splclick"
childObj.Click micNoCoordinate,micNoCoordinate,micRightBtn
blnFlag=True
Case "getroproperty"
iDict("retPropValue")= childObj.getROProperty(strData)
blnFlag=True
End Select
ExecuteActionOnObj= blnFlag
End Function
RegisterUserFunc "Browser", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Page", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Frame", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebElement", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Link", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebButton", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebEdit", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Image", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebCheckBox", "ExecuteActionOnObj", "ExecuteActionOnObj"
'' like wise, register for radio buttons, and others..
Function getChildObjProperties(strClass)
getChildObjProperties= False
Dim strMicClass, strPropValue
strMicClass= ""
strPropValue= ""
If strClass= "" or IsEmpty(strClass) Then
Reporter.ReportEvent micFail, "Pass prefix of a webclass object", "Invalid prefix passed"
Else
Select Case LCase(strClass)
Case "lnk"
strMicClass= "Link"
strPropValue= "html tag=A"
Case "plk"
strMicClass= "Link"
Case "txt"
strMicClass= "WebEdit"
strPropValue= "html Tag=INPUT"
Case "btn"
strMicClass= "WebButton"
strPropValue= "html Tag=Submit"
End Select
If strPropValue="" OR isEmpty(strPropValue) Then
getChildObjProperties= strMicClass
Else
getChildObjProperties= strMicClass & "<>" & strPropValue
End If
End If
End Function
=======================================================================
Set iDict= CreateObject("Scripting.Dictionary")
Call LoadGlobalData("Config.xls")
Function LoadGlobalData(strFileName)
On Error resume Next
strFile= PathFinder.Locate(strFileName)
Set fso=CreateObject("Scripting.FileSystemObject")
Set Exl=CreateObject("Excel.Application")
If fso.FileExists(strFile) Then
Exl.Application.Visible= False
Exl.Workbooks.Open strFile
Set ws= Exl.Sheets("configValues")
If Err.Number<>0 Then
Reporter.ReportEvent micWarning, "Error found while setting the global data", err.Description
err.Clear
End If
On Error goto 0
i=2
Do While ws.Cells(i,1)<>"" OR Not IsEmpty(ws.Cells(i,1))
'msgbox ws.Cells(i, 1)
iKey=Ws.Range("A"&i)
iVal=ws.Range("B"&i)
iDict(iKey)=iVal
i=i+1
Loop
End If
Set exl= Nothing
Set fso= Nothing
End Function
'msgbox iDict("strEnvironment")
For each ele in iDict.Keys
' strExe=ele & "=" & iDict(ele)
Execute "ele = iDict(ele)"
msgbox ele
Next
Set iDict= Nothing
'b=10
'Execute "A=B"
'msgbox A
sheetNM="strData"
Dim arrColumns()
intCols=0
testCase= "Gmail Login"
intRow=0
Set Exl= CreateObject("Excel.Application")
Exl.Application.Visible = False
Exl.Workbooks.Open(strFile)
'' Search whether work sheet is available or not..
blnSheet= False
For j=1 to Exl.Worksheets.Count
If Exl.Worksheets(j).Name=sheetNM Then
blnSheet= True
Exit For
End If
Next
'' Set the sheet reference here
Set Ws= Exl.Sheets(sheetNM)
RowCnt= Ws.UsedRange.Rows.Count
ColCnt= Ws.UsedRange.Columns.Count
For i=2 to RowCnt
If instr(1, ws.Cells(i, 1), testCase, 1)>0 Then
intRow=i
Exit For
End If
Next
If intRow=0 Then
'' "Data Not found in excel sheet.."
ExitTest
End If
'' Get the Header values into an array
For i=1 to ColCnt
If ws.Cells(1, i)<>"" Then
Redim Preserve arrColumns(i)
arrColumns(i-1)= ws.Cells(1, i)
intCols= i
else
Exit For
End If
Next
'' Set the header values
Set thdGlobal=DataTable.GlobalSheet
For each head in arrColumns
thdGlobal.AddParameter head, ""
Next
''First import header data from excel into DataTable
TextFound=0
For i=intRow to RowCnt
If instr(1, ws.Cells(i, 1), testCase, 1)>0 Then
TextFound= TextFound+1
thdGlobal.SetCurrentRow TextFound
For j=1 to intCols
DataTable(j, "Global")= ws.Cells(i, j)
Next
End If
Next
'parameterCnt= thdGlobal.GetParameterCount
'For i=1 to parameterCnt
' msgbox thdGlobal.GetParameter(i).Name
'Next
Exl.Quit
Set Exl= Nothing
-------------------------------------------------------
'' Action 1
SystemUtil.CloseProcessByName "iexplore.exe"
SystemUtil.Run "iexplore.exe", "gmail.com"
Environment("intIteration")=1
If Browser("creationTime:=0").exist(10) Then
Browser("creationTime:=0").Sync
End If
rCount= DataTable.GlobalSheet.GetRowCount
If rCount=0 OR Environment("intIteration")> rCount Then
Reporter.ReportEvent micFail, "Import test data into data table", "Test data for test name: '"& Environment("TestName") & "' not found."
ExitTest
End If
For i=1 to rCount
DataTable.GlobalSheet.SetCurrentRow (i)
If i <= Environment("intIteration") Then
RunAction "testingAction1", oneIteration
msgbox "Iteration: "& i & " of total: "& rCount
End If
' If Environment("intIteration")=1 Then
' Exit For
' End If
Next
msgbox "done"
===============================
Action Name: testingAction1
Browser("creationTime:=0").Sync
Browser("creationTime:=0").Page("creationTime:=0").Sync
Browser("creationTime:=0").Page("creationTime:=0").Link("html tag:= A", "innerText:= More information").Highlight
Browser("creationTime:=0").Page("creationTime:=0").Link("html tag:= A", "innerText:= More information").Click
==================================================
'systemutil.Run "iexplore.exe", "google.com"
Set o=Browser("CreationTime:=0").Page("creationtime:=0")
t= o.ExecuteActionOnObj("lnk", "name=Punjabi", "click", "", "")
Public Function ExecuteActionOnObj(ByRef objRef, strClass, strObjProp, strAction, strData, strAddtional)
ExecuteActionOnObj= False
Dim blnFlag: blnFlag=False
strPropValues=getChildObjProperties(strClass)
' If strObjProp <> "" Then
' strPropValues = strPropValues & "<>" & strObjProp
' End If
If instr(1, strPropValues, "<>")>0 Then
arrObjProperties=Split(strPropValues, "<>")
else
Dim arrObjProperties(0): arrObjProperties(0)= strPropValues
End If
Set objChd=Description.Create
objChd("micClass").Value=arrObjProperties(0)
For i=1 to UBound(arrObjProperties)
arrPropValue=Split( arrObjProperties(i), "=")
objChd(Trim(arrPropValue(0))).Value= Trim(arrPropValue(1))
Next
If instr(1, strObjProp, "<>")>0 Then
arrScreen=Split(strObjProp, "<>")
else
Dim arrScreen(0): arrScreen(0)= strObjProp
End If
For i=0 to UBound(arrScreen)
arrScrProp=Split( arrScreen(i), "=")
objChd(Trim(arrScrProp(0))).Value= Trim(arrScrProp(1))
Next
Set refChdObj=objRef.ChildObjects(objChd)
If refChdObj.Count=0 Then
Reporter.ReportEvent micFail, "Object not found", "Object is not found"
Exit Function
End If
For j=0 to refChdObj.Count-1
intX=refChdObj(j).getROProperty("x")
intY=refChdObj(j).getROProperty("y")
intHeight= refChdObj(j).getROProperty("height")
If intX<> 0 And intHeight<>0 Then
Set ChildObj= refChdObj(j)
Exit For
End If
Next
Select Case LCase(strAction)
Case "click"
childObj.Click
blnFlag=True
Case "splclick"
childObj.Click micNoCoordinate,micNoCoordinate,micRightBtn
blnFlag=True
Case "getroproperty"
iDict("retPropValue")= childObj.getROProperty(strData)
blnFlag=True
End Select
ExecuteActionOnObj= blnFlag
End Function
RegisterUserFunc "Browser", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Page", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Frame", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebElement", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Link", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebButton", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebEdit", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "Image", "ExecuteActionOnObj", "ExecuteActionOnObj"
RegisterUserFunc "WebCheckBox", "ExecuteActionOnObj", "ExecuteActionOnObj"
'' like wise, register for radio buttons, and others..
Function getChildObjProperties(strClass)
getChildObjProperties= False
Dim strMicClass, strPropValue
strMicClass= ""
strPropValue= ""
If strClass= "" or IsEmpty(strClass) Then
Reporter.ReportEvent micFail, "Pass prefix of a webclass object", "Invalid prefix passed"
Else
Select Case LCase(strClass)
Case "lnk"
strMicClass= "Link"
strPropValue= "html tag=A"
Case "plk"
strMicClass= "Link"
Case "txt"
strMicClass= "WebEdit"
strPropValue= "html Tag=INPUT"
Case "btn"
strMicClass= "WebButton"
strPropValue= "html Tag=Submit"
End Select
If strPropValue="" OR isEmpty(strPropValue) Then
getChildObjProperties= strMicClass
Else
getChildObjProperties= strMicClass & "<>" & strPropValue
End If
End If
End Function
=======================================================================
Set iDict= CreateObject("Scripting.Dictionary")
Call LoadGlobalData("Config.xls")
Function LoadGlobalData(strFileName)
On Error resume Next
strFile= PathFinder.Locate(strFileName)
Set fso=CreateObject("Scripting.FileSystemObject")
Set Exl=CreateObject("Excel.Application")
If fso.FileExists(strFile) Then
Exl.Application.Visible= False
Exl.Workbooks.Open strFile
Set ws= Exl.Sheets("configValues")
If Err.Number<>0 Then
Reporter.ReportEvent micWarning, "Error found while setting the global data", err.Description
err.Clear
End If
On Error goto 0
i=2
Do While ws.Cells(i,1)<>"" OR Not IsEmpty(ws.Cells(i,1))
'msgbox ws.Cells(i, 1)
iKey=Ws.Range("A"&i)
iVal=ws.Range("B"&i)
iDict(iKey)=iVal
i=i+1
Loop
End If
Set exl= Nothing
Set fso= Nothing
End Function
'msgbox iDict("strEnvironment")
For each ele in iDict.Keys
' strExe=ele & "=" & iDict(ele)
Execute "ele = iDict(ele)"
msgbox ele
Next
Set iDict= Nothing
'b=10
'Execute "A=B"
'msgbox A
No comments:
Post a Comment