1 message in com.canoo.lists.webtest[Webtest] Patch to support error/fail...
FromSent OnAttachments
Paul King26 Jan 2004 00:27 
Subject:[Webtest] Patch to support error/failure properties
From:Paul King (pau@worldplayservices.com)
Date:01/26/2004 12:27:46 AM
List:com.canoo.lists.webtest

Hi,

Please find below a patch which adds support for errorproperty and failureproperty configuration settings as per the ant junit task.

To use it simply place two extra lines "failureproperty" and/or "errorproperty" in your config tag:

<config

host="localhost"

port="7001"

protocol="http"

basepath="/ "

summary="true"

verbose="true"

haltonfailure="false"

haltonerror="false"

failureproperty="test.failure"

errorproperty="test.error"

resultpath="results"

resultfile="myTestResults.xml"/>

These now become ant properties which you can reference in your ant build script, so you can have multiple steps executing in your ant file with the error/failure captured at the end:

...

<target name="all" depends="junit1,webtest1,webtest2,...,reports,checktesterrors,checktestf ailures" />

<target name="reports" >

<style ...

<target name="checktestfailures" if="test.failure">

<fail>There were test failures</fail>

</target>

<target name="checktesterrors" if="test.error">

<fail>There were test errors</fail>

</target>

<target name="junit1">

<junit errorproperty="test.error" failureproperty="test.failure" ...

<target name="webtest1" depends="init">

<testSpec name="webtest1">

&config;

<steps>

&login;

&logout;

</steps>

</testSpec>

</target>

...

There are several ant books which describe the benefits of this approach when used with junit (e.g. allowing cleanup to occur, allowing reports to be generated, allowing multiple failures to be gathered with one test run) but obviously there will be some use cases where you don't want to set these values as per the above example, e.g. when there are dependencies between your test cases (usually a bad idea but not always avoidable) and one test case failing will cause subsequent errors for all dependent tests (i.e. so that subsequent test case failures aren't really a reflection of errors in the test code).

Cheers, Paul.

-------------------->8--------------------

diff -c -w -r src-386/src/com/canoo/webtest/ant/TestSpecificationTask.java src-386-patched/src/com/canoo/webtest/ant/TestSpecificationTask.java

*** src-386/src/com/canoo/webtest/ant/TestSpecificationTask.java Fri Jan 23 20:50:06 2004

--- src-386-patched/src/com/canoo/webtest/ant/TestSpecificationTask.java Mon Jan 26 15:10:43 2004

***************

*** 70,77 ****

webTestResult.isFailure() && config.isHaltOnFailure()) {

throw new BuildException(PlainTextReporter.getBuildFailMessage(webTestResult));

}

}

-

public void logVerbose(String message) {

log(message, Project.MSG_VERBOSE);

--- 70,82 ----

webTestResult.isFailure() && config.isHaltOnFailure()) {

throw new BuildException(PlainTextReporter.getBuildFailMessage(webTestResult));

}

+ if (webTestResult.isError() && config.getErrorProperty() != null) {

+ getProject().setProperty(config.getErrorProperty(), "true");

+ }

+ if (webTestResult.isFailure() && config.getFailureProperty() != null) {

+ getProject().setProperty(config.getFailureProperty(), "true");

+ }

}

public void logVerbose(String message) {

log(message, Project.MSG_VERBOSE);

diff -c -w -r src-386/src/com/canoo/webtest/engine/Configuration.java src-386-patched/src/com/canoo/webtest/engine/Configuration.java

*** src-386/src/com/canoo/webtest/engine/Configuration.java Fri Jan 23 20:50:06 2004

--- src-386-patched/src/com/canoo/webtest/engine/Configuration.java Mon Jan 26 15:11:27 2004

***************

*** 29,34 ****

--- 29,36 ----

private boolean fShowHtmlParserOutput = false;

private boolean fHaltOnError = true;

private boolean fHaltOnFailure = true;

+ private String fErrorProperty = null;

+ private String fFailureProperty = null;

private String fHost;

private String fBasePath;

***************

*** 248,257 ****

--- 250,275 ----

fHaltOnError = haltOnError;

}

+ public void setErrorProperty(String errorProperty) {

+ fErrorProperty = errorProperty;

+ }

+

+ public void setFailureProperty(String failureProperty) {

+ fFailureProperty = failureProperty;

+ }

+

+ public String getFailureProperty() {

+ return fFailureProperty;

+ }

+

public void setHaltonfailure(boolean haltOnFailure) {

fHaltOnFailure = haltOnFailure;

}

+ public String getErrorProperty() {

+ return fErrorProperty;

+ }

+

public void setShowhtmlparseroutput(boolean showParserOutput) {

fShowHtmlParserOutput = showParserOutput;

}

***************

*** 282,287 ****

--- 300,307 ----

map.put("saveresponse", (isSaveResponse() ? "yes" : "no"));

map.put("haltonerror", (isHaltOnError() ? "yes" : "no"));

map.put("haltonfailure", (isHaltOnFailure() ? "yes" : "no"));

+ map.put("errorproperty", (getErrorProperty() == null ? "" : getErrorProperty()));

+ map.put("failureproperty", (getFailureProperty() == null ? "" : getFailureProperty()));

map.put("showhtmlparseroutput", (isShowHtmlParserOutput() ? "yes" : "no"));

map.put("resultfile", getResultFile());