Skip to Content

Add Automated System Tests with the SAPUI5 Test Recorder to Your CI/CD Pipeline

test
0 %
Add Automated System Tests with the SAPUI5 Test Recorder to Your CI/CD Pipeline
Details

Add Automated System Tests with the SAPUI5 Test Recorder to Your CI/CD Pipeline

September 15, 2020
Created by
May 10, 2020
Use the SAPUI5 Test Recorder to create system tests with UIVeri5 against the user interface of an SAPUI5/SAP Fiori application. Add the tests to a continuous integration and delivery pipeline to run them automatically.

You will learn

  • How to create system tests with UIVeri5 using the UI5 Test Recorder
  • How to create a CI/CD pipeline with project “Piper”
  • How to add system tests as automated steps to your CI/CD pipeline

Prerequisites

  • You use SAPUI5 in version 1.74 or higher.
  • You have installed and configured a local Git client.
  • You have installed Node JS in version 8.0 or higher.
  • You have installed Visual Studio Code.
  • You have installed UIVeri5 using the following command:

    npm install @ui5/uiveri5 -g
    
  • Your Google Chrome version is up to date. See Update Google Chrome.
  • You have a Jenkins instance that is preconfigured for using project “Piper”. See Configuration.
  • You have an account and a repository in GitHub.

This tutorial only applies to SAPUI5 in version 1.74 or higher. If you use an older version of SAPUI5, have a look at Add Automated System Tests to Your CI/CD Pipeline, instead.

What Is This Tutorial About?

In this tutorial, you’ll create and run automated system tests with UIVeri5 against a simple shopping app for electronic devices. Your test application has basic functions such as a product catalog sorted by categories, a search option, and an add to cart function.

The tutorial consists of three main stages:

Main Stages of Tutorial
  1. Set up your project and manually go through your test scenario before starting to code it.

  2. Create and run system tests with UIVeri5 to check the home screen of your application, its product search, and the navigation to a product.

  3. Automate your system tests by integrating them into a CI/CD pipeline.

About System Tests with UIVeri5

UIVeri5 is an SAP open-source JavaScript testing framework for SAPUI5 applications. It drives a real browser for your deployed app and simulates authentic user scenarios. System tests check both front-end and back-end and make sure that all pieces of an application work well together.

The following graphic shows the positioning of system tests with UIVeri5 compared to other testing methods and tools. The arrow shape illustrates the granularity of the methods: Compared to unit, component, or integration tests, system tests examine less details and focus on crucial workflows, instead.

Test Comparison

For more information about testing with UIVeri5, have a look at these blogs:

About the SAPUI5 Test Recorder

The SAPUI5 Test Recorder is a tool that helps you create integration and system tests. You can use it in any SAPUI5 application to inspect its user interface, view the control properties, and get code snippets for OPA5 and UIVeri5 tests. As of version 1.74, it is part of the SAPUI5 framework.

For more information about the SAPUI5 Test Recorder, see Test Recorder.

About CI/CD with Project “Piper”

Project “Piper” is one of SAP’s solutions for continuous integration and delivery. It provides pre-configured Jenkins pipelines, which you can use in your own Jenkins master infrastructure and adapt according your needs. Project “Piper” consists of two different parts:

  • A shared library, which contains the description of steps, scenarios, and utilities that are required to use Jenkins pipelines
  • A set of Docker images that can be used to implement best practice processes

For more information about SAP solutions for CI/CD, see:


Step 1: Set up your test project

In Visual Studio Code, set up your UIVeri5 test project.

  1. Open Visual Studio Code.

  2. Choose View Command Palette… Git:Clone.

  3. As Repository URL, enter:

    https://github.com/SAP-samples/teched2019-uiveri5.git
    
  4. Select a folder of your choice into which to clone the test repository by choosing Select Repository Location.

  5. When asked if you would like to open the cloned repository, choose Open.

    As a result, the project TECHED2019-UIVERI5 is loaded into the EXPLORER pane and you can see its resources in the outline:

    Resources in the EXPLORER pane

    Like all system tests with UIVeri5, you’ll define your tests through different files:

    • (a) The conf.js file:

      In this file, you can define, for example, the browser and reporter that are used, the base URL, and the credentials for your login dialog.

    • (b) The spec.js file (in this case, it’s called teched.spec.js):

      In this file, you’ll define your test scenario, which comprises steps that are triggered one after the other. Within the test scenario, you’ll refer to your page objects.

    • (c) Page objects (in this case, you have home.js for the home screen and product.js for the detail view of a product):

      Page objects are design patterns that represent a significant part of an app, for example, a view. They group two kinds of elements:

      • Actions, for example, entering a specific text in a search field and triggering the search
      • Assertions, for example, getting a search result that matches the previously entered text

      Page objects use locators to identify specific elements on the screen. Thereby, they allow test runners to see and do anything a real user would. Page objects reside in the pages folder of your project.

  6. Open the conf.js file.

    In this file, you’ll define the base URL of your test application.

  7. Add the following line into the exports.config property:

    baseUrl: "https://sapui5.hana.ondemand.com/test-resources/sap/m/demokit/cart/webapp/index.html",
    

    Now, your project setup is ready. Make sure that your code looks as follows and choose File Save.

    Project Setup

    If you want to set up a project for an application that is protected by credentials, you need to add authentication configurations. See Authentication.

  8. To check if the test execution works, make sure that you’re in the root folder of your project, choose Terminal New Terminal, and enter the following command:

    uiveri5
    

    As a result, the browser briefly opens to execute the tests. However, as you haven’t defined any tests, yet, the application doesn’t load.

  9. In the terminal response, check if the test execution has been successful:

    Terminal Response: Successful
Log on to answer question
Step 2: Walk through the test scenario

Manually, familiarize yourself with your test scenario before starting to code it. Later, you’ll automate the following steps so that they are automatically executed during your system tests.

  1. In Google Chrome, use the following URL to access the home screen of your shopping application:

    https://sapui5.hana.ondemand.com/test-resources/sap/m/demokit/cart/webapp/index.html
    
  2. Check how many product categories are shown in the Product Catalog:

    Product Categories in the Product Catalog

  3. In the Product Catalog, search for Watch and check if the displayed results match your request:

    Comparison between Search Term and Search Result
  4. Choose Flat Watch HD32 and check if the product appears in the detailed view:

    Detail View of Flat Watch HD32
  5. Check if at the bottom right of the detailed view, there is an Add to Cart button:

    Add to Cart Button
Log on to answer question
Step 3: Test the home screen

Implement a test that checks if in the product catalog on the home screen of your application, all categories are shown. To verify this, the expected number of product categories are compared with the displayed ones.

  1. From the EXPLORER pane in Visual Studio Code, open teched.spec.js.

    In this file, you’ll define the steps of your test scenario and within them, refer to your page objects.

  2. Implement the it function by adding the skeleton of the home screen test:

    it("Should validate the home screen", function () {
    
    });
    

    Your code should now look as follows:

    Skeleton of Home Screen Test
  3. To specify what you want to check, add the following line to the test skeleton:

    Then.onTheHomePage.iShouldSeeAllCategories();
    

    iShouldSeeAllCategories is a reference to the test function that you’ll define in the following.

    Now, your first test scenario is complete. Make sure that it looks as follows and choose File Save.

    First Scenario of Home Screen Test
  4. From the EXPLORER pane, open pages home.js.

    This file represents the page object for your home screen. In page objects, you can define actions that are performed during a test and make assertions. In this specific case, however, you won’t implement an action that is executed during the test but only check the home screen. Therefore, leave the actions function empty and only make assertions:

    Empty Actions Section in Home Screen Test
  5. In the Shopping Cart application in Google Chrome, press CTRL + SHIFT + ALT + T (if you use a Windows system) or SHIFT + CTRL + OPTION + T (if you use a Mac system) to open the Test Recorder in a new browser window.

  6. In your sample application, right-click the first entry of the Categories list and choose Highlight. As a result, the Test Recorder highlights the entry to indicate its activity:

    Highlighting of First Category

    Now, the Test Recorder provides a code snippet for your test:

    Please make sure that the dialect UIVeri5 is selected.

    Code Snippet for List Item
  7. Copy this code snippet into the assertions section of your home.js page object.

  8. To identify all elements, remove the bindingPath and interaction:

    Remove Binding Path and Interaction
  9. Add a suitable name for your assertion and the following code snippets:

    Add Name and Additional Code Snippets for iShouldSeeAllCategories

    Now, the page object for your home screen is ready. Make sure that your code looks as follows and choose File Save.

    Page Object for Home Screen Test
  10. To run the test, execute the following command in the terminal:

    uiveri5
    

    As a result, the browser opens and the home screen is loaded.

  11. In the terminal response, check if the test has been passed successfully:

    Status: Passed
Log on to answer question
Step 4: Test the product search

Implement a test that checks if when you search for a product, the search results are displayed accordingly. To verify this, the entered search term is compared with the search result.

  1. From the EXPLORER pane in Visual Studio Code, open teched.spec.js.

  2. Into the describe function, add the skeleton of the product search test:

    it("Should search for a product", function () {
    
    });
    

    Your code should now look as follows:

    Skeleton of Product Search Test
  3. Within the test skeleton, add the following interaction, which will be defined later:

    When.onTheHomePage.iSearchForProduct();
    
  4. Then, add the expected behavior, namely that the product list is filtered:

    Then.onTheHomePage.theProductListShouldBeFiltered();
    

    Now, your test is complete. Make sure that it looks as follows and choose File Save.

    Product Search Test
  5. From the EXPLORER pane, open pages home.js.

  6. In the Shopping Cart application in Google Chrome, press CTRL + SHIFT + ALT + T (if you use a Windows system) or SHIFT + CTRL + OPTION + T (if you use a Mac system) to open the Test Recorder in a new browser window.

  7. In your sample application, right-click the search field and choose Enter Text. As a result, the Test Recorder highlights the search field to indicate its activity:

    Highlighted Search Field

    Now, the Test Recorder provides a code snippet for your test:

    Please make sure that the dialect UIVeri5 is selected.

    Code Snippet for Search Field
  8. Copy this code snippet into the actions section of your home.js page object.

  9. Add a suitable name for your assertion and define that during your test, the test runner should search for Watch:

    Name and Additional Snippets for iSearchForProduct

    Next, make an assertion about the title of the product that is displayed first in the filtered catalog.

  10. After your first assertion, add a comma.

  11. In the search field of your sample application, enter Watch.

  12. Right-click the first product in the filtered catalog and choose Highlight. As a result, the Test Recorder highlights the list entry to indicate its activity:

    Highlighted List Entry

    Now, the Test Recorder provides a code snippet for your test:

    Please make sure that the dialect UIVeri5 is selected.

    Code Snippet for List Entry
  13. Copy this code snippet into the assertions section of your home.js.

  14. Remove the bindingPath and interaction:

    Remove Binding Path and Interaction
  15. Add a suitable name for your assertion and the following code snippets:

    Page Object for List Entry Test

    Now, the page object for your home screen is ready. Make sure that your code looks as follows and choose File Save.

    Added Code Snippets
  16. To run the test, execute the following command in the terminal:

    uiveri5
    

    As a result, the browser opens and you can watch the automated test software execute the actions you have defined.

  17. In the terminal response, check if the test has been passed successfully:

    Status: Passed
Log on to answer question
Step 5: Test the navigation to a product

Check if the following two statements are true:

  • When you select a product from the filtered catalog, it is shown in the detailed view. To verify this, compare the selected product title with the title in the detailed view.
  • In the detailed view, there is an Add to cart button.
  1. From the EXPLORER pane in Visual Studio Code, open teched.spec.js.

  2. Into the describe function, add the skeleton of the product search test:

    it("Should navigate to the product", function () {
    
      });
    

    Your code should now look as follows:

    Skeleton of Product Search Test
  3. Within the test skeleton, add the following interaction with reference to your home.js:

    When.onTheHomePage.iSelectTheFirstProduct();
    
  4. Then, add the first behavior you expect, namely that the product title appears in the detail view:

    Then.onTheProductPage.theProductTitleIsShown();
    
  5. Next, add your second expectation, which is that the Add to cart button appears:

    Then.onTheProductPage.theProductCouldBeOrdered();
    

    Now, your test is complete. Make sure that it looks as follows and choose File Save.

    Product Search Test
  6. From the EXPLORER pane, open pages home.js.

  7. Add a comma after the close bracket of the first action.

  8. In the Shopping Cart application in Google Chrome, press CTRL + SHIFT + ALT + T (if you use a Windows system) or SHIFT + CTRL + OPTION + T (if you use a Mac system) to open the SAPUI5 Test Recorder in a new browser window.

  9. In your sample application, right-click the title of the first search result and choose Press. As a result, the Test Recorder highlights the title to indicate its activity:

    Highlighted Title

    Now, the Test Recorder provides a code snippet for your test:

    Please make sure that the dialect UIVeri5 is selected.

    Code Snippet for Title
  10. Copy this code snippet into the actions section of your home.js.

  11. Adapt the name of the action. With this action, you define that during your test, the test runner clicks on the first search result:

    Name for Product Selection Test

    Now, the page object for your home screen is ready. Make sure that it looks as follows and choose File Save.

    Page Object for Home Screenshot
  12. From the Explorer pane, open pages product.js.

    This file represents the page object for the detail view of your selected product.

  13. In the Shopping Cart application in Google Chrome, right-click the header of the detail view and choose Highlight. As a result, the Test Recorder highlights the header to indicate its activity:

    Highlighted Header

    Now, the Test Recorder provides a code snippet for your test:

    Please make sure that the dialect UIVeri5 is selected.

    Code Snippet for Header
  14. Copy this code snippet into the assertions section of your product.js.

  15. Add a suitable name for your action and the following code snippets:

    Added Name and Code Snippets

    Now, your page object should look as follows:

    Page Object for Product Navigation

    To verify if there is an Add to Cart button in the detail view of your selected product, add another assertion.

  16. Add a comma after your last assertion.

  17. In the Shopping Cart application in Google Chrome, right-click the Add to Cart button and choose Highlight. As a result, the Test Recorder highlights the button to indicate its activity:

    Highlighted Button

    Now, the Test Recorder provides a code snippet for your test:

    Please make sure that the dialect UIVeri5 is selected.

    Code Snippet for Button
  18. Copy this code snippet into the assertions section of your product.js.

  19. Add a suitable name for your assertion and add the following code snippet to define that you expect the Add to Cart button to be displayed:

    Added Name and Code Snippets

    Now, the page object for the detail view of your selected product is ready. Make sure that it looks as follows and choose File Save.

    Page Object with Button Test
  20. To run the test, execute the following command in the terminal:

    uiveri5
    
  21. In the terminal response, check if the test has been passed successfully:

    Status: Passed
In which file do you define actions and assertions for the detail view of a specific product in your app?
×
Step 6: Integrate your system tests into a CI/CD pipeline

Automate your system tests by integrating them into a CI/CD pipeline.

  1. Execute a Git commit and push the content of your local TECHED2019-UIVERI5 project into your GitHub repository.

  2. In Google Chrome, open and sign in to your Jenkins instance.

  3. To create a new Jenkins pipeline, choose New Item.

  4. As item name, enter UI-Testing (or any other name you like), select Pipeline, and choose OK.

  5. Switch to the Pipeline tab.

    For your CI/CD pipeline, you’ll use the library of project “Piper”. It contains all steps you need to automate the tests you have implemented.

  6. In the Script area, add the skeleton of your pipeline with reference to the project “Piper” library:

    #!/usr/bin/env groovy
    @Library(['piper-lib-os']) _
    
    //Setup the skeleton for Jenkins based Runs
    node {
        stage('System Tests') {
    
        }
    }
    

    Make sure that your script looks as follows and choose Save:

    Screenshot Pipeline Skeleton in Jenkins
  7. To run your newly created pipeline, choose Build Now.

    As a result, your build is scheduled.

  8. In the Build History, choose #1 to check the results of your first pipeline run.

  9. To check the log for failures due to syntax issues, choose Console Output. Make sure that the (empty) pipeline has run successfully:

    Console Output in Jenkins: Successful

    Next, implement a pipeline stage for your system tests with UIVeri5.

  10. From the sidebar, choose Back to Project.

  11. Choose Configure and switch to the Pipeline tab.

  12. Add the following content to your System Tests stage:

    deleteDir()
    
    // Clone code from the system test repository
    git '<YOUR GITHUB REPOSITORY>'
    
    // checkout the master branch
    sh 'git checkout master'
    
    // With this next step UIVeri5 tests can be executed.
    uiVeri5ExecuteTests script: this
    
    // HTML Publisher plugin
    // Publish HTML reports
    // Publish Test Report for UIveri5 on Jenkins  
    publishHTML target: [
        allowMissing: true,
        alwaysLinkToLastBuild: true,
        keepAll: true,
        reportDir: 'target/report/screenshots/',
        reportFiles: "report.html",
        reportName: "UIVeri5 Test Report"
    ]
    
  13. In the script, exchange <YOUR GITHUB REPOSITORY> with the URL of the GitHub repository into which you have pushed your local TECHED2019-UIVERI5 project.

    Make sure that your script looks as follows and choose Save:

    Pipeline Script Part 1Pipeline Script Part 2
  14. To run your pipeline, choose Build Now.

    As a result, your build is scheduled.

    The pipeline run might take a few minutes.

  15. Choose #2 to view the results of your second pipeline run. Make sure that it has run successfully:

    Console Output in Jenkins: Successful
  16. From the sidebar, choose UIVeri5 Test Report.

    Here, you get an overview of all test results together with screenshots from their execution:

    UIVeri5 Test Report
Log on to answer question

Congratulations!

You have successfully created different system tests with UIVeri5 and integrated them into a continuous integration and delivery pipeline.


Next Steps

Back to top