Mobile automation using appium and browserstack

Some important points

  1. Register with Browserstack
  2. You will get Account Key to run automated tests on real devices
  3. Send commands to cloud server (Hub running in Selenium grid)
  4. You can access the video recordings of tests as well
  5. You will have to upload the apps to Browserstack server
  6. If you are accessing resources through local network, you will need to create a tunnel to Browserstack servers as well by running local binary.

You can refer for more details - https://www.browserstack.com/app-automate/appium-java In the Same way, we can run appium tests in other cloud providers like Saucelabs as well. Below code demonstrates how you can run appium tests in Browserstack cloud.

package org.softpost.android.simulator;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.concurrent.TimeUnit;

/**
 * Created by Sagar on 10-07-2016.
 */
public class BrowserStackTest {
    AndroidDriver driver;
    @Test
    public void test1() throws Exception{
        String userName = "USERNAME";
         String accessKey = "ACCESS_KEY";

        try{
             DesiredCapabilities caps = new DesiredCapabilities();

            caps.setCapability("device", "Samsung Galaxy S10 Plus");
            caps.setCapability("os_version", "10.0");
            caps.setCapability("project", "BS Project");
            caps.setCapability("build", "BS Build");
            caps.setCapability("name", "BS  Test");
            caps.setCapability("app", "bs://app-url");

            AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>
            (new URL("https://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), 
            caps);

            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

            driver.findElement(
                By.xpath
                ("//android.widget.Button[@resource-id='com.android.calculator2:id/digit_2']")).click();

            driver.findElement(By.xpath("//*[@text='+']")).click();

}catch (Exception ex) {
    ex.printStackTrace();


}finally {

    driver.quit();
}
    }

}

Web development and Automation testing

solutions delivered!!