Posts Tagged Automated Functional Tests

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

JDBC/log4j and JRuby

Have been experimental with various Java technologies (At this time, JDBC, reading from properties files and log4j) and tying it all together with JRuby – Which I might add runs also in compiled mode as well.

Simple use of properties files in JRuby involves

# Initialize the properties object from java.util
# Refer to http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
# on how to use.
properties = java.util::Properties.new
# Make sure that propertyfile exists!
properties.load(java.io.FileInputStream.new("propertyfile.properties"))
puts properties.getProperty("propertykey")

Now for some jdbc action! (The below code is well commented.. Enjoy!)

require 'java' # So we can use the sexy java goodness!
# Make sure you download this from the mysql site! (Link: http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.10.zip/from/pick)
require 'mysql-connector-java-3.1.10-bin.jar'
import 'com.mysql.jdbc.Driver' # Load the JDBC Driver

# Replace 'conn_string' with the JDBC Connection string (e.g. jdbc:mysql://localhost:3306/DBNAME)
# Replace 'uid' with the database username
# Replace 'pwd' with the database password
conn = java.sql::DriverManager.getConnection(conn_string, uid, pwd);
# Prepared queries are teh win
stmt = conn.prepareStatement("select field from table where otherfield = ?")
stmt.setString(1, "Whatwearesearchingfor") # First param
stmt.executeQuery
while rs.next do
puts rs.getString("field")
end
stmt.close # Because we should close what we open
conn.close # Same as above

And finally, some log4j thrown in!

require 'log4j-1.2.15.jar' # Assume you have already done require java
# The below is how you use log4j controlled by XML
import org.apache.log4j.Logger
import org.apache.log4j.xml.DOMConfigurator
logger = Logger.getLogger("LoggerName") # LoggerName would be defined in the XML file
DOMConfigurator.configure("log4j.xml")
logger.info "This would log an INFO entry if it were configured to be shown"
# Additionally you can use debug, info, warn, error, fatal

The results have been to a good degree of success. All I will need now to create a kickass and open source web frontend testing framework is:

  • Celerity
  • log4j
  • JDBC
  • properties files

I’ve basically got 90% of the functionality of a commercial tool right here!  Schweet!

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