Concerning webtest.version::Canoo Webtest: R_1217.
I have several problems with Canoo Webtest, they could be split in these points:
1. Access dynamic properties in an own java class
2. Execute webtest steps in a java class
3. Access an email (via the filters)
4. Proper way to wait for a specific email
1)
The declarative approach of ANT (and webtest) seems inappropriate sometimes.
The webtest documentation suggests to use Groovy in this case, but because of
the good Eclipse support and meaningful error msgs I choose to use Java for
more complex situations.
My first problem is that I can't access webtests dynamic properties in my Java
class. The ANT side declaration looks like this :
<taskdef name="mytask" classname="javaTestSupport.CommonTasks"
classpathref="classpath"/>
<webtest (...)">
<config (...)/>
<steps>
<mytask userRole="test" />
</steps>
</webtest>
My Java-Class:
public class CommonTasks extends com.canoo.webtest.steps.Step{
public void doExecute() throws BuildException{
setWebtestProperty("isUser", Boolean.toString(isUser),
Step.PROPERTY_TYPE_DYNAMIC);
}
}
leads to:
INFO (com.canoo.webtest.steps.Step) - Exception thrown from this class:
com.canoo.webtest.engine.StepExecutionException
INFO (com.canoo.webtest.steps.Step) - Message was: Unexpected exception caught:
java.lang.NullPointerException
ERROR (com.canoo.webtest.steps.Step) - Cannot handle unexpected exception in
step AntWrapper at with (description="<unknown>")
com.canoo.webtest.engine.StepExecutionException: Unexpected exception caught:
java.lang.NullPointerException, Step: CommonTasks at
C:\(...)\justATest.webtest.xml:17: with (stepType="mytask")
at com.canoo.webtest.steps.Step.handleUnexpectedException(Step.java:607)
at com.canoo.webtest.steps.Step.execute(Step.java:138)
at org.apache.tools.ant.Task.perform(Task.java:364)
at com.canoo.webtest.extension.AntWrapper.doExecute(AntWrapper.java:77)
at com.canoo.webtest.steps.Step.execute(Step.java:135)
My first thought Just to use ant properties (because they are not immutable in
a java-class) doesn't work neither, because webtest doesn't seems to expand the
ant properties during a webtest. Starting a new webtest with another session
is not useful.
2)
My workaround now was just to execute StoreProperty inside Java.
So I created a StoreProperty Step and tried to execute it as follows:
StorePropertyStep sp = new StorePropertyStep();
sp.setContext(getContext());
sp.setContainer(getContainer());
sp.setProject(getProject());
sp.setLocation(getLocation());
sp.setRuntimeConfigurableWrapper(getRuntimeConfigurableWrapper());
sp.setDescription("set isUserProperty");
sp.setWebtestProperty("userRole", "userRole", "dynamic");
/* Other options I played around with
sp.setName("userRole");
sp.setProperty("userRole2");
sp.setValue(Boolean.toString(isUser));
sp.doExecute();
sp.setWebtestProperty("userRole", "userRole");
sp.execute();
*/
all result in this kind of exception:
ERROR (com.canoo.webtest.steps.Step) - Cannot handle unexpected exception in
step AntWrapper at with (description="<unknown>")
com.canoo.webtest.engine.StepExecutionException: Unexpected exception caught:
java.lang.NullPointerException, Step: CommonTasks at
C:\(...)\justATest.webtest.xml:17: with (stepType="mytask")
at com.canoo.webtest.steps.Step.handleUnexpectedException(Step.java:607)
at com.canoo.webtest.steps.Step.execute(Step.java:138)
at org.apache.tools.ant.Task.perform(Task.java:364)
at com.canoo.webtest.extension.AntWrapper.doExecute(AntWrapper.java:77)
at com.canoo.webtest.steps.Step.execute(Step.java:135)
(...)
Caused by: java.lang.NullPointerException
at com.canoo.webtest.steps.Step.setWebtestProperty(Step.java:426)
at javaTestSupport.CommonTasks.doExecute(CommonTasks.java:61)
at com.canoo.webtest.steps.Step.execute(Step.java:135)
==> How to set/get dynamic canoo/webtest properties in a java class?
3)
I switched to testing emails and after some hours I stuck in problems again.
I want to access the content of a plain email. Therefore I want to SAVE the
email once. Whenever I try to do this, an exception is thrown
Following code is working:
<emailSetConfig server="@{eMail.mailServer}" type="@{eMail.serverType}"
password="@{eMail.password}" username="@{eMail.userName}"
delay="@{eMail.serverDelay}" />
<sleep seconds="@{emailReceiveTime}"/>
<emailStoreMessageId
from="@{eMail.petToyServerEMailAdress}" to="@{eMail.UserEmailAddress}"
property="confirmEMail.id" propertyType="dynamic"
subject="@{eMail.registerdNewUserSuccessfully.Header}" />
<emailMessageContentFilter description="MessageContent of
confirmation email" contentType="simple" messageId="#{confirmEMail.id}" />
I verified that the code is working properly by adding <verifyText
text="xxxx"/> with good/bad values.
If I add to emailMessageContentFilter save="xxx" or if I change in my <config>
saveresponse="true" the following exception occurs:
C:\\webtest\commonTasks.webLib.xml:258: The following error occurred while
executing this line:
C:\\website\build.xml:310: org.dbunit.dataset.NoSuchTableException: rotina
ERROR (com.canoo.webtest.steps.Step) - Cannot handle unexpected exception in
step AntWrapper at with (description="<unknown>")
C:\\website\webtest\testes\createNewUser.webtest.xml:108: The following error
occurred while executing this line:
C:\\website\webtest\commonTasks.webLib.xml:258: The following error occurred
while executing this line:
C:\\website\build.xml:310: org.dbunit.dataset.NoSuchTableException: rotina
at
org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:380)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:64)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
4)
Is there a better way than try to guess the time until a specific email
arrives? My code right now looks like this and is not very useful.
<emailSetConfig .../>
<sleep seconds="@{emailReceiveTime}"/>
<emailStoreMessageCount ...
Thanks /MfG
Stefan
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest