-
Notifications
You must be signed in to change notification settings - Fork 6
Getting Started
This tutorial explains how to set up and run QxWebDriver tests for a qooxdoo Desktop application using Maven and JUnit.
- JDK (5+), Maven and Firefox (or any other supported browser) to write and run the tests
- Python 2.x and a qooxdoo (Desktop) SDK to create the application to be tested
path_to_qooxdoo_sdk/create-application.py -n helloworld
cd helloworld
./generate.py build
cd ..
(This step will be unnecessary once qxwebdriver-java has matured a bit and is made available through open source Maven repositories.)
git clone https://github.com/qooxdoo/qxwebdriver-java.git
cd qxwebdriver-java
mvn install -DskipITs
cd ..
Note the artifact's version number near the end of the console output, e.g. 0.0.1-SNAPSHOT.
mvn archetype:generate -DgroupId=com.mycompany.helloworld -DartifactId=helloworld-test -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd helloworld-test
Open pom.xml in your favorite editor and edit the dependencies
section:
<dependencies>
<dependency>
<groupId>org.oneandone</groupId>
<artifactId>qxwebdriver-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
Make sure you use the qxwebdriver-java version number from Step 2. For JUnit, we want to use a 4.x version (the Maven quickstart archetype defaults to 3.x).
The project will contain a demo test case, helloworld-test/src/test/java/com/mycompany/helloworld/AppTest.java. Replace the contents of this file with the following code:
package com.mycompany.helloworld;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.oneandone.qxwebdriver.By;
import org.oneandone.qxwebdriver.QxWebDriver;
import org.oneandone.qxwebdriver.ui.Widget;
import org.openqa.selenium.Alert;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AppTest {
static QxWebDriver driver;
static final String AUT_URL = "file:///home/username/workspace/helloworld/build/index.html";
@BeforeClass
public static void setUpBeforeClass() throws Exception {
FirefoxDriver webDriver = new FirefoxDriver();
driver = new QxWebDriver(webDriver);
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
driver.close();
}
@Before
public void setUp() throws Exception {
driver.get(AUT_URL);
}
@Test
public void testButton() {
Widget button = driver.findWidget(By.qxh("qx.ui.form.Button"));
String buttonLabel = (String) button.getPropertyValue("label");
assertEquals("First Button", buttonLabel);
button.click();
Alert alert = driver.switchTo().alert();
assertEquals(alert.getText(), "Hello World!");
alert.accept();
}
}
Change AUT_URL
as appropriate. For a real project you would probably make this configurable by defining a property in pom.xml.
As you can see, the test case is pretty straightforward:
-
setUpBeforeClass
creates the QxWebDriver instance that all tests in this class will use -
setUp
(re)loads the application before each test -
testButton
uses QxWebDriver to locate the button widget, verify its label, click it and verify that the alert box is displayed. -
tearDownAfterClass
closes the browser
Execute the project's test
goal:
mvn test
At this point, you might get a compilation failure saying static import declarations are not supported in -source 1.3
. If so, edit pom.xml and configure the project to use your Java version, e.g. 1.6 for Java 6:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Provided there are no (further) errors, you should see Firefox open, load the qooxdoo application and (very briefly) flash the alert box before closing down.