BrowserStack is a popular cloud testing platform because it provides instant access to all desktop and mobile browsers. And you don’t have to set up virtual machines and devices and browsers. Furthermore, the most effective part is you can run your tests in parallel in different environments. The widest usage of this platform is running selenium scripts on the cloud. But what about load testing a BrowserStack script.
BrowserStack does not do load testing. However, you can take the scripts that you create for BrowserStack and use them for load testing with a simple modification. This post will walk through the steps with an example script.
BrowserStack Script
Below is a simple automation code written in Node.js to perform a cloud test on BrowserStack.
Here is a script for BrowserStack:
var webdriver = require('selenium-webdriver'); var capabilities = { 'browserName' : 'Chrome', 'browser_version' : '62.0', 'browserstack.local':true, 'os' : 'Windows', 'os_version' : '10', 'resolution' : '1024x768', 'browserstack.user' : 'mahirkaplanc1', 'browserstack.key' : '' } var driver = new webdriver.Builder(). usingServer('http://hub-cloud.browserstack.com/wd/hub'). withCapabilities(capabilities). build(); driver.get('http://slot8.ss.etiya.com/telaura/faces/telaura').then(function(){ driver.findElement(webdriver.By.name('uname')).sendKeys('username\n').then(function(){ driver.findElement(webdriver.By.name('password')).sendKeys('password\n').then(function(){ driver.findElement(webdriver.By.id('cb1')).click().then(function(){ driver.quit(); }); }); }); });
We will modify and simplify the script to run it on the Redline13 load testing platform.
test.js
var redline = require( 'redline13-webdriver' ); //import redline13 library var driver = redline.loadBrowser('chrome'); //this might be chrome,firefox,phantomjs. var By = redline.webdriver.By; // using By library for locator var URL = "http://slot8.ss.etiya.com/telaura/faces/telaura"; //Rest of the code is the same of Webdriver code driver.get(URL); //navigate to url driver.manage().window().maximize(); driver.findElement(By.name("uname")).sendKeys("username"); // enter username driver.findElement(By.name("password")).sendKeys("password"); // enter password driver.findElement(By.id("cb1")).click(); // enter login button driver.quit();
Both of these use a Javascript programming language. However we can use the “redline13-webdriver” library to create a script with easier syntax and much clearer. And you won’t have to handle Javascript promises.
If you don’t have Redline13 library, just run the following to set it up:
npm install redline13-webdriver
You have completed the installation. You are ready to run your script. You can check that your script works on your local machine with a command prompt:
node test.js
Running a Load Test
It’s time to upload the script on Redline13 to perform a load test.
Steps are:
- https://www.redline13.com/StartTest start test
- Select ‘Custom Test’
- Set Number of Users to 50 (or any number you want)
- Upload Custom – drop in your test.js file
- In Advanced Custom Test Options select ‘WebDriver NodeJS’ plugin
- You will need two RedLine13 Plugins which can be added via https://www.redline13.com/Account/plugins
- Node Version Manager
- WebDriver NodeJS
- You will need two RedLine13 Plugins which can be added via https://www.redline13.com/Account/plugins
- Select ‘PhantomJS’ as the browser type
-
- Domains – You can provide a space separated list of domains which will track full URLs from that URL
- Other domains will be truncated to their domain name and recorded, lumping together all metrics from a domain. For example, all google analytics calls.
- Hard Filter – If checked, will only track from the domains specified, other metrics will not be recorded.
- Capture ScreenShot on Error – If checked, when the script throws an error, an image will automatically be captured if possible and be available at end of test.
- Domains – You can provide a space separated list of domains which will track full URLs from that URL
- Start Test
- Watch Results
Conclusion
Follow these steps and you can begin load testing a BrowserStack script on the cloud. You can take that selenium automation script and perform a load test with thousands of concurrent users.