Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
sabatale
Contributor
3,308
Selenium is easily one of the most popular open-source test automation frameworks available, with over 18K stars on GitHub and thousands of users and developers around the world. You are likely to see it running in businesses of all sizes, including large SAP customers. On the other end, while by no mean as popular as Selenium, SAP CBTA is a SAP automation testing proprietary tool that comes with a major limitation: only SAP technologies are officially supported (see SAP Note 2436142 for more information).

Can you seamlessly integrate SAP CBTA and Selenium to automate a given business process? Unlike HP, Tricentis or Worksoft, there is no native integration available to you. However, since CBTA is built with Visual Basic Script (VBS) and gives you the option to build your own functions, you can still give it a shot.

None of this is supported by SAP. Always build a prototype before trying anything in Production, and make sure to have the right experts (internal or external resources) on your team!


Selenium being a framework, you have multiple ways to use it. Because it is visually more appealing and low-code, I will be using Selenium IDE (a record & playback browser extension with an integrated development environment) and Selenium Command-line Runner (command-line execution for Selenium .side scripts).

Our objective: Execute a single CBTA script in which Selenium will take over the execution for 2 steps. The script will be running against SAP CRM (here, SAP Solution Manager) and Google Chrome. We also want Selenium to run unnoticed and reuse the browser window that was first triggered by SAP CBTA.

First, build a simple CBTA script against Google Chrome. In my example I have my user perform the following actions: 1) logon to the CRM; 2) click the "Change Request Management" menu link; 3) click the "Change Documents" link; 4) click the "Search" button.


Second, install Selenium IDE for Chrome and create a new project. Set the playback URL (e.g. CRM home page) and start recording the exact same steps as for CBTA. Remove all but the two last steps (3 and 4 from the previous list). Obviously, this is just an example but it illustrates one of 3 common reasons why you would need Selenium:




  1. Automate actions that are not natively supported by CBTA, or for which you already have workarounds available with Selenium: for example, repetitive loops or technologies such as Java Applets or Silverlight;

  2. Make use of Selenium alternative URIs feature, meaning the tool always keeps a list of 4-5 different object identifiers (the unique ID that defines the position of an object on the screen) and will try them one after another until it can find one that works;

  3. Leverage other tools relying on the Selenium framework to automate non-web technologies, or plugins to perform different types of testing such as Visual Testing.


It is important to note that your script needs to start with the "open" command, otherwise Selenium will not launch at all. Do not worry, this does not mean a new browser window will open instead of reusing the existing one. Save your Selenium project (.side format).


Third, make sure the Runtime Library Manager (RTL) on your SAP Solution Manager system is working. You can follow SAP Note 1912801 for customizing. If your server is running on HTTP protocol (meh), then do not select the SSL option in the webservice configuration. The RTL allows you to create VBS scripts that can be invoked by CBTA during execution - think of it as building Z* code for custom requirements. Navigate to the "Test Suite - Administration" tile and click the "Customize RTL" link to launch the RTL.


Again the CBTA documentation does a fantastic job at explaining how things work. You can refer to the "CBTA 3.0 - Runtime Library Manager" PDF to learn how to set a local storage path for your functions and synchronize them with SAP CBTA. Create a new .vbs file from scratch in your favorite IDE (e.g. Atom) or from a standard template.

Outside of the required template sections (see documentation), my core function has 2 main features:

  • Selenium_CBTA_Impl() defines the different input parameters that we use to pass data to the Selenium script - here, the first 2 inputs define my .vbs script default local filepath while the rest are set to blank;

  • Set WshShell triggers the command-line for Selenium execution. There are different ways to reuse an existing browser window (the ones called by CBTA when executed). Because SAP CBTA can execute scripts on the Google Chrome debug port by default, one simple option is to start Selenium on the same port - for example:"selenium-side-runner "& Input1 & Input2 &" -c ""browserName=chrome goog:chromeOptions.debuggerAddress='127.0.0.1:9222'""


You will notice the function returns "DONE" after the command is executed. However, since there is no logic to determine whether the Selenium execution has been successful, it will always return "DONE" as the output parameter. Make sure to implement your own logic (e.g. checking the Selenium execution log for PASS or FAIL result).
Function Selenium_CBTA_Impl( Input1, Input2, Input3, Input4, Options ) 'internal

Selenium_CBTA_Impl = "No output - Initial value..!" 'initializes the returned value

'START - Set default input parameters if empty
If IsNull(Input1) Then
Input1="C:\VBS\" '1 = path where Selenium scripts are located
End If

If IsNull(Input2) Then
Input2 = "SAP-CRM-Change.side" '2 = script name with .side extension
End If

If IsNull(Input3) Then
Input3 = ""
End If

If IsNull(Input4) Then
Input4 = ""
End If
'END - Set default input parameters if empty

'START - Run Selenium command prompt
Set WshShell = WScript.CreateObject("WScript.Shell")
Const waitOnReturn = True 'wait for command to finish
Const windowStyle = 0 'runs in background

Command = "selenium-side-runner "& Input1 & Input2 &" -c ""browserName=chrome goog:chromeOptions.debuggerAddress='127.0.0.1:9222'"" --output-directory=C:\Temp\"

WshShell.Run Command, windowStyle, waitOnReturn
'END - Run Selenium command prompt

Selenium_CBTA_Impl = "DONE" 'sets returned value (output parameter)

End Function

 

Now, back to the Test Composition Environment, disable the steps you wish to automate with Selenium (in my case, the last two) and add a new CBTA Default Component of type "CBTA_*_A_INVOKE_FUNCTION" or "CBTA_*_A_EXECUTESTATEMENT". Both components call a custom script as part of the test execution but there are a few key differences as to when you should use one or the other. Please refer to the CBTA Frontend documentation.

Remember my Selenium_CBTA_Impl( Input1, Input2, Input3, Input4, Options )? With the "INVOKE_FUNCTION" component, each of those inputs is automatically mapped to PARAMETER1, etc. In my case, I do not need any but you can obviously use those parameters to pass data to Selenium.


Save the script and run it. You should notice... no difference whatsoever. Because we chose to trigger Selenium in the background, there is no way to differentiate it from CBTA without having a look at the execution report:


Voilà!
4 Comments
Labels in this area