Testing web apps using Robot Framework | Applitools Documentation

Quickstart: Visual Testing with Robot Framework

This quickstart will show you how to visually test web apps using Robot Framework. Visual testing can help you catch problems that traditional automation struggles to find.

After preparing your environment, this three-step quickstart should take about 15 minutes to complete.

Step 1: Preparing your environment

You'll need a few things to run this quickstart:

  1. An Applitools account, which you can register for free.
  2. Python version 3.6 or higher.
  3. A good editor with Robot Framework support like Visual Studio Code.
  4. An up-to-date version of Google Chrome.
  5. A corresponding version of ChromeDriver.

Installing ChromeDriver

The major version numbers of Chrome and ChromeDriver must be the same. Otherwise, Selenium WebDriver may raise an exception when it is initialized. For example, Chrome v101 requires ChromeDriver v101. ChromeDriver must be installed into a directory covered by the system PATH variable. Follow the instructions on Selenium's Install browser drivers page. On macOS and Linux, the recommended location for the chromedriver executable is the /usr/local/bin directory. You can test that ChromeDriver is working by running the chromedriver -v command to print its version.

Step 2: Getting your example project

Downloading the example project

The example project is located at https://github.com/applitools/example-robot-framework. Clone this repository to your local machine:

git clone https://github.com/applitools/example-robot-framework.git
cd example-robot-framework

Don't have Git?

Instead of running git clone, you can download the project as a ZIP file and extract it.

Installing the dependencies

The example project uses pip for package management. Run the following command (which works on any operating system):

pip3 install -r requirements.txt

Adding Applitools to Another Robot Framework Project

This example project already declares the Applitools Eyes SDK as a dependency. If you want to add the Applitools Eyes SDK into an existing Python environment, run the following command:

pip3 install eyes-robotframework

Then, generate the Applitools configuration file:

python3 -m EyesLibrary init-config

Deciding how to run tests

There are two ways to test the visual snapshots captured by the test:

  1. Using Applitools Ultrafast Grid for cross-browser testing in the cloud
  2. Using Applitools Classic runner on your local machine

Walking through the code

The project contains one visual test case, which is located at acme_bank.robot. It is a Robot Framework test script that covers login behavior for the ACME Bank demo web app. You can control which way tests are run by changing the EyesLibrary runner setting:

*** Settings ***
# Use Selenium WebDriver and Applitools Eyes.
Library     SeleniumLibrary
Library     EyesLibrary       runner=web_ufg    config=applitools.yaml

# Declare setup and teardown routines.
Test Setup        Setup
Test Teardown     Teardown

*** Keywords ***
# For setup, load the demo site's login page and open Eyes to start visual testing.
Setup
    Open Browser    https://demo.applitools.com    headlesschrome
    Eyes Open

# For teardown, close Eyes and the browser.
Teardown
    Eyes Close Async
    Close All Browsers

*** Test Cases ***
# This test covers login for the Applitools demo site, which is a dummy banking app.
# The interactions use typical Selenium WebDriver calls,
# but the verifications use one-line snapshot calls with Applitools Eyes.
# If the page ever changes, then Applitools will detect the changes and highlight them in the Eyes Test Manager.
# Traditional assertions that scrape the page for text values are not needed here.
Log into bank account

# Verify the full login page loaded correctly.
    Eyes Check Window    Login Page     Fully

# Perform login.
    Input Text        id:username    applibot
    Input Text        id:password    I<3VisualTests
    Click Element     id:log-in

# Verify the full main page loaded correctly.
    # This snapshot uses LAYOUT match level to avoid differences in closing time text.
    Eyes Check Window    Main Page    Fully    Match Level  LAYOUT

The applitools.yaml file in the project root directory provides the configuration to run this visual test. Its configuration applies to all test cases in the project:

### applitools.yaml 1.2

# This config file specifies how to run visual tests with Applitools.
# It applies to all tests in this project.

# To connect visual test results to your account,
# you must set the `APPLITOOLS_API_KEY` environment variable to your Applitools API key.
# To find it: https://applitools.com/tutorials/getting-started/setting-up-your-environment.html
# If you don't explicitly set the API key here,
# then the SDK will automatically read the `APPLITOOLS_API_KEY` environment variable to fetch it.
# api_key: YOUR_API_KEY

# Propagate Eyes results to robot `report.html`.
propagate_eyes_test_results: true

# A batch is the collection of visual checkpoints for a test suite.
# Batches are displayed in the Eyes Test Manager, so use meaningful names.
batch:
  name: "Example: Robot Framework"

# The name of the app under test.
# All tests for the same app should share the same app name.
# Set this name wisely: Applitools features rely on a shared app name across tests.
app_name: ACME Bank Web App

# Applitools can run checkpoints for snapshots on the local machine using the Classic runner.
web:
  viewport_size:
    width: 1200
    height: 600
  force_full_page_screenshot: false
  wait_before_screenshots: 100
  stitch_mode: CSS

# Applitools can run checkpoints for snapshots against any browser in the Ultrafast Grid.
web_ufg:

# Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
  # Warning: If you have a free account, then concurrency will be limited to 1.
  runner_options:
    test_concurrency: 5

# This setting defines 5 unique browser configurations to test.
  browsers:

# Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
    # Other browsers are also available, like Edge and IE.
    desktop:
      - browser_type: CHROME
        width: 800
        height: 600
      - browser_type: EDGE
        width: 1600
        height: 1200
      - browser_type: SAFARI
        width: 1024
        height: 768

# Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
    # Other mobile devices are available, including iOS.
    chrome_emulation:
      - device_name: Pixel_2
        screen_orientation: PORTRAIT
      - device_name: Nexus_10
        screen_orientation: LANDSCAPE

Step 3: Running your tests

Setting Applitools variables

Before running the visual test, you must find your Applitools API key and set it as an environment variable named APPLITOOLS_API_KEY. You may set it through your IDE (if applicable), or you may set it from the command line like this:

export APPLITOOLS_API_KEY=<your-api-key>
set APPLITOOLS_API_KEY=<your-api-key>

Launching visual tests

Run the following command to launch tests:

robot acme_bank.robot

Tests will run using headless Chrome.

After your tests run, you should see results in the Eyes Test Manager. You can log into the Test Manager at eyes.applitools.com or at the address for your private Applitools Eyes server.

When you run tests with the Applitools Ultrafast Grid, the tests will run one time on the local machine, and then they will upload snapshots to render on each target configuration in the cloud. The Test Manager will show a separate result for each rendering. When you run tests with the Applitools Classic runner, the Test Manager will show the one snapshot from your local machine.

You can also change the web page to inject visual bugs:

#     Open Browser    https://demo.applitools.com                  headlesschrome
    Open Browser    https://demo.applitools.com/index_v2.html    headlesschrome

If you rerun the tests, then they should yield "unresolved" results for you to review. Visual differences will be highlighted in magenta. It's up to you to accept (👍) or reject (👎) the changes. Applitools will remember your decisions for future analysis.

Taking the next steps with Applitools

Congratulations on completing this quickstart! There's still so much to learn about visual testing with Applitools, but you're off to a great start.

Resources for next steps:

  1. Setting match levels for visual checkpoints
  2. Organizing Tests Into Batches
  3. Run A/B Tests