Posts Tagged iPhone Development

Using different datasets for testing CoreData

I found that making use of compiler pre-process directives and bundling some test databases into your application (and using NSFileManager to copy the files across) makes testing with real data a breeze.

What I’ve done first is I have taken a copy of the iPhone database (Do a find . -name “ApplicationName” in the backup directory for your application OR if jailbroken do it in /var/mobile/Applications). Then you look for any sqlite files generated and now you can use this as a baseline test.

Next, create a folder in the xcode project (better organization!) called “QA” and then set up a target called “Test”, under the pre-processor directives add _TEST to this.

And finally the code

#if _TEST
	NSLog(@"Application in Test Mode %@", [[NSBundle mainBundle] pathForResource:@"AppDB" ofType:@"sqlite" inDirectory:@""]);
	NSLog(@"DEST: %@", [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"AppDB_Test.sqlite"]);
	if ([[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"AppDB" ofType:@"sqlite" inDirectory:@""] toPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"AppDB_Test.sqlite"] error:nil]) {
		NSLog(@"Copied DATABASE");
	} else {
		NSLog(@"Could not copy database");
	}
    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"AppDB_Test.sqlite"]];
#else
    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"AppDB.sqlite"]];
#endif

Tags: ,

Distributing apps between other iPhone developers

It has been around for a while, but I found a pretty easy to explain tutorial on how you can give an iPhone app to another registered iPhone developer (without giving them the source) AND not using an adhoc distribution profile (which personally I think is a huge brainf$@k and very limiting).

To sum it up all it involves is resigning the binary with your own certificate. Hopefully this will not work on apps on the AppStore (not that it matters anyway as most of the apps get cracked within minutes/seconds anyway).

Anyway the link is here. Enjoy!

Tags: ,

Selenium/Webdriver + iPhone webdriver in action

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).

Tags: , , , , ,