Selenium

Selenium is an open source framework used to automate tests carried out on a web browser. Testerum takes the Selenium library to the next level of accessibility and maintainability. You don't need anymore to write Selenium tests using a programming language and long scripts that are hard to maintain. Testerum allows you to easily create Selenium tests in a visual manner with no programming knowledge required.

If you want to see the list of all Selenium steps:
  1. Navigate to Steps in the top menu bar.
  2. Expand the Basic Steps => Selenium node.
  3. To see all the Selenium steps, expand all the Selenium sub-nodes.
img 1
Selenium Steps

First Selenium Test

Let's have a look at a very basic Selenium test (img 2):
  1. This test is composed only by Selenium steps
  2. To edit a parameter of a step click the step to expand and see the Parameters Details node.
  3. In order to set a value to a particular parameter or edit an existing one click the Edit button.
img 2
Selenium Basic Test

Navigate to & Switch context

The first thing you will have to do when working with Selenium is probably to launch a browser and navigate to a page. Navigating to a page is simple, it can be done by adding a step "Given the page at url <<url>> is open".

Navigate to a page. This step launches for you the browser and navigates to the page.

Element Locator

Most of the Selenium steps require to interact with an element such as: clicking an element, typing a text into a field, etc. All the steps that require you to target an HTML element will have a parameter called elementLocator The value of the elementLocator parameter needs to have the following syntax: elementLocatorType = elementLocatorExpression

The elementLocatorType can be one of following:

The part elementLocatorType= is optional. If it's missing, the default locator type will be CSS. For example, nav > .home will match elements with the CSS class home that are direct children of a nav element. Tip: If multiple elements match, a step will choose only the first one, unless noted otherwise in the step's description.

Example with different Element Locators:
Example with different Element Locators

Selenium Settings

Certain aspects of Selenium can be configured. For this click the Settings from the menu bar (img 3).
img 3
Menu bar Settings
Selenium Settings:(img 4)
  1. After step delay: this setting sets a time delay between each Selenium Action. For example, setting a value of 1000, it will produce a delay of 1 second between each action.
  2. Browser:
    • In this category you can define on which browser the tests will be executed on: Chrome, Firefox, Opera, Edge, Internet Explorer or a Remote Browser.
    • You can specify what Selenium Driver to be used for your browser. By default will use the latest known version. If you want to add a newer or a custom Selenium Driver see: Add a new Selenium driver
    • By default Selenium expects that the specified browser is installed on your system. If this is not your case, you can specify the location of the browser to be used.
    • Headless Mode: There are cases when you may need to run automation tests in ‘headless’ mode, i.e., when no browser is being displayed.
      Three Benefits Of Headless Browser Testing:
      • Executing tests on servers
        There may be setups where installing a browser is not possible, such as servers. In these cases, headless browsers help run automation tests easily.
      • Improves speed and performance
        Since this type of testing does not actually open a browser, the system saves the processing power that would otherwise be used in a real browser test. Consequently, the tests are executed faster.
      • Helps you multitask
        You can use your browser or your machine to do anything else while the tests run in the background. It saves hours of time that is otherwise spent staring at the screen.
  3. Leave browser open after test: Possible values are: false, true or onFailure. This option is useful in development.
  4. Take screenshot after each step: After each Selenium step a screenshot will be taken helping you debugging problems on server.
  5. Wait timeout (millis): This tells Selenium for how long it should try executing an action before failing the test.
    For example you have a command to click an element. Selenium will try to click that element for this specified amount of time. If the element is not present on the page for this amount of time the test will fail.
img 4
Menu bar Settings

Add a new Selenium driver

Testerum comes bundled with Selenium drivers for the most popular browsers (Chrome, Firefox, Safari, Internet Explorer, Edge, and Opera). From time to time, browser vendors release a new version of their browser that no longer works with the latest version of the Selenium driver that Testerum has. At the same time, browser vendors also release a newer version of the Selenium driver which works with the new browser version. When this happens, you can either wait until a new Testerum version will be released, which includes the new driver, or download the new driver yourself, and let Testerum know about it.

How to add a new Selenium driver to Testerum

  1. First, you will need to download the new Selenium driver. You can do that from one of the following places: Note:
    • There is no need to download the Selenium driver for Safari - it comes installed together with the Safari browser.
    • Since there will be no new versions of Internet Explorer (the last version is 11), there is no need to download new drivers for it.
  2. After downloading the driver, extract the executable file (e.g. operadriver.exe) from the downloaded archive in a directory where you have write access.

  3. Rename the executable file to contain the platform and the version, e.g. operadriver_win64_75.0.3770.100.exe. For the platform part, use win64, mac64, or linux64, depending on your operating system.

  4. In the same folder as the extracted driver, create a text file with the same name as the driver file, but having the .json extension: operadriver_win64_75.0.3770.100.json.

    The content of the file should have the following format:

    {
        "driverFile": "operadriver_win64_75.0.3770.100.exe",
        "driverVersion": "75.0.3770.100",
        "browserVersions": ["61", "62"]
    }
    The driverFile specifies the name of the executable file.
    The driverVersion is the version of the driver.
    The browserVersions lists all the browser versions supported by this driver.

  5. Copy the executable file (operadriver_win64_75.0.3770.100.exe) and the JSON file (operadriver_win64_75.0.3770.100.json) to the Selenium drivers directory, for example {TESTERUM INSTALLATION DIRECTORY}\selenium-drivers\opera.

  6. Restart Testerum so it can pick up the new driver.

Command line settings

When you execute the tests from a CI/CD environment or from a command line you can overwrite the default Selenium settings. For this please check the Runner Selenium Settings section.

Integrate Selenium tests with Jenkins

In the last few years, Jenkins has become very popular. It’s one of the best open-source tools that allow you to automate the build and deploy process of your web applications. It is also well-known for its capability of running automated tests without human interaction.

In this section you will learn step-by-step how to integrate Selenium tests created with Testerum in Jenkins.

Prerequisites

img 1
Testerum download page

Getting Started with Jenkins and Testerum

In this section you will learn how to quickly set up Jenkins Job that automatically starts and executes your Selenium tests in Testerum.

  1. In Jenkins, create a new job
  2. Select Freestyle project, and click 'Ok'.

img 2
Jenkins create job
  1. Navigate to Source Code Management
  2. Select 'Git'
  3. Specify the Repository URL (where the tests are)
  4. Add the credentials
  5. Choose the branch
img 3
Jenkins-add-git-repo
  1. Navigate to 'Build' section
  2. Click on 'Add build step'
  3. Select 'Execute shell' from the list
img 4
Jenkins Build Section

Compose Shell Command

The Jenkins Shell Command is composed from multiple parts (img 5):

  1. Specify the path to where you unzipped Testerum and where the testerum-runner.sh is (the path should be added between double quotes " ")
  2. The argument repository-directory specifies the directory where the Testerum files (features, tests, external resources, etc.) are stored.
    You see here we use the variable ${WORKSPACE} because Jenkins checks out the tests from Git repository on the server and this variable is a shortcut to the Jenkins workspace folder.
  3. The setting testerum.selenium.driver.browserType specify against what browser to run Selenium tests.
    Possible values are: CHROME, FIREFOX, OPERA, EDGE, INTERNET_EXPLORER, SAFARI, or REMOTE.
    The default value is CHROME.
  4. The setting testerum.selenium.driver.headless tells Testerum whether to run the browser in headless mode or not.
    When running in headless mode, no browser window or any other UI will be displayed, but the tests will still run as normal.
    In a CI/CD environment this option should have the value true.
    For more Selenium settings please check out Selenium settings
  5. The setting testerum.selenium.driver.browserExecutablePath tells Testerum where to find the browser to run. If this setting is missing, the browser specified by testerum.selenium.driver.browserType will be looked up in the system PATH.
  6. The argument managed-reports-directory specifies the directory where the reports should be generated.
    These reports can be exposed on a Web server like Apache or Nginx to have clear and live reports over the application under-test.
  7. Click on Save
img 5
Jenkins Execute command
  1. Click on Build Now
  2. Click on the build #1 session and then select Console Output to check the logs
img 6
Jenkins Build Bow