Run test scripts on a Xcode iPhone simulator


We want to run our test in a iPhone simulator. The iphone simulator comes with Xcode which is available for the Mac operating systems. This recipe will show us how we can run our WebDriver tests in a iphone simulator.


We need to download Xcode from the following location:

The iPhone WebDriver application is not available from the App Store, therefore we need to check-out the code and build it manually. We can do the check-out by entering the following terminal command: svn checkout selenium-read-only

More information on SVN checkouts:


  1. Open the project selenium-read-only/iphone/iWebDriver.xcodeproj in Xcode.
  2. Double-click on the project and set the build configuration to the latest version of the iPhone Simulator, by using the drop-down box in the top left corner.
  3. Click on Run (play button). After compiling, the iphone simulator should appear and the iWebDriver app will be installed in it.
  4. Now we can use the IPhoneDriver in our tests.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.iphone.IPhoneDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class MobileIphoneSimulator {
private static WebDriver driver;
public void setUp() throws Exception {
driver = new IPhoneDriver();
public void tearDown() {
public void measurePerformance() throws InterruptedException {
driver.findElement(By.cssSelector("input#search_query_top")).sendKeys("ipod nano");
String searchHeader = driver.findElement(By.cssSelector("H1")).getText().toLowerCase();
Assert.assertTrue(searchHeader.contains("ipod nano"));