Index: gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSTestingUtil.java
===================================================================
--- gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSTestingUtil.java	(revision 26108)
+++ gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSTestingUtil.java	(revision 26108)
@@ -0,0 +1,157 @@
+package org.greenstone.gsdl3.testing;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+public class GSTestingUtil
+{
+	public static boolean isImageLoaded(WebDriver driver, WebElement image)
+	{
+		return (Boolean) ((RemoteWebDriver) driver).executeScript("return arguments[0].complete", image);
+	}
+
+	public static void loginAs(WebDriver driver, String username, String password)
+	{
+		//Click the login button
+		WebElement loginButton = findElementByXPath(driver, "//li[@id='userMenuButton']/a");
+		loginButton.click();
+
+		//Enter the username
+		WebElement usernameInput = findElementByXPath(driver, "//input[@name='username']");
+		usernameInput.sendKeys(username);
+
+		//Enter the password
+		WebElement passwordInput = findElementByXPath(driver, "//input[@name='password']");
+		passwordInput.sendKeys(password);
+
+		//Log in
+		loginButton = findElementByXPath(driver, "//input[@type = 'submit']");
+		loginButton.click();
+	}
+
+	public static void logout(WebDriver driver)
+	{
+		//Open up the user menu
+		WebElement menuButton = findElementByXPath(driver, "//li[@id='userMenuButton']/a");
+		menuButton.click();
+
+		//Wait for the menu to display
+		WebElement menu = findElementByXPath(driver, "//ul[@id='userMenu']");
+		waitForXPath(driver, "//ul[@id='userMenu']");
+		for (int i = 0; i < 30; i++)
+		{
+			if (menu.getAttribute("style").contains("display: block;"))
+			{
+				break;
+			}
+
+			//The menu hasn't displayed in 30 seconds
+			if (i == 29)
+			{
+				Assert.fail();
+			}
+
+			try
+			{
+				Thread.sleep(1000);
+			}
+			catch (Exception ex)
+			{
+				ex.printStackTrace();
+			}
+		}
+
+		WebElement logoutButton = menu.findElement(By.xpath("./a[2]"));
+		logoutButton.click();
+	}
+
+	public static String generateRandomString(int length)
+	{
+		StringBuffer stringToReturn = new StringBuffer("");
+		for (int i = 0; i < length; i++)
+		{
+			int num = (int) (Math.random() * 52);
+			if (num < 26)
+			{
+				char c = (char) ('a' + num);
+				stringToReturn.append(c);
+			}
+			else
+			{
+				char c = (char) ('A' + (num - 26));
+				stringToReturn.append(c);
+			}
+		}
+
+		return stringToReturn.toString();
+	}
+
+	public static void loadClassifierByName(WebDriver driver, String name)
+	{
+		WebElement link = findElementByXPath(driver, "//ul[@id='gs-nav']/li/a[text()='" + name + "']");
+		link.click();
+	}
+
+	public static void loadCollectionByName(WebDriver driver, String collection)
+	{
+		WebElement demoColLinkElem = findElementByXPath(driver, "//div[@id='collectionLinks']/a[descendant::text()='" + collection + "']");
+		demoColLinkElem.click();
+	}
+
+	public static WebElement findElementByXPath(WebDriver driver, String xpath)
+	{
+		WebElement elem;
+		try
+		{
+			elem = driver.findElement(By.xpath(xpath));
+			return elem;
+		}
+		catch (NoSuchElementException ex)
+		{
+			return null;
+		}
+	}
+
+	public static List<WebElement> findElementsByXPath(WebDriver driver, String xpath)
+	{
+		List<WebElement> elems;
+		try
+		{
+			elems = driver.findElements(By.xpath(xpath));
+			return elems;
+		}
+		catch (NoSuchElementException ex)
+		{
+			return null;
+		}
+	}
+
+	public static void waitForXPath(WebDriver driver, String xpath)
+	{
+		final String path = xpath;
+		//Wait for the page to load
+		(new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>()
+		{
+			public Boolean apply(WebDriver d)
+			{
+				try
+				{
+					d.findElement(By.xpath(path));
+					return true;
+				}
+				catch (NoSuchElementException ex)
+				{
+					return false;
+				}
+			}
+		});
+	}
+}
