Reusable SAP login code (SAP, BPT, UFT, QTP)

Nine years ago, I published an article about reusable QTP codes. I am reposting the old solution here hoping someone can pick something from it and improve it for their own purpose. I dont see much posts similar to this in the past years and I am not into blogging really.

Problem statement:

A reusable SAP login code is required but it has to be generic enough to cater login requirement across different SAP system clients.

Solution:

1.) Need to identify a function that addresses this test automation requirement. The location of the function varies across implementation; it can be implemented by a copy-paste friendly function or add the function as an additional resource of your test (File>Setting). In BPT, this can be implemented thru the library function, which is manipulated thru the application area and associate the component that requires the function.

'*FUNCTION DECLARATION**************************************************************************************************************

'* NAME: sapLogin

'* AUTHOR: Ely Repolido

'* REMARKS:

'* -

'* ARGUMENTS:

'* test_object - The logical name or description of the browser object.

'* sapSystemClient - The system and client string where you want the login to take lace i.e. A53.310 or Q53.110. This is case insensitive. sapLogin is smart enough to know which system you need to log on to even if you indicate "ECC Development(A53).310". It only needs to recognize if you put in A53, Q53, S53, 110, 210, 310. Ideal usage is of course the shortest; "Q53.110", this will be enough for the function.

'* sapUserName - The ECC account name

'* sapPassword - ECC account password

'* sapLanguage - Language you need. Indicate "" if you’re not sure what exactly you have to give. Usually this has the value of"EN.

'*

'* RETURN:

'* - A boolean value to indicate if the login was successful or not (TRUE or FALSE only)

'*

'*************************************************************************************************************************************


Public Function sapLogin(test_object, sapSystemClient, sapUserName, sapPassword, sapLanguage)

Dim constSystemValues

Dim constClientValues

constSystemValues="A53 Q53 S53"

constClientValues="110 210 310"

' do nothing if any of the parameters is empty [except language]

If Len(trim(sapSystemClient))=0 or Len(trim(sapUserName))=0 or Len(trim(sapPassword))=0 Then

sapLogin=False

Exit Function

End If

' format case insensitive parameters

sapSystemClient=Trim(LCase(sapSystemClient))

sapUserName=Trim(LCase(sapUserName))

if len(trim(sapLanguage))=0 then sapLanguage="en"

' the 4th char of the sapSystemClient parameter should be a dot

If Not(InStr(sapSystemClient,".")=4) Then

sapLogin=False

Exit Function

End If

' decipher the system and the client values from the sapSystemClient parameter

arrSystemClient=Split(sapSystemClient,".")

If Not(UBound(arrSystemClient)=1) Then

sapLogin=False

Exit Function

End If

' the system should be valid

Dim varSystem

varSystem=arrSystemClient(0)

If Not(InStr(Lcase(constSystemValues),LCase(varSystem))>0) Then

sapLogin=False

Exit Function

End If

' the client should be valid

Dim varClient

varClient=arrSystemClient(1)

If Not(InStr(constClientValues,varClient)>0) Then

sapLogin=False

Exit Function

End If

' close current ECC sessions and proceed to login sequence

SAPGuiUtil.CloseConnections

' this is the equivalent code of the design steps

SAPGuiUtil.AutoLogonByIP boxSelector(varSystem), varClient, sapUserName, sapPassword, sapLanguage

' verify if the main window is displayed with text "SAP Easy Access" in the window title

varWinText=SAPGuiSession("type:=GuiSession").SAPGuiWindow("type:=GuiMainWindow").GetROProperty("Text")

If InStr(varWinText,"SAP Easy Access")>0 Then

sapLogin=True

End If

End Function

RegisterUserFunc "SAPGuiSession", "Login", "sapLogin"



'* FUNCTION DECLARATION**************************************************************************************************************

'* NAME: boxSelector

'* AUTHOR: Ely Repolido

'* REMARKS:

'* - This component works exclusively for the sapLogin function (found also in this library).

'*

'* ARGUMENTS:

'* - 3 character string that identifies the target ECC system i.e. "A53", "S53", "Q53"

'*

'* RETURN:

'* - This function returns the connection string (equivalent IP of the server) need by the sapLogin function

'*

'*************************************************************************************************************************************

Private Function boxSelector(targetSystem)

If Instr(UCase(targetSystem),"A53")>0 Then boxSelector="/H/145.26.53.170/S/3253" 'boxIP="/H/145.26.53.170/S/3253"

If Instr(UCase(targetSystem),"S53")>0 Then boxSelector="/H/145.26.54.126/S/3253" ' boxIP="/H/145.26.54.126/S/3253"

If Instr(UCase(targetSystem),"Q53")>0 Then boxSelector="/H/145.26.55.43/S/3253" ' boxIP="/H/145.26.55.43/S/3253"

End Function


2.)In the calling component (for BPT framework), call the function this way:


Parameter("LoginOutput")= _

SAPGuiSession("type:=GuiSession").Login( _

parameter("sapSystemClient"), _

parameter("sapUserName"), _

parameter("sapPassword"), _

parameter("sapLanguage"))



3.) Note that before adaption to your environment, you need to identify the IP addresses of the target environments. Once identified, go to the boxSelector function and update the IP addresses. Modify the logic branch as needed.

To view or add a comment, sign in

More articles by Ely Repolido

Others also viewed

Explore content categories