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 !

Appium Desired Capabilities for Android and iOS

Screen-Shot-2016-09-28-at-11.03.39-AM

     Most of the time I observed that people facing the issues at the initial stage of running their automation scripts due to lack of knowledge in the selection of Desired Capabilities based on their Automation platform. Here, I would like to explain important Desired Capabilities for following:

  • Mobile Web Android
  • Mobile Web iOS
  • Mobile Native Android
  • Mobile Native iOS

Mobile Web Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Chrome”);

Mobile Web iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI);
capabilities.setCapability(nativeWebTap, true);
capabilities.setCapability(“startIWDP”, true);
capabilities.setCapability(IOSMobileCapabilityType.START_IWDP, true);
capabilities.setCapability(“app”, “path of SAFAILAUNCHERAPPPATH”);
//SAFAILAUNCHERAPPPATH = “/usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/build/SafariLauncher/SafariLauncher.app”
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

Mobile Native Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(MobileCapabilityType.UDID, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
capabilities.setCapability(MobileCapabilityType.APP, “location of your .APK”);
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, “package name of your Android application”);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, “activity name of your Android application”);

Mobile Native iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(MobileCapabilityType.UDID, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.APP, “location of your .iPA or .APP”);
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, “bundle ID of your iOS application”);
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

     Once you set your Desired Capabilities, next need to instantiate the drivers for Android and iOS in the following way:

For Android
WebDriver driver;
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub&#8221;), capabilities)

For iOS
WebDriver driver;
driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub&#8221;), capabilities)

Try to use above mentioned Desired Capabilities in your automation scripts.

make it perfect !