CAPABILITY GENERATOR

LambdaTest DocumentationAutomation Testing ● pytest With Selenium – Running pytest Automation Script On LambdaTest Selenium Grid

pytest With Selenium – Running pytest Automation Script On LambdaTest Selenium Grid


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. How to run a sample Selenium with pytest on LambdaTest Automation.
  2. How to set up an environment for testing your locally hosted websites or web pages.
  3. How to configure Python desired capabilities for executing a Selenium test.
  4. How to run your test cases in parallel to reduce build times
  5. Advanced features of LambdaTest.

Prerequisites For Running pytest With LambdaTest Selenium Grid


  1. Global Dependencies
    • A Git or GitHub repository.
    • Make sure that you have the latest Python build installed. Download and install Python from here.
    • To install python with homebrew use the command below:
    • Make sure you have pip installed for package installation.

  2. LambdaTest Authentication Credential
  3. Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.

    • For Linux/Mac
    • For Windows

  4. Project
    • The recommended way to run your tests would be in virtualenv. It will isolate the build from other setups you may have running and ensure that the tests run with the specified versions of the modules specified in the requirements.txt file.
    • Create a virtual environment in your project folder the environment name is arbitrary.
    • Activate the environment:
    • Install the required packages:

Running Your First pytest automation script on LambdaTest Selenium Grid


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 with pytest. You can also find this code from our pytest GitHub repository.

Below is a sample code for test file.

Executing Parallel Testing Using pytest With Selenium Grid

Below is the command using which you can run parallel test with pytest on LambdaTest Selenium Grid.

In the above command, we have used -s to disable the output capture & -n is used to specify the number of parallel test execution.

Test Your Locally Hosted Selenide Tests With LambdaTest


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 execute a test of your locally hosted Selenide tests on cloud to perform automated cross browser testing on 2000+ browsers offered by Selenium Grid on LambdaTest. So you make sure how well your changes look, even before your customers. 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.

Important note: Some Safari & IE browsers, doesn’t support automatic resolution of the URL string “localhost”. Therefore if you test on URLs like “http://localhost/” or “http://localhost:8080” etc, you would get an error in these browsers. A possible solution is to use “localhost.lambdatest.com” or replace the string “localhost” with machine IP address. For example if you wanted to test “http://localhost/dashboard” or, and your machine IP is 192.168.2.6 you can instead test on “http://192.168.2.6/dashboard” or “http://localhost.lambdatest.com/dashboard”.

Fast track your automated cross browser testing process with pytest + LambdaTest integration.

Got any questions?

Feel free to share with our experts through 24×7 chat support or you can also drop a mail to support@lambdatest.com.

Happy testing! 🙂