Posts Tagged QA

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: ,

WebDriver Framework in Ruby

Well as a little experiment, I decided to write a simple navigational automated test that takes the JAVA WebDriver libraries but manipulates the objects in Ruby (which goes through all the links on my mobile site @ http://barryteoh.com/). This uses the iPhone Driver as well, so yes I actually wrote an automated test which drives the iPhone (it is actually pretty cool to watch!).

If I can somehow get it posted to YouTube I will do this. (Edit: Youtube video is here)

Anyway, the code is up on GitHub which you can also clone using the GIT repo git://gist.github.com/294392.git

Oh and hey…. I even noticed it runs while the iPhone is locked (something which most commercial tools fails to do!)

Tags: ,

The Benefits of Multithreaded QA Automation

Just noted that writing an automated test that is multi-threaded is a good and very cost effective way of picking up race condition type bugs in an application – especially when there is dependancies between 2 system states.

Of course this will be picked up when doing performance testing, but the earlier a bug is found the better (and cheaper) right?

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: , , , , ,

Automated Testing on the iPhone for web apps

Have been taking a look at the iPhoneDriver component for WebDriver/Selenium 2.0 (which connects to a UIWebView instance on the iPhone).

Some of the observations I’ve noted if you wish to go down that path:

  • The framework is pretty easy to set up
  • You will need the iPhone SDK and to be a registered iPhone developer (so you can create provisioning profiles for on device testing)
  • You need an iPhone for on device testing (duh). Haven’t tried on the simulator but the documentation says it works.
  • The framework is Java based so you can data drive your tests (i.e. Using JDBC to connect to a database)
  • You could use JUnit and probably cruise control and set up some sort of continuous build integration
  • WebDriver is loosely based on selenium by the looks of the API. The script appears not to need too much modification in order for it to work

Tags: , ,

Multithreaded Automated UI Testing

Well my latest bit of personal development in the IT world is multithreaded development using scripting languages (as I don’t like waiting for stuff to compile).

Using multithreading as far as UI testing can goes means you can cover a lot in less time.

Where I’m looking at is Python (due to it’s integration with Quality Center) as well as Ruby (because I like the syntax and it offers a language which interacts with the JVM).

An area of interest is probably Jython. If I can get that integrated with a Quality Center VAPI-XP test, then I almost got the best of both worlds.

Tags: , , ,

Experimentation with the Celerity Test Framework

Just was doing some basic experimentation and reading on a JRuby test framework called Celerity (thanks to my DZone RSS Feed).

On initial thoughts, it seems like it a better open source test framework than Selenium is (Runs in headless/CLI mode by the looks of things AND the FAQ claims that it handles popups which  Selenium doesn’t).

Failing that if the popup handling is true, then for web based testing it probably makes a good rival to HP/Mercury’s QuickTest Professional tool (especially if you can multi-thread it using Ruby/JRuby’s threading).

The learning curve isn’t so bad if you can understand the HTML DOM (i.e. you aren’t a record and playback test monkey)

Tags: , ,