This is a Sample code for :
Creating a txt file, write data into that file n read data from that file.
code:
Dim fso, MyFile,ts,op,MyFile1
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("C:\text.txt", True)
MyFile.WriteLine("Last_Name" & " | " & "First_Name" & " | " & "Result") & " " & NewLine
MyFile.WriteLine("---------------------------------") & " " & NewLine
RowCnt=DataTable.GetSheet ("Action1").GetRowCount
For i=1 to RowCnt
DataTable.SetCurrentRow (i)
If DataTable.Value("Result",dtLocalSheet)="FAIL" Then
MyFile.WriteLine (DataTable.Value("Last_Name",dtLocalSheet) &" | " & DataTable.Value("First_Name",dtLocalSheet) &" | " & DataTable.Value("Result",dtLocalSheet)) & " "
MyFile.WriteLine()
end if
Next
MyFile.Close
Set f = fso.GetFile("C:\text.txt")
Set ts = f.OpenAsTextStream(1,-2)
Set MyFile1= fso.CreateTextFile("C:\text1.txt", True)
Do While Not ts.AtEndOfStream
op = op & ts.ReadLine
Loop
MyFile1.WriteLine(op)
ts.Close
MyFile1.close
Showing posts with label qtp codes. Show all posts
Showing posts with label qtp codes. Show all posts
Monday, November 7, 2011
Alternate to Wait function
Function IOE(ObjectName,mtime)
a=ObjectName.Exist
b=1
while a=0
wait(1)
a=ObjectName.Exist
b = b + 1
if b=mtime then
a=1
end if
wend
End Function
a=ObjectName.Exist
b=1
while a=0
wait(1)
a=ObjectName.Exist
b = b + 1
if b=mtime then
a=1
end if
wend
End Function
Creating Objects
Creates a new, empty description object in which you can add collection of properties and values in order to specify the description object in place of a test object name in a step.
Syntax
set PropertiesColl = Description.Create
Example
1. set EditDesc = Description.Create()
EditDesc("Name").Value = "userName"
EditDesc("Index").Value = "0"
Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName"
2. 'Define User ID field object
Set oUserID = Description.Create()
oUserID("Class Name").Value = "WebEdit"
oUserID("name").Value = "j_username"
Syntax
set PropertiesColl = Description.Create
Example
1. set EditDesc = Description.Create()
EditDesc("Name").Value = "userName"
EditDesc("Index").Value = "0"
Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName"
2. 'Define User ID field object
Set oUserID = Description.Create()
oUserID("Class Name").Value = "WebEdit"
oUserID("name").Value = "j_username"
Clicking "webelement" within a cell of WebTable
This we can do more efficiently by using "Programmatic Descriptions" and substituting properties with variables(You can see in KB articles. But once case, I dont know why,"Programmatic Descriptions" did not work for me. Then I workaround by doing the below code :
numWTLen=Browser("Browser").Page("Page").Frame("Frame").WebTable("Table").RowCount
For i=1 to numWTLen
strConfigStatus=Trim(Browser("Browser").Page("Page").Frame("Frame").WebTable("Table").GetCellData(o,3))
If strConfigStatus="Configured" Then 'If this Condition satisfy, then only we are clicking "Web element" within Cell
'Putting Index value dynamically for every row.
DataTable.Value("Index",dtLocalSheet)=i 'Index starts from "0" but my Webtable first row contains Headings, hence i took index starts from "1"
Browser("Browser").Page("Page").Frame("Frame").WebElement("WebElement").Click
Exit For 'Exiting from "For" Loop
End If
Next
Note:Before executing the above code. we have to parameterize the " WebElement("WebElement")"
(right click on WebElement("WebElement") , choose object Properties and select "Parameter radio button").
property Name "Index" to "Local sheet" with Name "Index". And also obviously add "Index" property
to the " WebElement("WebElement")" property list and remove "innertext" property from property
list.
Example: WebElement("WebElement") contails two properties.
1) Name:html Tag Value=some tag
2) Name:Index Value=1
Thanks!
Raghubansh
numWTLen=Browser("Browser").Page("Page").Frame("Frame").WebTable("Table").RowCount
For i=1 to numWTLen
strConfigStatus=Trim(Browser("Browser").Page("Page").Frame("Frame").WebTable("Table").GetCellData(o,3))
If strConfigStatus="Configured" Then 'If this Condition satisfy, then only we are clicking "Web element" within Cell
'Putting Index value dynamically for every row.
DataTable.Value("Index",dtLocalSheet)=i 'Index starts from "0" but my Webtable first row contains Headings, hence i took index starts from "1"
Browser("Browser").Page("Page").Frame("Frame").WebElement("WebElement").Click
Exit For 'Exiting from "For" Loop
End If
Next
Note:Before executing the above code. we have to parameterize the " WebElement("WebElement")"
(right click on WebElement("WebElement") , choose object Properties and select "Parameter radio button").
property Name "Index" to "Local sheet" with Name "Index". And also obviously add "Index" property
to the " WebElement("WebElement")" property list and remove "innertext" property from property
list.
Example: WebElement("WebElement") contails two properties.
1) Name:html Tag Value=some tag
2) Name:Index Value=1
Thanks!
Raghubansh
Wednesday, October 12, 2011
Compare values of 2 Excel sheets cell by cell
This code will open two excel sheet and compare values of each sheet cell by cell, if any changes there in cells , it will highlight the cells in red color in the first sheet.
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:Documents andSettingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:Documents and
Settingsmohan.kakarlaDesktopDocs2.xls”)
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
cell.Interior.ColorIndex = 3′Highlights in red color if any changes in cells
Else
cell.Interior.ColorIndex = 0
End If
Next
set objExcel=nothing
Source : MDSN
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:Documents andSettingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:Documents and
Settingsmohan.kakarlaDesktopDocs2.xls”)
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
cell.Interior.ColorIndex = 3′Highlights in red color if any changes in cells
Else
cell.Interior.ColorIndex = 0
End If
Next
set objExcel=nothing
Source : MDSN
Subscribe to:
Posts (Atom)