Friday, 3 April 2015

Example code for running test on Safari browser - Appium/iPhone

This Piece of code tested on -
  • Appium -1.3.4 IOS -6 (8.1)
  •  Mac: Mavericks [10.9.5] 
  • Java -1.7 & 8 
  • TestNg 
  • WebDriver- 2.45

import java.util.concurrent.TimeUnit;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

 A test to demonstrate the automation on Safari browser using Appium [the open source tool]
public class TestGoogleSearch_SafariBrowser {
 WebDriver wd;

 public void beforeTest() throws MalformedURLException { //set capabilities required
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", "iPhone 6");
  capabilities.setCapability("platformName", "iOS");
  capabilities.setCapability("platformVersion", "8.1");
  capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");
  wd = new IOSDriver(new URL(""), capabilities);//instantiate driver
  wd.manage().timeouts().implicitlyWait( 30,TimeUnit.SECONDS);

 public void testSearchPage() throws InterruptedException {
  WebElement serachField = wd.findElement("q"));
  serachField.sendKeys("Pooja Shah Selenium youtube");

 public void afterTest() {

Problems with solutions

1. That URL did not map to a valid JSONWP resource
the url is wrong, it should be well formed path ""

2.error: Failed to start an Appium session, err was: Error: Could not navigate to webview; there aren't any!
set the platformversion capability properly-
ex. capabilities.setCapability("platformVersion", "8.1");

3. “fruitstrap quit unexpectedly” or unable to install 
  Possible solution: it works perfectly on ios simulator on mavericks but running on real device on Yosemite there are issues <br/>
with real device you need to separately add a udid in capabilities and and use a proxy called ios-webkit-debug-proxy
group-discussion for details
appium-dicussion for details

4 Could not get the iOS SDK version because the Xcode version could not be determined
it generally happens when appium somehow can't find xcode or you don't have any ios simulator created so if first one is the problem then hit
"xcode-select --switch /Applications/" from commandline
or if second is the problem then just create one.
or if all well then shut down appium, simulator and the script &  restart appium  -> script

Note : Now the visual is also available for the same on youtube: 

click on- Automate Safari browser on mobile 

Memories from Conference of the year

Another happy day:-) Got the opportunity to meet & chat with the amazing people around the globe. The brilliant minds behind the inven...