Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The client is able to request URLs, fill in form data, click links, and make assertions about output and behavior.

Usage

...

The core part of this library is a base class for you to extend your tests cases fromclasses : AbstractIntegrationTestSuite SeleniumTestCase.

This class is responsible for starting an instance of Jetty to server your web application, as well as a copy of Selenium Server. It also implements the Selenium interface.You must inform the suite about the location of your web application. The default location is src/main/webapp (as this is the default directory for storing a web application when building using Maven). This can be changed by provided a public constructor for your test suite.

Note

Before Tapestry 5.2, your class should extend AbstractIntegrationTestSuite

Here's an example from one of the Tapestry modules:

Code Block
java
java
package org.apache.tapestry5.springjpa.integration.app2;

import org.apache.tapestry5.test.AbstractIntegrationTestSuiteSeleniumTestCase;
import org.testng.annotations.Test;

public class TapestrySpringIntegrationTestSinglePersistenceUnitIntegrationTest extends AbstractIntegrationTestSuite
{
    public TapestrySpringIntegrationTest()
    {
        super("src/test/webapp");
    }
    SeleniumTestCase
{

    @Test
    public void integrationpersist_testentities() throws Exception
    {
        open(BASE_URL);

        type("input", "paris in the springtime("/persistitem");
        clickAndWaitassertEquals(getText("//inputspan[@value@id='Convertname']");

        assertFieldValue("input", "PARIS IN THE SPRINGTIME");
    }.length(), 0);

    @Test
    public void access_to_spring_context() throws Exception
    {
        open(BASE_URLclickAndWait("link=create item");

        assertTextPresentassertText("[upcase]//span[@id='name']", "name");
    }
} 

With the SeleniumTestCase class, you can use basic This is a very simple example, but it demonstrates a mix of Selenium methods (such as open() and type()) and methods added by the AbstractIntegrationTestSuite SeleniumTestCase base class (clickAndWait() and assertFieldValue()).

Of course, a real integration test would contain many methods, and may need to single thread their execution, or even specify an execution order.

In addition, the AbstractIntegrationTestSuite SeleniumTestCase base class extends the normal exception reporting provided by Selenium; when a failure occurs inside Selenium server, a more detailed message, including the current page's HTML source, is reported to System.err.

Configuration

All the configuration of your Integration Tests should be in your testng.xml file. Tapestry provides some parameters, in order to have the right environment for your tests.

Parameter

Default Value

Value

tapestry.web-app-folder

src/main/webapp

The path to a web app

tapestry.servlet-container

jetty7

the server container to use for the integration tests (jetty7 or tomcat6)

tapestry.context-path

 

The context path

tapestry.port

9090

The web server port

tapestry.ssl-port

8443

The web server ssl port

tapestry.browser-start-command

*firefox

The browser command to pass to Selenium

Here's an example :

Code Block
xml
xml

<suite name="Selenium Tests Suite" annotations="1.5">
  <test name="Integration Tests" enabled="true">
    <parameter name="tapestry.browser-start-command" value="*googlechrome" />
    <parameter name="tapestry.port" value="9091" />

    <classes>
      <class name="com.example.newapp.SeleniumTest"></class>
    </classes>
  </test>
</suite>