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 http://www.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.