Automation Testing with BrowserStack

BrowserStack is one of the cloud based tools used to do the Cross-browser testing with the most accurate results. Nowadays, Automation Testing plays the significant role in the testing environment. To have the maximum test coverage, all the Test engineers move towards the Automation testing. For that purpose, BrowserStack enables the distinctive features for the users called Automate.

Introduction: 

BrowserStack is one of the cloud based tools used to do the Cross-browser testing with the most accurate results. Nowadays, Automation Testing plays the significant role in the testing environment. To have the maximum test coverage, all the Test engineers move towards the Automation testing. For that purpose, BrowserStack enables the distinctive features for the users called Automate.

Same as Live testing in BrowserStack, Automate enables automation testing within the BrowserStack.

automated testing with browserstack
automated testing with browserstack

The above listed or the Languages and frameworks supported by BrowserStack Automate.

We can choose any language and framework from the list. Here, I’m going to use PHP to explain about BrowserStack Automate.

Steps to create an Automated test script: 

Step 1: Open the notepad and start writing your own script in PHP.

At first, we need to create a remote web driver to run the script. It will build the connectivity between the script and BrowserStack’s browsers. Here’s the code for creating the remote web driver.

require_once(‘vendor/autoload.php’);

use Facebook\WebDriver\Remote\RemoteWebDriver;

use Facebook\WebDriver\WebDriverBy;

$web_driver = RemoteWebDriver::create ();

Note: To run our test scripts in BrowserStack, it requires your Username and Access Key. automated testing with browserstack

By clicking on the + symbol, the username and Access key will be revealed there; so, we can copy and update it in the script.

Step 2: We need to select the browser to be executed. In the BrowserStack itself, we can generate the code for the selected browsers.

Step 2.1: Open the https://www.browserstack.com/automate/php#configure-capabilities

Step 2.2: Move towards the” Configuring capabilities”.

automated testing with browserstack

Step 2.3: Select the OS, Browser with version and resolution.

Step 2.4: For the selected capabilities, code will be generated as below.

automation testing

Step 3:  If your website is not certified by SSL, then you can also handle those errors in the script itself. Here’s the code for handling SSL certificate exception.

$caps[‘acceptSslCerts’] = “true”;

Step 4: If you want to debug the code using BrowserStack, then you need to enter the below code in your script.

$caps[‘browserstack.debug’] = “true”;

Debugging: BrowserStack enables the user to debug their code with the help of Text Logs, Visual Logs, and Video of the session.

  • Text Logs: provide all the Information with the details of actions and timing.
automation testing
  • Visual Logs: Which provides the details with screenshots.
  • Video: It records all the actions done through the automated script. It helps to identify the exact root cause while execution.

It also enables the option with Play and download, we can watch the video and we can also share the video by downloading.

automation testing

Note: Although recording the logs in the form of video is very helpful, but it will take some time to make it work. It may result in increasing the execution time. If you don’t want to record the video log, then you can add the below code in the script.

$caps[‘browserstack.video’] = false;

Step 5: After that, you need to write a code for desired operation you want to test.

In the below sample program, I have written a code for just opening the https://www.mstsolutions.com website. And for getting the title form the website.

Sample Program:

automation testing

Step 6: At the end of the code, we must give the code to end; otherwise, the script will not stop running and will end up with the status of timeout. Here’s the code for quitting statement.

$web_driver->quit();

Running the test script in BrowserStack:  

Step 1: For PHP, I’m executing through command prompt. (If you are using eclipse, you need to select the script and click Run).

  • Once the script started execution, it will trigger the BrowserStack to start the script to Run.
  • Every script execution will be maintained as a session with a unique session ID.
automation testing
  • Under All projects the running and the executed scripts will be displayed.
  • Once the Script started execution, all the logs will get started recording.
  • Lively, we can see the video in BrowserStack about what’s happening while execution.
  • Once the execution is Successfully completed, then the Status will be changed from “Running” to “Completed”. And then, it notifies the Status in Green color dot.
automation testing
  • If it’s failed because of an error, the Status will be “Errors”.
  • If the session is timed out, then the Status will be “Timeout”. Then it notifies the Status in Yellow color dot.

Step 2: After executing the above code, the results will be shown in the command prompt and it will be stored in BrowserStack as Log.

OUTPUT:

MST Solutions – Driving Cloud Transformations

Benefits of BrowserStack Automation: 

  1. Simultaneously, we can work with other windows simply by minimizing the Browser.
  2. Instantly we can watch the screen in the form of video about what’s executing.
  3. Status will be shown for every single session; with that we can rerun the failed cases.
  4. All the sessions will be maintained for the All projects; so, there is no need to track the execution in the separate window.
  5. We can Filter the sessions with the Status.
  6. Parallel Tests Running: Parallelly we can run up to 5 Test cases.
  7. Queued Tests: The tests to be queued for the sequential execution.

Referred link: 

https://www.browserstack.com/automate/php

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.