Monday, 14 October 2013

Run Selenium scripts on Cloud - Browserstack | TestNG

Browserstack provides similar Saucelabs setup for cloud based automation using Selenium.  Given below a generic test using TestNG from Eclipse IDE that run on Browserstack cloud server.

1| Login to
2| Obtain the username and accesskey
3| Make use of the following script and do edit whenever necessary.

package packagename;

import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class Classname{

  public static final String USERNAME = "yourusername";
  public static final String ACCESS_KEY = "youraccesskey";
  public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "";

  private WebDriver driver;  

  public void setUp() throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "Firefox");
caps.setCapability("browser_version", "23.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "XP");
        caps.setCapability("browserstack.debug", "true"); //This enable Visual Logs
        driver = new RemoteWebDriver(new URL(URL), caps);

  public void testSimple() throws Exception {
    System.out.println("Page title is: " + driver.getTitle());
    Assert.assertEquals("Google", driver.getTitle());
    WebElement element = driver.findElement("q"));
  public void tearDown() throws Exception {  


4| Got to this link and get your logs.
5| For running tests parallel, refer: this link