Preconditions: -
You need to upload a excel sheet in the QC resources tab, as below:
Key Value
UID naresh
PWD XXXX
**********************************************************************************************************************
'Name: Fun_GetCredentials
'Purpose: This function will get the credential details from the QC resource
'Argument(s): ip_intResourceId: Resource ID of the item
'Returns: 0: Indicates failure
' Credential details as: UserID|Password
'Example: returnValue = Fun_GetCredentials("1055")
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Revised:
'Revised by:
'Changes:
' **********************************************************************************************************************
Function Fun_GetCredentials(ip_intResourceId)
Dim objQCResource, objDataSheet, intDSRowCnt, intDSRowIndex, strUserID, strPwd
On Error Resume Next
'Get the resource object from QC with resource id as ip_intResourceId
Set objQCResource = QCUtil.QCConnection.QCResourceFactory.Item(ip_intResourceId)
'Download the resource file into the result directory
objQCResource.DownloadResource Environment("ResultDir"), True
'Get the sheet 1 of resource file from result directory into the design time datatable at sheet 1
DataTable.ImportSheet Environment("ResultDir") & "\" & objQCResource.Filename, 1, 1
'Get the object Datasheet from the design time datatable
Set objDataSheet = DataTable.GetSheet(1)
intDSRowCnt = objDataSheet.GetRowCount
'Loop for each row and validate the Key column, based on key value get value column value
For intDSRowIndex = 1 To intDSRowCnt
objDataSheet.SetCurrentRow(intDSRowIndex)
Select Case UCase(Trim(DataTable.Value(intConstKeyColIndex, 1)))
Case "UID"
strUserID = Trim(DataTable.Value(intConstValueColIndex, 1))
Case "PWD"
strPwd = Trim(DataTable.Value(intConstValueColIndex, 1))
End Select
Next
'Set the return value
If Trim(strUserID) <> "" And Trim(strPwd) <> "" Then
Fun_GetCredentials = strUserID & "|" & strPwd
Else
Fun_GetCredentials = 0
subJCP_EventReport "Fail", "Required credential details are not found. " & VBNewLine & "User ID = " & strUserID & VBNewLine & "Password = " & strPwd, Nothing
Exit Function
End If
'If unexpected error is reported here
If Trim(CStr(Err.Description)) <> "" Then
Fun_GetCredentials = 0
subJCP_EventReport "Fail", "Unable to get login credentials. Error: " & Err.Description & VBNewLine & Err.source, Nothing
Err.Clear
End If
On Error GoTo 0
'Delocate the reference
Set objQCResource = Nothing
Set objDataSheet = Nothing
End Function
**********************************************************************
Then use the below function like :
Example: -
'<<< ---- If Credential pop up is loaded, get the JCP credentials from the Datatable () :Begins ---->>>
If Browser("FlexApp").Dialog("Credential Popup").Exist(intConstWaitShort) Then
returnValue = Fun_GetCredentials("1035")
If Trim(CStr(returnValue)) = "0" Then
ExitComponentIteration
Else
arrCredentials = Split(returnValue, "|")
Browser("FlexApp").Dialog("Credential Popup").WinEdit("User name:").Set arrCredentials(0)
Browser("FlexApp").Dialog("Credential Popup").WinEdit("Password:").Set arrCredentials(1)
Browser("FlexApp").Dialog("Credential Popup").WinButton("OK").Click
End If
End If
'<<< --- If Credential pop up is loaded, get the JCP credentials from the Datatable () :Ends ------->>>
You need to upload a excel sheet in the QC resources tab, as below:
Key Value
UID naresh
PWD XXXX
**********************************************************************************************************************
'Name: Fun_GetCredentials
'Purpose: This function will get the credential details from the QC resource
'Argument(s): ip_intResourceId: Resource ID of the item
'Returns: 0: Indicates failure
' Credential details as: UserID|Password
'Example: returnValue = Fun_GetCredentials("1055")
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Revised:
'Revised by:
'Changes:
' **********************************************************************************************************************
Function Fun_GetCredentials(ip_intResourceId)
Dim objQCResource, objDataSheet, intDSRowCnt, intDSRowIndex, strUserID, strPwd
On Error Resume Next
'Get the resource object from QC with resource id as ip_intResourceId
Set objQCResource = QCUtil.QCConnection.QCResourceFactory.Item(ip_intResourceId)
'Download the resource file into the result directory
objQCResource.DownloadResource Environment("ResultDir"), True
'Get the sheet 1 of resource file from result directory into the design time datatable at sheet 1
DataTable.ImportSheet Environment("ResultDir") & "\" & objQCResource.Filename, 1, 1
'Get the object Datasheet from the design time datatable
Set objDataSheet = DataTable.GetSheet(1)
intDSRowCnt = objDataSheet.GetRowCount
'Loop for each row and validate the Key column, based on key value get value column value
For intDSRowIndex = 1 To intDSRowCnt
objDataSheet.SetCurrentRow(intDSRowIndex)
Select Case UCase(Trim(DataTable.Value(intConstKeyColIndex, 1)))
Case "UID"
strUserID = Trim(DataTable.Value(intConstValueColIndex, 1))
Case "PWD"
strPwd = Trim(DataTable.Value(intConstValueColIndex, 1))
End Select
Next
'Set the return value
If Trim(strUserID) <> "" And Trim(strPwd) <> "" Then
Fun_GetCredentials = strUserID & "|" & strPwd
Else
Fun_GetCredentials = 0
subJCP_EventReport "Fail", "Required credential details are not found. " & VBNewLine & "User ID = " & strUserID & VBNewLine & "Password = " & strPwd, Nothing
Exit Function
End If
'If unexpected error is reported here
If Trim(CStr(Err.Description)) <> "" Then
Fun_GetCredentials = 0
subJCP_EventReport "Fail", "Unable to get login credentials. Error: " & Err.Description & VBNewLine & Err.source, Nothing
Err.Clear
End If
On Error GoTo 0
'Delocate the reference
Set objQCResource = Nothing
Set objDataSheet = Nothing
End Function
**********************************************************************
Then use the below function like :
Example: -
'<<< ---- If Credential pop up is loaded, get the JCP credentials from the Datatable () :Begins ---->>>
If Browser("FlexApp").Dialog("Credential Popup").Exist(intConstWaitShort) Then
returnValue = Fun_GetCredentials("1035")
If Trim(CStr(returnValue)) = "0" Then
ExitComponentIteration
Else
arrCredentials = Split(returnValue, "|")
Browser("FlexApp").Dialog("Credential Popup").WinEdit("User name:").Set arrCredentials(0)
Browser("FlexApp").Dialog("Credential Popup").WinEdit("Password:").Set arrCredentials(1)
Browser("FlexApp").Dialog("Credential Popup").WinButton("OK").Click
End If
End If
'<<< --- If Credential pop up is loaded, get the JCP credentials from the Datatable () :Ends ------->>>
No comments:
Post a Comment