Skip to Content
Author's profile photo Tobias Hofmann

Testing SAP Portal applications with Selenium

Before an application can go into production, it needs to be tested. For Java there are several widely adopted test frameworks available like jUnit or TestNG. As these are used to test Java applications, what about web applications? How to test the UI that actually is constructed by using HTML, CSS, JSP and Javascript? This is not easy as you have to simulate user input and validate the generated response, including different browsers. The example in this blog is about testing a simple HTMLB checkbox.

Record the actions

A tool that can help you creating test cases for web applications is Selenium. Selenium offers a Firefox plugin called Selenium IDE that records what the user is clicking and translates these actions into HTML code. To test an application with Selenium the following steps are needed:

  1. Record the user action
  2. Select a test framework and save the recorded actions in Java code
  3. Import the generated code into your Java project

For the 1st step, Selenium offers a Firefox plugin called Selenium IDE. This means while the user actions can be replayed by several browsers (IE, Opera, FF, mobile, etc.), with the IDE only the user actions from a Firefox user can be recorded.


In the generated HTML code of Selenium, these values are shown as HTML:

    <td>Simple checkbox checked</td>

It is easy to see a possible problem here: how Selenium will find the actual HTML UI to test. In the above example the absolute path is used. When the portlet is not run as a single application but inside the portal the path will change. So make sure that the HTML code of the application is surrounded by a unique HTML that can serve as a starting point of the path.

As the HTML isn’t really useful, you’ll have to export the actions to a framework of your choice (I created my own export template called SAPHtmlbTestNG).


For those who already know Selenium: the IDE does not come with an export to TestNG and WebDriver, so you are bound to use Selenium RC. After exporting the test case you get Java code that actually can be used to run the tests:

public class test extends Tests {
    @Parameters({"seleniumServer", "seleniumPort", "seleniumBrowser", "testBaseUrl"})
    public test(String seleniumServer, int seleniumPort, String seleniumBrowser, String testBaseUrl) {
        super (seleniumServer, seleniumPort, seleniumBrowser, testBaseUrl);
    public void setUp() throws Exception {
    @Test public void testTest() throws Exception {"/irj/servlet/prt/portal/prtroot/com.tobias.test.testSelenium.testCheckbox");
    public void tearDown() throws Exception {

What does that actually mean? In the Selenium IDE I added a test that checks if a HTML element (e.g. a UI element like a button, checkbox or any other HTML element) is in the HTML code retrieved from the application:


For this Selenium identified the actual location of the element in question in the HTML source code:


Transformed into Java code, this reads as:


As for Selenium and testing: the actual Java code for executing the tests is Selenium. TestNG only serves as the framework running the Selenium Java code. That’s why there are testing annotations like @BeforeClass. TestNG will control the flow of the tests (starting selenium, running the tests, stopping selenium).

Running the Selenium test with TestNG

To run the tests a few things have to be considered:

  1. A Selenium server needs to be up and running
  2. TestNG can be controlled over a XML file

Starting the Selenium server can be done via a (ant/maven) script or manually. What is more interesting is the XML file that controls TestNG. There the actual tests to be performed together with parameters are defined:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="Suite" parallel="none">
    <parameter name="seleniumServer" value="localhost" />
    <parameter name="seleniumPort" value="4444" />
    <parameter name="seleniumBrowser" value="*chrome" />
    <parameter name="testBaseUrl" value="http://server:port/" />
    <parameter name="logonUser" value="test" />
    <parameter name="logonPassword" value="abc" />
        <listener class-name="com.tobias.test.selenium.Screenshot" />
      <test name="Test" preserve-order="true">
          <class name="com.tobias.test.selenium.checkbox.Checkbox"/>

The parameters are read by the annotation @Parameters and are used to define the selenium server. I added a listener that allows me to take a screenshot when a test fails and in the <test> section the actual tests are listened. There is only one test listened; to add more tests just add them by <class> definitions.

Run the test

After the tests are prepared and the tests and parameters are defined in the XML, the tests can run: either by invoking them directly in Eclipse or by running a script. TestNG will create HTML reports of the tests results.

Adding new test cases isn`t really hard when using the Selenium IDE. Where the IDE doesn`t help creating test cases, the developer can create them directly in Java. A benefit of Selenium is that you`ll end up having functional tests, as a real browser will make the calls to the application and validate the result.


From the 21 tests in my test suite, 2 failed. Because of my screenshot class added to my test suite, TestNG made a screenshot when the test failed.


Selenium used together with a framework like TestNG allows for functional testing of SAP web application. This is not bound to SAP Portal or WDJ apps, everything that has a HTML based UI can be tested. You have to keep in mind that even as UI testing is important, you should not focus solely on it. Unit and service tests should make the largest part in your test efforts. You won’t get OOTB a lot of UI tests, that process needs some time. It would be nice to get from SAP a predefined set of tests that can be run with every patch/ EHP installation, but it is up to you to create these tests.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Gregor Wolf
      Gregor Wolf

      Hi Tobias,

      great to see others picking up Selenium. As you might be aware I've created the SeleniumABAP project on Code Exchange which allows you to run tests from within the ABAP Stack as ABAPUnit or eCATT tests. You can watch a replay of my talk at Mastering SAP Technologies.

      Best regards


      Author's profile photo Former Member
      Former Member

      Hi Tobias,

      Excellent job!

      In Brazil I automate SAP testing with Selenium RC.

      I wrote a post about this job.

      Best regards

      Eduardo Souza

      Author's profile photo Former Member
      Former Member

      Hi Eduardo,

      I am not able to access you link.

      Could you please provide me correct link.

      In my new project, we have to automate SAP, hence i am looking for option if we can do that using selenium + java.

      Your help is much appreciated.



      Author's profile photo Former Member
      Former Member

      Is it for SAP UI5?

      Author's profile photo Priya Jha
      Priya Jha

      Hi Tobias/All,

                      I am working on SAP Selenium webdriver. I wanted to know that after every test

                      when the HTML reports are generated,how can we mail the same to the                             concerned person?

                      Searched for it on the net but couldn't find.

                     Any help will be greatly appreciated.

      Best regards,

      Priya Jha

      Author's profile photo Former Member
      Former Member

      Hi Priya/Gregor/All,

      I also started working on CRM WEB UI with selenium webdriver.

      I have a few questions over here.

      I want to export a value from selenium wedriver and import same value in sap tools like eCATT/CBTA and proceed the test. ( It's like integration scenario which consist of CRM UI using selenium webdriver, SAP GUI using eCATT/CBTA in a single test ).

      Can you kindly help me in this.



      Author's profile photo Former Member
      Former Member

      Hi Priya ,

      Its good to use Jenkins, there you can not only schedule nightly builds but aslo reports can be automatically triggered to respective person.



      Author's profile photo Former Member
      Former Member

      Hello Tobias

      I got your point, thanks for the post.

      I am working as a selenium tester in a small size firm. I was always wondering how to test SAP product using selenium automation testing tool here.

      Author's profile photo Former Member
      Former Member

      hi Mazhar

      Did you use Selenium IDE , how did you get firefox to recognize the SAP object

      is the format SAPHtmlbTestNG required


      Author's profile photo Former Member
      Former Member

      Hi Tobias,

      In my new project, we have to automate SAP web application, hence i am looking for option if we can do that using selenium + java.

      Your help is much appreciated.



      Author's profile photo Loraine Silva Santana
      Loraine Silva Santana


      Sabe me informar se a ferramenta Sellenium, server para tb utilizarmos no SAP com o conceito de esteira (DevOps)?


      Loraine Sant´Ana