Sorry for mis-understanding your question... (Sometimes, my mind is just
switched off :))

BTW even htmlUnit is very good, Selenium is very slow... I use PageTester
for non-ajax unit testing.

You can look at

code.google.com/p/tapestry-addons/

I have used selenium for ajax-testing. You will find it very easy.

For HtmlUnit, may be this code will help. Here I have started a jetty server
and then used htmlunit to test all links on 'Index' page are properly
rendered


public class TawusComponentsTest extends Assert {
   private static EmbeddedJettyServer server;
   private String url;
   private WebClient webClient;
   private HtmlPage page;

   @BeforeClass
   public void startServer() throws Exception {
      server = new EmbeddedJettyServer("src/test/webapp",
"/tawus-hibernate");
      server.start();
      url = server.getUrl();
      webClient = new WebClient();
   }

   @Test
   public void testAllLinks() throws IOException {
      page = webClient.getPage(url + "index");
      List<HtmlAnchor> anchors = page.getAnchors();

      for(final HtmlAnchor anchor : anchors){
         HtmlPage testPage = anchor.click();
         assertTrue(testPage.getTitleText().contains("Tawus Integration
Testing"),
            "Rendering failed for " + anchor.asText());
      }
   }



   @AfterClass
   public void stopServer() throws Exception {
      webClient.closeAllWindows();
      server.stop();
   }
}

The embedded server is

package com.googlecode.tawus.test;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.webapp.WebAppContext;

public class EmbeddedJettyServer {

   private String location;
   private String contextPath;
   private Server server;
   private String url;
   private int port;

   public EmbeddedJettyServer(String location, String context) {
      this(location, context, 8080);
   }

   public EmbeddedJettyServer(String location, String context, int port){
      this.location = location;
      this.contextPath = context;
      this.port = port;
   }


   public int getPort(){
      return port;
   }

   public String getUrl() {
      return url;
   }

   public Server getServer() {
      return server;
   }

   public void start() throws Exception {
      server = new Server();
      SocketConnector connector = new SocketConnector();
      connector.setPort(getPort());
      server.setConnectors(new Connector[] { connector });
      WebAppContext context = new WebAppContext();
      context.setServer(server);
      context.setContextPath(contextPath);
      context.setWar(location);
      server.setHandler(context);
      server.start();
      url = "http://localhost:"; + getPort() +  contextPath  + "/";
   }

   public void stop() throws Exception {
      server.stop();
   }

}

Hope it helps
regards
Taha



On Thu, Apr 7, 2011 at 6:56 PM, Paul Field <paul.fi...@db.com> wrote:

> Testify cannot run unit tests that rely on javascript - it is not
> simulating an entire browser. So your tests act more like a browser
> running with javascript turned off and you can't test AJAX functionality.
> However you can test that your page degrades well if there is no
> Javascript :-)
>
> You can find out a bit more about making your pages degrade gracefully in
> Tapestry's Ajax guide:
> http://tapestry.apache.org/tapestry5/guide/ajax.html
> (look for the section "Graceful Degradation")
>
> If you need a full browser simulation, then try using Selenium with the
> tapestry-test module (http://tapestry.apache.org/tapestry5/tapestry-test/)
>
> Selenium is a lot slower than Testify though, so the best approach is to
> use both tools and test with Testify for non-Javascript/Ajax functionality
> and use Selenium when you want to test with a full browser implementation.
>
> - Paul
>
>
> joknroll <adjudentifr...@yahoo.com> wrote on 07/04/2011 13:16:02:
>
> > hum, I agree with you,it works :)
> > But my problem concern the usage of tapestry testify to do unit testing
> on
> > my component.
> >
> > My dummy case is to understand the behavior of unit test with testify to
> > implement it in a bigger project.
> >
> > --------------------------------------------------------
> > my dummy.tml:
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> >
> > ${messageChangeWhenSubmit}
> >
> >
> >
> >
> >
> >
> >
> >
> > --------------------------------------------------------
> > in my class TestDummy.java:
> > [...]
> >    @Test
> >    public void updateValue() {
> >       Document doc = tester.renderPage("demo/dummyDemo");
> >       Element submitButton = doc.getElementById("mySubmit");
> >       Map&lt;String, String&gt; parameters = new HashMap&lt;String,
> > String&gt;();
> >       doc = tester.clickSubmit(submitButton, parameters);
> >       assertEquals(doc.getElementById("testDiv").getChildMarkup(), "!!
> UPDATE
> > !!");
> >    }
> > --------------------------------------------------------
> > in my Dummy.java
> > [...]
> >    @Persist
> >    @Property
> >    private String messageChangeWhenSubmit;
> >
> >    @Component(id = "myForm")
> >    private Form myForm;
> >
> >    @Property
> >    @InjectComponent
> >    private Zone myZone;
> >
> >    @SetupRender
> >    public void init() {
> >       logger.debug("## INIT ##");
> >       messageChangeWhenSubmit = "somethingToTest";
> >    }
> >
> >    @OnEvent(value = EventConstants.VALIDATE, component = "myForm")
> >    public Object launchProcess() {
> >       messageChangeWhenSubmit = "!! UPDATE !!";
> >       return myZone;
> >    }
> > --------------------------------------------------------
> >
> > The test "updateValue" failed.. I wanted to know if it's a usage of
> testify
> > and what I have to be aware of to pass the test....
> >
> > --
> > View this message in context: http://tapestry.1045711.n5.nabble.
> > com/Tapestry-Testify-SetupRender-launched-instead-of-update-a-zone-
> > tp4288081p4288382.html
> > Sent from the Tapestry - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@tapestry.apache.org
> >
>
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and delete this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.

Reply via email to