can any body give the code to write the function for given
suppose user login with usrer id and pwd to yahoomail.after
cliking "sign in"if it is valid user id the next page will
display userid'message box.( Note u have to use excel sheet
to retrive the userid's data)
Answer Posted / hari
'-----------------------------------------------------------
--------Create the Connection String -----------------------
------------------------------------------------------------
---------
Function fgGetConnection( )
'****
'Purpose: Get
connection to Excel Workbook
'****
Dim objConnection
Set objConnection = CreateObject
("ADODB.Connection")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0
;Data Source='D:\Test Data\Test_Data.xls' ;Extended
Properties=Excel 8.0;"
Set fgGetConnection = objConnection
End Function
'-----------------------------------------------------------
--------Close the excel connection -------------------------
------------------------------------------------------------
-------
Function fgCloseConnection ( objConnection )
'****
'Purpose: Close connection to
Excel Workbook
'****
objConnection.Close
End Function
'-----------------------------------------------------------
--------Fetch the test data from the excel -----------------
------------------------------------------------------------
---------------
Function fgGetData (objConnection, strColumnName, Sheet,
intPageNumber, TestSetName)
'****
'Purpose: Queries the Excel Workbook
for one field in the particular Sheet
' - Can also take a string
with comma separated values to get all the columns and give
it back as an array.
'****
'MsgBox strColumnName
'MsgBox Sheet
'MsgBox intPageNumber
'MsgBox TestSetName
Dim objRecordSet,
strQuery
Dim strScenarioID
Set objRecordSet =
CreateObject("ADODB.recordset")
objRecordSet.CursorType = 3 'set CursorType to be
able to do a RecordCount
strQuery
= "SELECT " & strColumnName & " FROM ["&Sheet& "$] WHERE
Test_Set = '" & TestSetName & "' AND Step_Number =" &
intPageNumber & " AND TestStatus='Y'"
objRecordSet.open
strQuery, objConnection
Select Case
objRecordSet.RecordCount
Case 0
fgGetData = ""
Case Else
If InStr(objRecordSet(0),
Chr(10)) > 0 Then
fgGetData = Replace
( objRecordSet(0), Chr(10), vbNewLine )
Else
fgGetData =
objRecordSet(0)
' msgbox fgGetData
End If
End Select
objRecordSet.Close
End Function
'***********************************************DB
Connection Start
Function****************************************************
****************************
Public Function CreateruntimeObject(Sheetname,ObName)
' msgbox ObName
set
conn=createobject("ADODB.CONNECTION")
set
recset=createobject("ADODB.RECORDSET")
conn.provider="MICROSOFT.JET.OLEDB.4.0"
conn.open "data source='D:\Object
Repository\Object.xls'; Extended properties=EXCEL 8.0"
qry="Select
Properties from [" & Sheetname& "$] where ObjName='"
&ObName& "'"
recset.open qry,
conn, 1, 1
props= recset.Fields(0)
'Create object description
for the data fetched from the excel sheet.
Set obj=description.create()
arrprops=split(props, "|")
For i=0 to UBOUND
(arrprops)
arrprop=split(arrprops(i), "=")
propname=arrprop(0)
propvalue=arrprop(1)
obj
(propname).value=propvalue
Next
Set CreateruntimeObject=obj
'if object not present????
End Function
'-----------------------------------------------------------
-------- Functional Result update in the testData Excel-----
------------------------------------------------------------
----------------------------
Public Function Resultupdate(objConnection,
Sheet,TestSetName, intPageNumber, Result, Status)
objConnection.Execute "update ["&Sheet&"$]
set TestResult ='" & Result & "', TestStatus ='" & Status
& "', Execution_Date =Now where Test_Set = '" &
TestSetName & "' and Step_Number =" & intPageNumber & ""
End Function
'-----------------------------------------------------------
--------GUI Result update in the testData Excel-----------
------------------------------------------------------------
----------------------
Public Function ResultupdateGUI(objConnection,
Sheet,TestSetName, Result, Status,objVal,objroPty)
objConnection.Execute "update
["&Sheet&"$] set TestResult ='" & Result & "', TestStatus
='" & Status & "', Execution_Date =Now where Test_Set
= '" & TestSetName & "' AND TestStatus='Y' AND
Objval='"&objVal&"' AND Objroproperty='"&objroPty &"' "
End Function
'-----------------------------------------------------------
--------Function for Close Application --------------------
------------------------------------------------------------
-------------
Function CloseApplication(Application)
dim strcompname,
strprocesstokill, objwmiservice, compname
dim colprocess
Set WshNetwork =CreateObject
("WScript.Network")
compname=WshNetwork.computername 'Get the computer
name
Set objwmiservice=Getobject
("Winmgmts:\\" &compname & "\root\cimv2") 'Get the task
manager
set
colprocess=objwmiservice.execquery("Select * from
win32_process where name='"&Application&"'")
' Get all the
processes in an arrary and terminate the required process
from the task manager.
For each process in
colprocess
msg=process.name
reporter.ReportEvent micDone, msg, msg & " this has been
terminated"
process.terminate()
Next
End Function
'-----------------------------------------------------------
--------Invoke outlook Folder Function ---------------------
------------------------------------------------------------
-----------
Function InvokeOutlookFedex()
Const olFolderInbox = 6
Set objOutlook =
CreateObject("Outlook.Application")
'
'If Dialog
("regexpwndclass:=#32770", "regexpwndtitle:=Personal
Folders Password").Exist(1) Then
' pass=Input("Enter
your Password")
' Dialog
("regexpwndclass:=#32770", "regexpwndtitle:=Personal
Folders Password").WinEdit("attached text:=Type the
password for.*").Set pass
'End If
Set objNamespace =
objOutlook.GetNamespace("MAPI")
Set objInbox =
objNamespace.GetDefaultFolder(olFolderInbox)
'msgbox objInbox
strFolderName =
objInbox.Parent
'msgbox strFolderName
Set objMailbox =
objNamespace.Folders(strFolderName)
Set objFolder =
objMailbox.Folders("FedEx QuickShip")
'msgbox objFolder
wait(5)
objFolder.display
wait(3)
Window(MainPage).maximize
End Function
Public Function Alternateobject(Sheetname,ObName)
' msgbox ObName
set conn=createobject("ADODB.CONNECTION")
set recset=createobject("ADODB.RECORDSET")
conn.provider="MICROSOFT.JET.OLEDB.4.0"
'conn.open "Provider=MS.Remote;" & "Remote
Server=\\Wm6103rbw-1331;" & "Remote Provider =
MICROSOFT.JET.OLEDB.4.0;" & "data source='\\Wm6103rbw-1331
\Object Repository\Object.xls'; Extended properties=EXCEL
8.0"
conn.open "data source='D:\Object
Repository\Object.xls'; Extended properties=EXCEL 8.0"
qry="Select Alternate_Prop from [" & Sheetname& "$]
where ObjName='" &ObName& "'"
recset.open qry, conn, 1, 1
props= recset.Fields(0)
''Gets the value into an array
' Do Until recset.eof
' For each val in recset.fields
' props=val.value
' msgbox props
' Next
' recset.movenext
' Loop
'Create object description for the data fetched from the
excel sheet.
Set obj=description.create()
arrprops=split(props, "|")
For i=0 to UBOUND(arrprops)
' msgbox arrprops(i)
arrprop=split(arrprops(i), "=")
propname=arrprop(0)
propvalue=arrprop(1)
' msgbox propname
' msgbox propvalue
obj(propname).value=propvalue
Next
Set Alternateobject=obj
'if object not present????
End Function
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
Hi Friends, I have an issue like the describe below: I'm using QTP and I'm testing on SharePoint. As you knoe, SharePoint has a customize function for user, so that, If I add an object Web Table at the first time, that object was recognized by "index" and "html tag", after that, if someone change the display of web part, the "Index" of my object was changed as well and QTP unable to select that Web Table. Can you guide me how to identify or anyway to keep that Web Table object as unique object? Thanks a lot.
Which conditional statement is the most convenient one to use in the case of multiple conditions in the vbscript language?
What are the valid scopes of a variable in vbscript?
Mention how you can call vbscript functions?
Write a function for Instr(). We need to write a function that works as same as Instr(). Code or Even pseudo code is good enough for me.?
Dear All, I am geting below IE error whilie executing the QTP scripts in Batch mode "Internet Explorer has encountered a problem and needs to close. We are sorry for the inconvenience." can any one suggest me how to resolve this issue . Thanks Balaji
Is vbscript language a case-sensitive language and what does it mean?
i have a problem with this error(this error related edit and
delete button,when i click this button in datagrid..i will
get this error)"Invalid postback or callback argument.
Event validation is enabled using
Which in-built functions are used to convert the specified expression in the form of date and string in the vbscript language?
How can you fetch the value of a cookie?
Hi Friends Rajendra this is bhavani prasad, iam working Hyderabad. i faced one problem with qtp recording mode i.e in my application there is 100 records first we click the first record that record will be jumped to next session and 99 records will there stop the recording and run the same script .Run this script qtp does not identify the records. So plz tell me what is the solution.
What are the naming conventions while declaring a variable in the vbscript language?
When does ‘on click of button’ event gets triggered in the vbscript language?
What is the difference between a dictionary and an array?
What is Procedure or Subroutine in VB Script?