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.
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.
$web_driver = RemoteWebDriver::create ();
Note: To run our test scripts in BrowserStack, it requires your Username and Access Key.
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”.
Step 2.3: Select the OS, Browser with version and resolution.
Step 2.4: For the selected capabilities, code will be generated as below.
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.
- 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.
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://stage.mstsolutions.com website. And for getting the title form the website.
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.
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.
- 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.
- 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.
MST Solutions – Driving Cloud Transformations
Benefits of BrowserStack Automation:
- Simultaneously, we can work with other windows simply by minimizing the Browser.
- Instantly we can watch the screen in the form of video about what’s executing.
- Status will be shown for every single session; with that we can rerun the failed cases.
- All the sessions will be maintained for the All projects; so, there is no need to track the execution in the separate window.
- We can Filter the sessions with the Status.
- Parallel Tests Running: Parallelly we can run up to 5 Test cases.
- Queued Tests: The tests to be queued for the sequential execution.