Step 1:-
Copy paste the below code in to a text file and save it as Login.xml
Note:The below code has 4 environments with different user id and passwords
--------------------------------------------------------------------------------
<Environment>
<Variable>
<ENV>UAT</ENV>
<ID>userid</ID>
<PSWD>Password</PSWD>
</Variable>
<Variable>
<ENV>PFIX</ENV>
<ID>userid</ID>
<PSWD>password</PSWD>
</Variable>
<Variable>
<ENV>PROD</ENV>
<ID></ID>
<PSWD></PSWD>
</Variable>
<Variable>
<ENV>SIT</ENV>
<ID>userid</ID>
<PSWD>password</PSWD>
</Variable>
</Environment>
-----------------------------------------------------------------------------------------
Step 2:- Use the below in QTP to get the data from xml file
-------------------------------------------------------------------------------------------
Public Function LoginUserInfo()
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\Login.xml") Then
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load("C:\Login.xml")
Set ENVnode = xmlDoc.getElementsByTagName("ENV")
Set IDnode = xmlDoc.getElementsByTagName("ID")
Set PSWDnode = xmlDoc.getElementsByTagName("PSWD")
ENVlength=ENVnode.length
IDlength=IDnode.length
PSWDlength=PSWDnode.length
Counter=1
for Counter=0 to ENVlength-1
ENVitem=ENVnode.item(Counter).Text
IDitem=IDnode.item(Counter).Text
PSWDitem= PSWDnode.item(Counter).Text
If (LEnv = ENVitem) Then
Environment.Value("ENV") = ENVitem
Environment.Value("UserID")=IDitem
Environment.Value("PSWD") = PSWDitem
ENV = Envitem
UserID = IDitem
PSWD = PSWDitem
Exit For
End If
Next
End If
End Function
--------------------------------------------------------------------------
Step 3:
From the above code you will get the data of login id , password and login environment in to the below variabels as
ENV= login environment
UserID= Login User ID
PSWD= Password
No comments:
Post a Comment