Site icon TestingDocs.com

Run BrowserStack Cloud Test

Introduction

BrowserStack is a live cloud-based browser testing on real desktop and mobile browsers. You can say goodbye to your lab devices and virtual machines if you use BrowserStack.

 

 

Learn more about BrowserStack on its official website: https://www.browserstack.com

BrowserStack Features

1000+ desktop browsers
Cross-browser testing: latest versions of Edge, Safari, Firefox, IE, and more on a range of Windows and OS X platforms on a robust cloud infrastructure.

Test dev environments
The local Testing feature allows you to test development and internal websites seamlessly, without setup or configuration.

Real Device Cloud
Test on a range of physical mobile devices and tablets for the most accurate results.

Native experience
Real browsers on real machines.

Secure and Private
Customers use BrowserStack every day to test securely in the cloud.

Now we will see how to run a sample test automation on BrowserStack.BrowserStack supports Selenium automated tests using TestNG with many more frameworks like JBehave etc ,.

Running tests on a cloud setup is very simple and straightforward. First, you need to get your  credentials  to build the URL as shown below:

Code Listing

public String USERNAME = "<sample_user_name>";
public String AUTOMATE_KEY = "<sample_automate_key>";
We can build the url with the above parameters:

public String URL = "https://" + USERNAME + ":" 
+ AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

//Now we will build and set DesiredCapabilities for the test to run 
//on Mozilla Firefox version 49 on Windows 10 OS.Below is the code :

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Firefox");
    caps.setCapability("browser_version", "49.0");
    caps.setCapability("os", "Windows");
    caps.setCapability("os_version", "10");
    caps.setCapability("browserstack.debug", "true");

 

Instantiate RemoteWebDriver with URL and DesiredCapabilities:
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

Sample Program to search Bing which runs on BrowserStack device.

public class BrowserStackTest {

    public static final String USERNAME = "<username_goes_here>";
    public static final String AUTOMATE_KEY = "<automation_key_goes_here>";
    public static final String URL = "https://" + USERNAME + ":" 
+ AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

    public static void main(String[] args) throws Exception {

      DesiredCapabilities caps = new DesiredCapabilities();
      caps.setCapability("browser", "Firefox");
      caps.setCapability("browser_version", "49.0");
      caps.setCapability("os", "Windows");
      caps.setCapability("os_version", "10");
      caps.setCapability("browserstack.debug", "true");

      WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
      driver.get("https://www.bing.com");
      WebElement element = driver.findElement(By.id("sb_form_q"));
      element.sendKeys("Hello Bing!");
      driver.findElement(By.id("sb_form_go")).click();
      WebDriverWait wait = new WebDriverWait(driver, 60);
      wait.until(ExpectedConditions.titleContains("Hello"));
      Assert.assertEquals("Hello Bing! - Bing", driver.getTitle());


      System.out.println(driver.getTitle());
      driver.quit();

    }
}

 

Run the test on your local IDE and login into the account on BrowserStack.

We can see the test run on the specified device in the test on BrowserStack as shown below:

 

 

Debugging tests on the cloud is easy. On BrowserStack we have 2 logs:

1.Text Logs
2. Visual Logs

Text Log for the test run

 

Visual Log

 

 

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Exit mobile version