LambdaTest Selenium Automation Grid is a cloud based scalable Selenium testing platform which enables you to run your automation scripts on 2000+ different browsers and operating systems. You can now run your Python Selenium automated test cases on a scalable Selenium infrastructure that is running real browsers and real operating systems. This post will help you in getting started with configuring and running your Python based automation test scripts on LambdaTest Selenium cloud platform. In this post we would be exploring:
1 |
curl https://bootstrap.pypa.io/get-pip.py | python |
1 |
$ brew install python |
1 |
pip install selenium |
1 |
pip install robotframework |
1 2 |
$ ${KEY} YOUR USERNAME:YOUR ACCESS KEY EXAMPLE: ${KEY} username:843908dfslkhfkhfhlkhdsfkl |
1 |
$ pip install -r requirements.txt |
The first step in using LambdaTest platform is to understand LambdaTest’s Selenium Grid capabilities. Our Selenium Grid uses remote webdriver instead of normal Selenium client browser drivers so if you are migrating from locally run Selenium, you would have to invoke LambdaTest Selenium remote webdriver. Next you need to specify in your code, which browser, browser versions, operating systems, and resolution you wish to run your test on, along with defining LambdaTest specific capabilities. You can checkout LambdaTest Capabilities Generator tool to understand more about how you can define running browser environments and leverage advanced LambdaTest capabilities.
Let’ start with a simple Selenium Remote Webdriver test first. The Robot Selenium script below tests a simple to-do application with basic functionalities like mark items as done, add items in list, calculate total pending items etc. You can also find this at our GitHub repository.
Feature: Test to add item Scenario: Test sample-todo-app Given I go to sample-todo-app to add item Then I Click on first checkbox and second checkbox When I enter item to add When I click add button Then I should verify the added item
Now, we have to create step definition file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
*** Settings *** Resource ../Resources/Common.robot Test Setup Common.Open test browser Test Teardown Common.Close test browser *** Variables *** *** Test Cases *** Example of connecting to Lambdatest via Robot testing Framework Page should contain element name:li1 Page should contain element name:li2 Click button name:li1 Click button name:li2 Input text id:sampletodotext Yey Let's add it to list Click button id:addbutton ${response} Get Text xpath=/html/body/div/div/div/ul/li[6]/span Should Be Equal As Strings ${response} Yey Let's add it to list |
Here is common.robot file to setup mandatory details to run at LambdaTest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
*** Settings *** Library Selenium2Library *** Variables *** @{_tmp} ... browserName: %{browserName}, ... platform: %{platform}, ... version: %{version}, ... name: RobotFramework Lambda Test ${BROWSER} %{ROBOT_BROWSER} ${CAPABILITIES} ${EMPTY.join(${_tmp})} ${KEY} <YOUR LAMBDATEST USERNAME>:<YOUR LAMBDATEST ACCESS KEY> ${REMOTE_URL} https://${KEY}@hub.lambdatest.com/wd/hub *** Keywords *** Open test browser Open browser https://lambdatest.github.io/sample-todo-app/ browser=${BROWSER} ... remote_url=${REMOTE_URL} ... desired_capabilities=${CAPABILITIES} Close test browser Close all browsers |
You would need to execute the below command in your terminal/cmd.
1 |
$ make test_Windows_10_chrome_68 |
To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name Lambda Tunnel. With Lambda Tunnel, you can test your locally hosted files before you make them live over the internet. You could even perform cross browser testing from different IP addresses belonging to various geographic locations. You can also use LambdaTest Tunnel to test web-apps and websites that are permissible inside your corporate firewall. The SSH tunnel provided by LambdaTest acts as a proxy server for hosting your web pages from your local machine to Virtual machines running on LambdaTest cloud servers. Curious to know more about Lambda Tunnel?
Follow our documentation on Lambda Tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.
Download the binary file of:
You can start tunnel by executing the below command in your cmd(Command Prompt) / terminal. Make sure that your pointer is routed in the same directory where you extract the downloaded Lambda Tunnel zip file.
1 |
LT -user [user's login email] -key [user's access key] |
So for example, if your user login email is example@lambdatest.com
and your user key is 123asd123
, then the command would be:
1 |
LT -user example@lambdatest.com -key 123asd123 |
While performing automation testing using Selenium with Robot framework on LambdaTest selenium grid, you might want to flag a test as either pass or fail. This can be done if it is required in the testing requirements to validate the expected behaviour of tests. So you can mark any test as pass or fail, representing the expected outcome of that respective test. Below is the script that shows how to mark tests as pass or fail for validation:
LambdaTest Annotation
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import os from robot.libraries.BuiltIn import BuiltIn def report_lambdatest_status(name, status): selenium = BuiltIn().get_library_instance('Selenium2Library') # Mark test status pass/failed lambda_status = "passed" if status=="PASS" else "failed" lambda_status_script = 'lambda-status={}'.format(lambda_status) selenium.execute_javascript(lambda_status_script) # Update test name lambda_status_script = 'lambda-name={}'.format(name) selenium.execute_javascript(lambda_status_script) |
Parallel Testing is one of the most demanding feature of LambdaTest Selenium Grid. By parallel testing, you can run more than one test case, simultaneously. This means that, Parallel testing would allow you to execute numerous automation test cases altogether. So you execute a single test scenario across different browsers or could run different test scenarios across the same browser but with different browser versions.
To perform parallel Robot Selenium testing on LambdaTest’s Online grid use the below command.
1 |
$ make run_all_in_parallel |