Browserstack supports mobile native automation

real-mobile.png

        I would like to announce that Browserstack supporting native mobile automation capability. Now you can upload the apk or iPA to browserstack server (in your browserstack account), set up the capabilities, create Android or iOS driver and start scripting.

Keep following steps in your mind:

  • Step 1: Setup Environment .
    • Ensure you have Appium Java client library and Java driver bindings installed)
  • Step 2: Upload your App.
    • Use our REST API to upload your .apk or .ipa file using CI tools.
      curl -u "browserstack_username:browserstack_accesskey" \
       -X POST "https://api.browserstack.com/app-automate/upload" \
       -F "file=@/path/to/app/file/Application-debug.apk"

      Note the app_url returned in the API response and update the app capability in your test code with it.

  • Step 3: Configure and Run test.
    • In this step you have to set the capabilities, create driver (iOS or Android) using Java class if you are using language as Java.

Following is the sample snippet,

For Android
import java.net.URL;
import java.util.List;
import java.net.MalformedURLException;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
public class BrowserStack {  
  public static String userName = "your_browserstack_username";
  public static String accessKey = "your_browserstack_accesskey";
  public static void main(String args[]) throws MalformedURLException, InterruptedException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("device", "device_name");
    caps.setCapability("os_version", "device_os_version");
    caps.setCapability("app", "app_url");
    AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);
}
For iOS
import java.net.URL;
import java.util.List;
import java.net.MalformedURLException;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
public class BrowserStackIOS {
  public static String accessKey = "browserstack_key";
  public static String userName = "browserstack_username";
  public static void main(String args[]) throws MalformedURLException, InterruptedException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("device", "device_name");
    caps.setCapability("os_version", "device_os_version");
    caps.setCapability("app", app_url);
    IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);
}
 app_url will get by calling following API,
String authString = "browserstack_username"+ ":" + "browserstack_password";
 String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
 Client restClient = Client.create();
 WebResource webResource = restClient.resource("https://api.browserstack.com/app-automate/recent_apps");
 ClientResponse resp = webResource.accept("application/json").header("Authorization", "Basic " + authStringEnc) .get(ClientResponse.class);
 if (resp.getStatus() != 200) {
 System.err.println("Unable to connect to Browserstack, please try again");
 }
 JSONParser parser = new JSONParser();
 JSONArray json = (JSONArray) parser.parse(resp.getEntity(String.class));
 String app_url = null;
 String app_name = null;
 for (int i = 0; i < json.size(); i++) {
 JSONObject jsonobject = (JSONObject) json.get(i);
 app_url = (String) jsonobject.get("app_url");
}

Try to execute your scripts using Browserstack for mobile native applications.

make it perfect !