How To Run Selenium Tests On BrowserStack [Cross Browser Testing using Selenium]

How To Run Selenium Tests On BrowserStack [Cross Browser Testing]

In this post, we see how to run Selenium Tests on BrowserStack. Before that let’s learn why do we execute Selenium WebDriver tests on BrowserStack. In this post, we will learn following.

What is BrowserStack

BrowserStack is one of the premium sponsors of Selenium. BrowserStack supports Selenium automated tests. It runs our Selenium tests on a cloud. It’s very simple and straightforward. Here I am not talking about the features of BrowserStack. It’s out of the scope of this article. Using BrowserStack we could do Cross Browser Testing using Selenium. In this article, I will show you how to do cross-browser testing using Selenium on BrowserStack.

You could learn more about BrowserStack on BrowserStack Official Site

What is Cross Browser Testing

Cross Browser Testing is a type of non-functional test which helps us ensure that our website or web application works as expected in various web browsers. We could do Cross Browser Testing on different browsers both manual and automated way. To do Cross Browser Testing manually, we (Software Testers) create tests for each browser and execute it manually on each browser. To do it in an automated way, we could create Selenium tests with multiple conditional statements that execute test cases based on a specified browser type. While testing a website, we need to ensure that our website is appearing same across all the browsers. To do this we need to have all the browsers. Fortunately, there are some tools (e.g., CrossBrowserTesting, BrowserStack) to perform cross-browser testing without testing individually in a manual way.

Read more on Cross Browser Testing

Check below video to watch “How To Execute Selenium Scripts in Parallel using BrowserStack”

Please be patient. The video will load in some time.

Run Selenium Tests on BrowserStack

Let’s get started with a sample test, which opens SoftwareTestingMaterial site’s homepage and gets the title of the page and verifies it using Assertion.

Prerequisites to perform Cross Browser Testing Using Selenium:

  1. BrowserStack Account – Here is a signup link
  2. BrowserStack Username and Access Key
  3. Selenium Jars
  4. TestNG Jars

Step 1: After few minutes of signing up for the trial, you receive an email from BrowserStack support asking if you need any help setting up integration with BrowserStack.

After login, note your Username and Access Key. We need to pass the Username and Accesskey along with the URL to run the scripts on BrowserStack Cloud. To do this do login – click on Automate – Copy your Username and Accesskey from the left-hand sidebar

Step 2: Create a maven project – check this post for the same

Step 3: Copy the below code and Run Selenium Test on BrowserStack

Given clear explanation in the comments section within the program itself. Please go through it to understand the flow.



Visual Logs:

Run Selenium Tests on Multiple Browsers in Parallel on BrowserStack

Copy the below code and Run Selenium Test on BrowserStack

Must Read: Learn More About DataProviders In TestNG



Capturing Screenshots While Executing Selenium Scripts on BrowserStack

To get the screenshots you have to run the following code:

Complete Code:

Have you tried running BrowserStack. Share your experience by commenting below in the comments section. If you like this post, share it with your friends.

Sharing is caring.

Share on facebook
Share on twitter
Share on linkedin

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

Leave a Comment

Your email address will not be published. Required fields are marked *

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook