Well I’ve gotten the webdriver+iPhone webdriver working. It’s fairly straight forward (and drives the same way as driving a browser).
The only caveat is that you need to pay $99 a year for the iPhone Developers Program. But $99 is chump change compared to any other test tool licensing.
Here’s what I’ve done (JAVA Only).
First of all I’ve added all the selenium + the compiled iphone webdriver jar files to a directory.
Next, I have compiled the following code which basically does a simple google search (for demonstration purposes).
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.iphone.IPhoneDriver;
import java.util.Properties;
public class Test {
public static void main(String[] args) throws Exception {
Properties p = new java.util.Properties();
p.load(new java.io.FileInputStream("url.properties"));
String url = p.getProperty("com.bt.url");
System.out.println("Connecting to iWebDriver on: " + url);
WebDriver driver = new IPhoneDriver(url);
driver.get(p.getProperty("com.bt.auturl"));
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Selenium");
element.submit();
// Simple output
System.out.println("Page title is: " + driver.getTitle() + "\n");
System.out.println("Page URL is: " + driver.getCurrentUrl() + "\n");
}
}
Next, create a file called “url.properties” and add the following values.
com.bt.url
com.bt.auturl
The first key defines where iWebDriver sits. The second key defines the google URL.
Finally run the following commands (UNIX Only. I guess you can use cygwin32)
# UNIX based systems is a hell of a lot nicer for java because you don't need to type # in all the jar files or update classpaths. But then again its my preference. # Compiling it javac -cp `find . -name "*.jar" | xargs | sed 's/ /:/g;s/.\///g;'`:. ClassSource.java # Running it java -cp `find . -name "*.jar" | xargs | sed 's/ /:/g;s/.\///g;'`:. ClassName
It will then run and produce some output telling you about the page. You will also see it navigate through the page on the iWebDriver application (It’s open source so you can even hack away at the code there to customize it to your liking).