Salesforce1 Mobile Automation Testing Adventures – Putting It All Together!

49125506In Part 3, I showed how you can automate typical CRUD flows in any hybrid or native app built using the Salesforce1 Mobile SDK. As I mentioned earlier as well, it’s good to be able to create UI tests with literally point and click capabilities using Appium, but it’s a far fetched reality from achieving end to end automation testing.

So, let’s now solve the last and the most interesting part of the jigsaw puzzle and write some code to build our UI automation framework.


When you are creating any scripts, there’s a ‘Record’ button which actually captures all your actions – taps, keys entered, on focus, off focus, literally everything. If you look closely, you actually see what code it is generating for each action that you perform in the bottom window.

Screen Shot 2015-02-11 at 6.13.23 pm

Appium supports multiple languages for producing such test script code including

  • Java
  • Node
  • Perl
  • PHP
  • Ruby
  • Python
  • .NET

Since I’ve worked with Selenium earlier and used Java to create automation tests for web application, I decided to go the Java route. And giving credit where due, I followed this very informative tutorial to modify some provided examples to write my own scripts for Mobile SDK sample apps.

First things first

Like with Selenium, the first step is to create a RemoteWebDriver and specify various capabilities such as

  • Device – iPhone/ Android
  • UUID – To be set only in case of iPhone when using a real device
  • Bundle ID – Bundle id of your app

I do this in my setup method as shown below.

public void setUp() throws Exception {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "iPhone Simulator");

Specify App Location

Next up, Appium needs what application and from where it needs to load. This is done as follows.

 File appDir,app;

//Specify directory
 appDir = new File( "/Users/gaurav/Desktop/AppFiles");

//Specify name of app file in that directory
 app = new File(appDir,"");

//Set app absolute path
capabilities.setCapability("app", app.getAbsolutePath());

// Load remote driver with server address and capabilites
 driver = new RemoteWebDriver(new URL(""), capabilities);

// Get a session id
 sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
 driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

Now the real thing!

Once the remote driver session has been established, the real magic begins. And to be honest, I found this part to be the most amazing. Each action that you perform on the Appium Inspector equates to one click() or sendKeys() call.

try {

// Find the username field in oAuth webview

// Enter the username value in oAuth webview
// Find the password field in oAuth webview

//Enter the password field in the oAuth webview

// Find the Login button and click it
driver.findElement("Log in to Salesforce")).click();

// Find the allow button on permissions screen and click it
driver.findElement(" Allow ")).click();
// We're now on our app home page, let's create a new account

// Find the account name field and get focus

// Enter the account name

//Find the Industry field and get focus

//Enter the industry value

//Find the phone field and get focus

// Enter the pone number

// We're done, find 'Save' button and click it
// All done

There you have it – while manually testing each such operation is a pain in the a**, you can record scripts for such key flows, put them into a Maven project and run it as part of your continous integration cycle, thereby helping achieve end to end automation.

If you’ve followed the earlier tutorials closely, hopefully it all makes sense!


While having such tests reduce manual testing efforts, I want to stress on a few things here

  • Appium can test across multiple devices with varying screen sizes/ resolutions, but it can’t really catch any “User Experience” issues which can best be judged by the human eye.
  • I’ve found the framework flaky at times. The Inspector would crash sometimes and often, the Inspector window won’t refresh itself manually. The framework is still maturing so I believe that’s kind of expected.

I created scripts for the following sample apps that are bundled with Salesforce1 Mobile SDK

  • AccountEditor (iOS hybrid)
  • ContactExplorer (iOS hybrid)
  • FileExplorer (iOS Native)
  • RestAPIExplorer (iOS Native)

The scripts are available on my Github repo. If you face any issues understand or running the scripts, drop me a line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s