Menu

#159 capturing a screenshot.

closed
None
5
2008-04-15
2006-09-07
Anonymous
No

It would be great if httpunit has a feature capturing
a screenshot for a given URL. I am not sure if it is
possible with the latest version.

Discussion

  • SidharthaPriye

    SidharthaPriye - 2007-04-05

    Logged In: YES
    user_id=1762215
    Originator: NO

    Are we looking at rendering "application-like" web pages?. What I mean by that is the captured screenshot intended to capture supporting images, stylesheets and javscripts. I have already developed the feature for my own project. If you are interested I would be glad to share it.

    Thanks
    Sidhartha

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-03-31
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> pending
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-03-31

    Logged In: YES
    user_id=1220573
    Originator: NO

    Please find below some code that I'm using myself for such a feature - how would you like this to be implemented in httpunit itself?

    /*
    Copyright (C) 1999-2006 BITPlan GmbH

    Pater-Delp-Str. 1
    D-47877 Willich-Schiefbahn

    Fon. +49 1805 BITPlan
    = +49 1805 2487526
    Fax. +49 2154 811 481

    generated: 11.03.2006 um 23:44

    $Header: /usr/cvsroot/Source/Eclipse/com.bitplan.testutil/src/com/bitplan/testutil/WebWatcher.java,v 1.9 2006/12/08 14:33:36 msf Exp $
    $Id: WebWatcher.java,v 1.9 2006/12/08 14:33:36 msf Exp $
    // >>>{RCS-Log section}{com/bitplan/testutil/WebWatcher.java}{com/bitplan/testutil/WebWatcher.java}
    $Log: WebWatcher.java,v $
    Revision 1.9 2006/12/08 14:33:36 msf
    Mac OS support

    Revision 1.8 2006/11/12 13:56:44 wf
    improving

    Revision 1.7 2006/11/10 18:06:34 wf
    improved

    Revision 1.6 2006/11/10 17:56:57 wf
    for SICCMOpti

    Revision 1.5 2006/11/10 14:13:18 wf
    improved

    Revision 1.4 2006/11/10 14:11:45 wf
    with -tab option

    Revision 1.3 2006/11/10 14:02:48 wf
    improved

    Revision 1.2 2006/03/11 22:45:21 wf
    regenerated

    Revision 1.1 2006/03/09 04:05:16 wf
    new files

    Revision 1.16 2006/03/04 14:02:43 wf
    regenerated

    Revision 1.15 2005/12/21 12:10:00 wf
    snapShotNow added

    Revision 1.14 2005/12/21 10:44:39 wf
    improved

    Revision 1.13 2005/12/21 09:43:05 wf
    fixed

    Revision 1.12 2005/12/21 08:13:44 wf
    fix

    Revision 1.11 2005/12/21 07:50:20 wf
    better JUnit multiple error support

    Revision 1.10 2005/06/28 15:16:14 wf
    regenerated

    Revision 1.9 2005/05/20 07:54:18 wf
    new type of problem ...

    Revision 1.8 2005/05/08 13:49:51 wf
    modified

    Revision 1.7 2005/05/04 13:25:04 wf
    W e b W a t c h e r modelled and regenerated

    // <<<{RCS-Log section}{com/bitplan/testutil/WebWatcher.java}{com/bitplan/testutil/WebWatcher.java}

    */
    /**
    * the package for all test utilties for test driven developmen
    */
    package com.bitplan.testutil;

    // >>>{User defined import section}{::com::bitplan::testutil::WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import com.bitplan.common.Execution;
    import com.bitplan.common.impl.ExecutionImpl;
    // <<<{User defined import section}{::com::bitplan::testutil::WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    import com.bitplan.testutil.*;
    import java.util.Vector;

    // needed imports for WebWatcher
    import java.io.File;
    import net.sourceforge.jwebunit.WebTester;

    import com.bitplan.common.Debug;

    /**
    * default java.lang package
    * @version $Id: WebWatcher.java,v 1.9 2006/12/08 14:33:36 msf Exp $
    * @author $Author: msf $
    * <DL><DT><B><DD>Template-Version:</B> Id: implgen.in,v 1.1 2006/03/10
    * 14:15:28 wf Exp </DD></DL>
    */
    public class WebWatcher {
    /**
    * ID for GNU Revision Control System - will show in the class file and
    * can be looked for
    * using the ident command of RCS
    */
    private final static String RCSID="$Id: WebWatcher.java,v 1.9 2006/12/08 14:33:36 msf Exp $";

    // >>>{User defined global section}{::com::bitplan::testutil::WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    // automatically call the browser to show a problem
    private boolean autoShow=false;
    /**
    * @return the autoShow
    */
    public boolean isAutoShow() {
    return autoShow;
    }
    /**
    * @param autoShow the autoShow to set
    */
    public void setAutoShow(boolean autoShow) {
    this.autoShow = autoShow;
    }

    protected File snapShotHtmlFile;
    /**
    * show the current snapShot in the browser
    */
    public void showFileInBrowser(File htmlFile) throws Exception {
    Execution exe=new ExecutionImpl();
    String os=System.getProperty("os.name");
    // use different browsers
    if (os.contains("Mac OS X")) {
    exe.execute("open "+htmlFile.getAbsolutePath());
    } else if(os.contains("Linux")) {
    exe.execute("firefox -new-tab file://"+htmlFile.getAbsolutePath());
    } else { // assume we have windows
    exe.execute("firefox -new-tab file://"+htmlFile.getAbsolutePath());
    } // if
    } // showSnapShotInBrowser

    /**
    * show the current snapShot in the browser
    */
    public void showSnapShotInBrowser() throws Exception {
    boolean oldAutoShow=isAutoShow();
    this.setAutoShow(true);
    snapShotNow();
    this.setAutoShow(oldAutoShow);
    } // showSnapShotInBrowser

    // <<<{User defined global section}{::com::bitplan::testutil::WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    // >>>{global reverse engineering}{::com::bitplan::testutil::WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    // <<<{global reverse engineering}{::com::bitplan::testutil::WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    // Attributes
    /**
    *
    * private flag whether htmlFile has been set
    */
    private boolean _sethtmlFile=false; // for lazy evaluation if set
    /**
    * getter for flag whether htmlFile has been set
    */
    private boolean _issethtmlFile() { return _sethtmlFile;} // is htmlFile set?

    /**
    * local copy for htmlFile
    * the default output file for the snapShots
    */
    private File myhtmlFile;
    /**
    * CORBA getter for htmlFile
    * the default output file for the snapShots
    * @return File
    * @throws Exception if getter fails
    */
    private File htmlFile() throws Exception {
    String ExcHint="?";
    try {
    if (!_sethtmlFile) {
    // >>>{Attr }{htmlFile}{I37c7eem103a7b28ea7mm7cf9}
    // <<<{Attr }{htmlFile}{I37c7eem103a7b28ea7mm7cf9}
    }
    } catch (Throwable t) {
    throw new com.bitplan.common.ExceptionStack("File htmlFile() failed: ",t,this,ExcHint);
    }
    return myhtmlFile;
    }
    /**
    * CORBA setter for htmlFile
    * @param phtmlFile the new File value to set
    * @throws Exception if getter fails
    */
    private void htmlFile(File phtmlFile) throws Exception {
    File lhtmlFile=myhtmlFile; // make old value available for Usercode
    myhtmlFile=phtmlFile;
    _sethtmlFile = true;
    // >>>{Attr set }{htmlFile}{I37c7eem103a7b28ea7mm7cf9}
    // no implementation yet !!!
    // <<<{Attr set }{htmlFile}{I37c7eem103a7b28ea7mm7cf9}
    }

    /**
    *
    * private flag whether sleeptime has been set
    */
    private boolean _setsleeptime=false; // for lazy evaluation if set
    /**
    * getter for flag whether sleeptime has been set
    */
    private boolean _issetsleeptime() { return _setsleeptime;} // is sleeptime set?

    /**
    * local copy for sleeptime
    * sleeptime between snapShots in Milliseconds
    */
    private int mysleeptime;
    /**
    * CORBA getter for sleeptime
    * sleeptime between snapShots in Milliseconds
    * @return int
    * @throws Exception if getter fails
    */
    private int sleeptime() throws Exception {
    String ExcHint="?";
    try {
    if (!_setsleeptime) {
    // >>>{Attr }{sleeptime}{I37c7eem103a7b28ea7mm7ce7}
    // no implementation yet !!!
    // <<<{Attr }{sleeptime}{I37c7eem103a7b28ea7mm7ce7}
    }
    } catch (Throwable t) {
    throw new com.bitplan.common.ExceptionStack("int sleeptime() failed: ",t,this,ExcHint);
    }
    return mysleeptime;
    }
    /**
    * CORBA setter for sleeptime
    * @param psleeptime the new int value to set
    * @throws Exception if getter fails
    */
    private void sleeptime(int psleeptime) throws Exception {
    int lsleeptime=mysleeptime; // make old value available for Usercode
    mysleeptime=psleeptime;
    _setsleeptime = true;
    // >>>{Attr set }{sleeptime}{I37c7eem103a7b28ea7mm7ce7}
    // no implementation yet !!!
    // <<<{Attr set }{sleeptime}{I37c7eem103a7b28ea7mm7ce7}
    }

    /**
    *
    * private flag whether tester has been set
    */
    private boolean _settester=false; // for lazy evaluation if set
    /**
    * getter for flag whether tester has been set
    */
    private boolean _issettester() { return _settester;} // is tester set?

    /**
    * local copy for tester
    * the tester to use for the snapShots and checks
    */
    private WebTester mytester;
    /**
    * CORBA getter for tester
    * the tester to use for the snapShots and checks
    * @return WebTester
    * @throws Exception if getter fails
    */
    private WebTester tester() throws Exception {
    String ExcHint="?";
    try {
    if (!_settester) {
    // >>>{Attr }{tester}{I37c7eem103a7b28ea7mm7ccb}
    // no implementation yet !!!
    // <<<{Attr }{tester}{I37c7eem103a7b28ea7mm7ccb}
    }
    } catch (Throwable t) {
    throw new com.bitplan.common.ExceptionStack("WebTester tester() failed: ",t,this,ExcHint);
    }
    return mytester;
    }
    /**
    * CORBA setter for tester
    * @param ptester the new WebTester value to set
    * @throws Exception if getter fails
    */
    private void tester(WebTester ptester) throws Exception {
    WebTester ltester=mytester; // make old value available for Usercode
    mytester=ptester;
    _settester = true;
    // >>>{Attr set }{tester}{I37c7eem103a7b28ea7mm7ccb}
    // no implementation yet !!!
    // <<<{Attr set }{tester}{I37c7eem103a7b28ea7mm7ccb}
    }

    // Operations

    /**
    * create a snapShot of the current WebContent as an HTMLfile
    * @throws Exception if snapShot fails
    */

    public void snapShot() throws Exception {
    String ExcHint="?";
    try {
    // >>>{Op }{snapShot}{I37c7eem103a7b28ea7mm7dba}
    snapShot(htmlFile());
    // <<<{Op }{snapShot}{I37c7eem103a7b28ea7mm7dba}
    } catch (Throwable _t) {
    throw new com.bitplan.common.ExceptionStack("void snapShot() failed",_t,this,ExcHint);
    }
    } // snapShot

    /**
    * assert that there is no PROBLEM or ERROR display on the current page
    * and do a snapShot, sleep a while after this
    * @throws Exception if assertNoProblem fails
    */

    public void assertNoProblem() throws Exception {
    String ExcHint="?";
    try {
    // >>>{Op }{assertNoProblem}{I37c7eem103a7b28ea7mm7d8c}
    snapShot();
    try {
    this.tester().assertTextNotPresent("<b>Fatal error</b>:");
    this.tester().assertTextNotPresent("Fatal error:");
    this.tester().assertTextNotPresent("PROBLEM:");
    this.tester().assertTextNotPresent("ERROR:");
    this.tester().assertTextNotPresent("PROGRAMMFEHLER");
    this.tester().assertTextNotPresent("Exception");
    this.tester().assertTextNotPresent("exception:");
    } catch (Throwable _t1) {
    snapShotNow();
    throw (_t1);
    }
    if (this.sleeptime()>0)
    Thread.sleep(this.sleeptime());
    // <<<{Op }{assertNoProblem}{I37c7eem103a7b28ea7mm7d8c}
    } catch (Throwable _t) {
    throw new com.bitplan.common.ExceptionStack("void assertNoProblem() failed",_t,this,ExcHint);
    }
    } // assertNoProblem

    /**
    * create a snapShot of the current WebContent as an HTMLfile
    * @param htmlFile the file to write the snapshot to
    * @throws Exception if snapShot fails
    */

    public void snapShot(File htmlFile) throws Exception {
    String ExcHint="?";
    try {
    // >>>{Op }{snapShotFile htmlFile}{I37c7eem103a7b28ea7mm7d5b}
    java.io.PrintWriter htmlWriter = new java.io.PrintWriter(new java.io.FileOutputStream(htmlFile));
    htmlWriter.print(this.tester().getTestContext().getWebClient().getCurrentPage().getText());
    htmlWriter.close();
    // <<<{Op }{snapShotFile htmlFile}{I37c7eem103a7b28ea7mm7d5b}
    } catch (Throwable _t) {
    if (ExcHint.equals("?")) {
    ExcHint="";
    // htmlFile: File
    } // if
    throw new com.bitplan.common.ExceptionStack("void snapShot(File htmlFile) failed",_t,this,ExcHint);
    }
    } // snapShot

    /**
    * get the fully qualifying domain name of the localhost
    * @throws Exception if getDefaultHost fails
    * @return get the fully qualifying domain name of the default host:
    * localhost
    */

    public String getDefaultHost() throws Exception {
    String result=null;
    String ExcHint="?";
    try {
    // >>>{Op }{getDefaultHost}{I37c7eem103a7b28ea7mm7d20}
    result=java.net.InetAddress.getLocalHost().getCanonicalHostName();
    // <<<{Op }{getDefaultHost}{I37c7eem103a7b28ea7mm7d20}
    } catch (Throwable _t) {
    throw new com.bitplan.common.ExceptionStack("String getDefaultHost() failed",_t,this,ExcHint);
    }
    return result;
    } // getDefaultHost

    /**
    * Constructor to use
    * @param tester the tester to use
    * @throws Exception if WebWatcher fails
    */

    public WebWatcher(WebTester tester) throws Exception {
    // >>>{constructor calls}{WebWatcherWebTester tester}{I37c7eem103a7b28ea7mm7cb7}
    // <<<{constructor calls}{WebWatcherWebTester tester}{I37c7eem103a7b28ea7mm7cb7}
    String ExcHint="?";
    try {
    // >>>{Op }{WebWatcherWebTester tester}{I37c7eem103a7b28ea7mm7cb7}
    this.tester(tester);
    this.sleeptime(0);
    this.htmlFile(new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"WebWatcher.html"));
    // <<<{Op }{WebWatcherWebTester tester}{I37c7eem103a7b28ea7mm7cb7}
    } catch (Throwable _t) {
    if (ExcHint.equals("?")) {
    ExcHint="";
    // tester: WebTester
    } // if
    throw new com.bitplan.common.ExceptionStack(" WebWatcher(WebTester tester) failed",_t,this,ExcHint);
    }
    } // WebWatcher

    /**
    * create a snapShot of the current WebContent as an HTMLfile with the
    * currentTimeStamp as a name
    * @throws Exception if snapShotNow fails
    */

    public void snapShotNow() throws Exception {
    String ExcHint="?";
    try {
    // >>>{Op }{snapShotNow}{I103c520m1084d36950dmm7a0a}
    String dateStr;
    SimpleDateFormat formatter= new SimpleDateFormat ("yyyy-MM-dd_HH-mm-ss");
    Date now = new Date();
    dateStr= formatter.format(now);
    snapShotHtmlFile=new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"WebWatcher"+dateStr+".html");
    snapShot(snapShotHtmlFile);
    if (autoShow) {
    this.showFileInBrowser(snapShotHtmlFile);
    }
    // <<<{Op }{snapShotNow}{I103c520m1084d36950dmm7a0a}
    } catch (Throwable _t) {
    throw new com.bitplan.common.ExceptionStack("void snapShotNow() failed",_t,this,ExcHint);
    }
    } // snapShotNow
    // Relations
    /**
    * default Constructor
    * @throws Exception if constructor fails
    */
    public WebWatcher() throws Exception {
    // >>>{Constructor 1}{WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    // no implementation yet !!!
    // <<<{Constructor 1}{WebWatcher}{I37c7eem103a7b28ea7mm7dd1}
    }

    } // WebWatcher

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-03-31

    Logged In: YES
    user_id=1220573
    Originator: NO

    Dear httpunit user!

    Thank you for your feature request. We appreciate the time and effort you are putting into this.

    Please supply a testcase with the expected result for the feature you are asking for and we'll look into implementing it. For a start you might want to get the trunk version from the
    subversion repository (see https://sourceforge.net/svn/?group_id=6550\)
    and have a look at the source code of some of the more than 700 JUnit based testcase in there.

    When you are ready you might want to attach the testcase (and if you already have started implementing it also the actual code) to your feature request.

    This should give you a clue on what a proper testcase for httpunit looks like. The main communication about further details of the development is via the httpunit developer mailinglist. You are most welcome to sign up via
    https://lists.sourceforge.net/lists/listinfo/httpunit-develop

    Yours
    The httpunit developer team

    (Russell and Wolfgang as of 2008-03)

     
  • SourceForge Robot

    • status: pending --> closed
     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     

Log in to post a comment.