Automation testing using Browserstack with selenium

Abdul Rauf
3 min readNov 2, 2022

--

This tutorial will help you in getting started with configuring and running your Python-based automation test scripts on the BrowserStack Selenium cloud platform.

Webapps Testing

Browserstack enables automated testers to do web application testing on all of the modern desktop operating system versions and the different browsers that run on them. BrowserStack also offers the option of testing mobile apps, or testing on mobile web browsers. Learn more about different plans and pricing on the BrowserStack website.

The Selenium framework is typically used for desktop web browser tests. You can also use it to test some features of mobile browsers, although ideally, you would use the Appium mobile automation framework, as it gives you the ability to test interactions that occur on a mobile device, such as swiping and pinching

For desktop applications you can choose hundreds of browsers on Mac, Windows, and Linux operating systems to test against, using the most recent versions of the web browsers available in those environments

What You’ll Need

  • A BrowserStack account (Log in or sign up for a free trial license).

Prerequisites For Running Selenium Python Scripts

Before you can start performing Python automation testing with Selenium, you would need to:

# install pipsudo easy_install pip# install the Selenium language bindingssudo pip install selenium==4.1.0# install the python-dotenv librarypython -m pip install python-dotenv

*NOTE: All code here is written in Python 3, and it doesn’t work with Python 2.

Select desktop browsers or real devices from a list of 3000+ available combinations. https://www.browserstack.com/docs/automate/selenium/select-browsers-and-devices

Run Your Test

Copy the following code snippet from github repository and save it on your machine. In the next step, we will run this script which will execute your first build on BrowserStack. The following sample test case opens the bstackdemo.com website, adds a product to the cart and verifies whether the product is added to the cart.

Execute build on BrowserStack

You are now ready to run your build on BrowserStack. From the root directory of this project, run the following command.

# Run from the root directory of this projectpython parallel.py

Cross Browser Testing

Selenium is the most popular automation testing tool for various functionalities. Cross-browser testing is one such feature supported by Selenium, which can be performed via the steps below:

>: Test cases can be automated using Internet Explorer, Firefox, Chrome, Safari browsers with the help of Selenium WebDriver. Copy the code here

>: To execute test cases with different browsers in the same machine at the same time a TestNG framework can be integrated with Selenium WebDriver. Copy the XML file here, In this XML file, the code specifies different classes for the drives to instantiate the browsers to execute the test cases on the website

>: Run the test cases. This code that will test the Browserstack home page on three different browsers — Chrome, Edge, and Firefox.

Your test results would be displayed on BrowserStack automation dashboard. BrowserStack Automation Dashboard will help you view all your text logs, screenshots, and video recording for your entire automation tests.

Credits:

--

--

Abdul Rauf

Opensource enthusiast, passionate about communities, DevRel at DotVVM