Robot Framework is a generic open source automation framework which can be used for test automation. It is open and extensible and can be integrated with many tools to create powerful and flexible automation solutions. Robot Framework has easy syntax, utilising human-readable keywords and its capabilities can be extended by libraries implemented with Python or Java.
This BrowserStack Example repository demonstrates a Selenium test framework written in Robot Framework with parallel testing capabilities. The Selenium test scripts are written for the open source BrowserStack Demo web application (Github). This BrowserStack Demo App is an e-commerce web application which showcases multiple real-world user scenarios. The app is bundled with offers data, orders data and products data that contains everything you need to start using the app and run tests out-of-the-box.
The Selenium test tests are run on different platforms like on-prem, docker and BrowserStack using various run configurations and test capabilities.
-
Clone the repository
-
Ensure you have the following dependencies installed on the machine
- Python 3
Install the requirements:
pip install -r requirements.txt
This repository contains the following Selenium tests:
| Module | Test name | Description |
|---|---|---|
| e2e | E2E Test | This test scenario verifies successful product purchase lifecycle end-to-end. It demonstrates the Page Object Model design pattern and is also the default test executed in all the single test run profiles. |
| login | Check if Signin opens on clicking on favourites nav item | This test verifies the login workflow with different types of valid login users. |
| login | Check Login with locked_user | This test verifies the login workflow error for a locked user. |
| offers | Set GPS location to Mumbai and check offers | This test mocks the GPS location for Mumbai and verifies that the product offers applicable for the Mumbai location are shown. |
| product | Apply Apple And Samsung Filter | This test verifies that the Apple products are only shown if the Apple vendor filter option is applied. |
| product | Apply 'Lowest to Highest' Order By Filter | This test verifies that the product prices are in ascending order when the product sort "Lowest to Highest" is applied. |
| user | Check Login with image_not_loading_user | This test verifies that the product images load for user: "image_not_loading_user" on the e-commerce application. Since the images do not load, the test case assertion fails. |
| user | Check Order in existing_orders_user | This test verifies that existing orders are shown for user: "existing_orders_user" |
For all the parallel run configuration profiles, you can configure the maximum parallel test threads by changing the settings below.
-
Docker / BrowserStack
While running any of the below tests in parallel, set the maximum parallel thread using the pabot argument as below:
pabot --processes <count_of_parallels> <name_of_suites_to_run>
This infrastructure points to running the tests on your own machine using a browser (e.g. Chrome) using the browser's driver executables (e.g. ChromeDriver for Chrome). #{ Selenium enables this functionality using WebDriver for many popular browsers.}
- For this infrastructure configuration (i.e on-premise), ensure that the ChromeDriver executable is placed in the
/src/test/resources/driversfolder.
Note: The ChromeDriver version must match the Chrome browser version on your machine.
-
How to run the test?
To run a specific test scenario, use the following command with the additional 'test-name' argument:
robot --variable testType:on-prem --test "<Test scenario name>" .
where, the argument 'test-name' can be any RobotFramework scenario name configured in this repository.
E.g. "Check Login with locked_user", "E2E Test", "Apply 'Lowest to Highest' Order By Filter" or any of the other test scenario names, as outlined in About the tests in this repository section.
-
Output
This run profile executes a specific test scenario on a single browser instance on your own machine.
-
How to run the test?
To run the entire test suite on your own machine, use the following command:
robot --variable testType:on-prem --suite <Suite-name> .
-
Output
This run profile executes the entire test suite sequentially on a single browser, on your own machine.
Docker is an open source platform that provides the ability to package and test applications in an isolated environment called containers.
- Install and start Docker.
- Note: Docker should be running on the test machine. Ensure Docker Compose is installed as well.
- Run
docker-compose pullfrom the current directory of the repository.
-
How to run the test?
- Start the Docker by running the following command:
docker-compose up -d
To run a specific test scenario, use the following command with the additional 'test-name' argument:
robot --variable testType:docker --test "<Test scenario name>" .
where, the argument 'test-name' can be any scenario name configured in this repository.
E.g. "Check Login with locked_user", "E2E Test", "Apply 'Lowest to Highest' Order By Filter" or any of the other test scenario names, as outlined in About the tests in this repository section.
- After tests are complete, you can stop the Docker by running the following command:
docker-compose down
-
Output
This run profile executes a specific test scenario on a single browser deployed on a docker image.
-
How to run the test?
- Start the docker image first by running the following command:
docker-compose up -d
- To run the entire test suite in parallel on the docker image, use the following command:
robot --variable testType:docker --suite <Suite-Name> .
- After the tests are complete stop the Selenium grid by running the following command:
docker-compose down
-
Output
This run profile executes the entire test suite in parallel on a single browser, deployed on a docker image.
BrowserStack provides instant access to 2,000+ real mobile devices and browsers on a highly reliable cloud infrastructure that effortlessly scales as testing needs grow.
-
Create a new BrowserStack account or use an existing one.
-
Identify your BrowserStack username and access key from the BrowserStack Automate Dashboard and export them as environment variables using the below commands.
- For *nix based and Mac machines:
export BROWSERSTACK_USERNAME=<browserstack-username> && export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
- For Windows:
set BROWSERSTACK_USERNAME=<browserstack-username> set BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
Alternatively, you can also hardcode username and access_key objects in the test_caps.json file.
Note:
- We have configured a list of test capabilities in the test_caps.json file. You can certainly update them based on your device / browser test requirements.
- The exact test capability values can be easily identified using the Browserstack Capability Generator
In this section, we will run a single test on Chrome browser on Browserstack. To change test capabilities for this configuration, please refer to the bstack-config.json file.
-
How to run the test?
To run a specific test scenario, use the following command with the additional 'test-name' argument:
robot --variable testType:bstack-single --test "<Test scenario name>" .
where, the argument 'test-name' can be any scenario name configured in this repository.
E.g. "Check Login with locked_user", "E2E Test", "Apply 'Lowest to Highest' Order By Filter" or any of the other test scenario names, as outlined in About the tests in this repository section.
-
Output
This run profile executes a single test on a single browser on BrowserStack. Please refer to your BrowserStack dashboard for test results.
In this section, we will run the tests in parallel on a single browser on Browserstack. Refer to bstack-config.json file to change test capabilities for this configuration.
-
How to run the test?
To run the entire test suite in parallel on a single BrowserStack browser, use the following command:
pabot --testlevelsplit --variable testType:bstack-single --suite <Suite-Name> .
-
Output
This run profile executes the entire test suite in parallel on a single BrowserStack browser. Please refer to your BrowserStack dashboard for test results.
- Note: By default, this execution would run maximum 5 test threads in parallel on BrowserStack. Refer to the section "Configuring the maximum parallel test threads for this repository" for updating the parallel thread count based on your requirements.
The only change you need to do here, is to add the respective options in the bstack-config.json file.
The webdriver framework handles the starting and termination of BrowserStack Local Instance.
-
Add
--listener 'allure_robotframework;./results/allure'to any test command above.- Example:
robot --listener 'allure_robotframework;./results/allure' --variable testType:single --suite offers .
- Example:
-
Serve the Allure report on a server:
allure serve
- View your test results on the BrowserStack Automate dashboard
- Documentation for writing Automate test scripts in Java
- Customizing your tests capabilities on BrowserStack using our test capability generator
- List of Browsers & mobile devices for automation testing on BrowserStack #{ Replace link for non-Selenium frameworks. }
- Using Automate REST API to access information about your tests via the command-line interface
- Understand how many parallel sessions you need by using our Parallel Test Calculator
- For testing public web applications behind IP restriction, Inbound IP Whitelisting can be enabled with the BrowserStack Enterprise offering
