Hi,

WebTest default behavior is to fail when an http error code is received.
 You can change this with
<config>
  <option name="ThrowExceptionOnFailingStatusCode," value="false"/>
</config

or
<groovy>
  step.context.webClient.throwExceptionOnFailingStatusCode = false
</groovy>

Cheers,
Marc.
-- 
Blog: http://mguillem.wordpress.com


Douglas Beattie wrote:
> I properly detect and verify (via verifyXPath) a successful login where the 
> response contains a statusCode=200, but when I run a test which provides an 
> invalid username and password to the login API the check for a statusCode=401 
> never gets executed. I see the 401 in the response but my test is failing 
> before I can execute the code to verify the statusCode. What am I doing wrong?
> 
> Here is my test:
> ---------------------------------------------
> <?xml version="1.0"?>
> 
> <!DOCTYPE project SYSTEM "../../dtd/Project.dtd">
> 
> <project name="loginInvalidUser" default="test">
> 
>   <target name="test">
>     <webtest name="Login Invalid User">
>         <steps>
>           <invoke url="http://${HOST}:${PORT}/identity/${VERSION}/login"; 
> username="${INVALIDUSER}" password="${INVALIDPASSWORD}"
>             description="Login Invalid User"
>           />
> 
>           <verifyXPath
>             description="Check login status code equals 401"
>             xpath="//@statusCode='401'"
>           />
> 
>         </steps>
>     </webtest>
>   </target>
> </project>
> ---------------------------------------------
> 
> The response I received from this test in both the ...response_invoke.xml and 
> the ...response_steps.xml files is:
> ---------------------------------------------
> <?xml version='1.0' encoding='UTF-8'?><identity 
> xmlns="http://api.familysearch.org/identity/v1"; 
> xmlns:fsapi-v1="http://api.familysearch.org/v1"; version="1.0.20080107.1070" 
> statusMessage="Authentication failed." 
> statusCode="401"><fsapi-v1:errors><fsapi-v1:error 
> code="401"><fsapi-v1:message>Authentication 
> failed.</fsapi-v1:message></fsapi-v1:error></fsapi-v1:errors></identity>
> ---------------------------------------------
> 
> The WebTestReport.xml file contains:
> ---------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <summary Implementation-Title="Canoo Webtest" Implementation-Version="R_1646">
>     <testresult endtime="Wed Jan 16 13:58:57 MST 2008"
>         
> location="/home/default/CanooWebTest/Home/SLAT_Tests/tests/Login_Logout/loginInvalidUser.xml:8:
>  "
>         starttime="Wed Jan 16 13:58:57 MST 2008" successful="no" 
> testspecname="Login Invalid User">
>         <config>
>             <parameter name="port" value="80"/>
>             <parameter name="summary" value="yes"/>
>             <parameter name="protocol" value="http"/>
>             <parameter name="host" value="localhost"/>
>             <parameter name="resultpath" 
> value="/home/default/CanooWebTest/Home/SLAT_Tests/results"/>
>             <parameter name="saveprefix" value="response"/>
>             <parameter name="basepath" value="null"/>
>             <parameter name="resultfile" value="WebTestReport.xml"/>
>             <parameter name="haltonerror" value="no"/>
>             <parameter name="errorproperty" value="webtest.error"/>
>             <parameter name="saveresponse" value="yes"/>
>             <parameter name="haltonfailure" value="no"/>
>             <parameter name="failureproperty" value="webtest.failure"/>
>             <parameter name="showhtmlparseroutput" value="yes"/>
>             <parameter name="timeout" value="300"/>
>         </config>
>         <results>
>             <step>
>                 <parameter name="description" value="Login Invalid User"/>
>                 <parameter name="password" value="invalid"/>
>                 <parameter name="resultFilename" 
> value="001_response_invoke.xml"/>
>                 <parameter name="taskName" value="invoke"/>
>                 <parameter name="url" 
> value="http://10.0.1.1:8080/identity/v1/login"/>
>                 <parameter name="username" value="invalid"/>
>                 <result>
>                     <failed duration="192"/>
>                 </result>
>             </step>
>             <step>
>                 <parameter name="description" value="Check login status code 
> equals 401"/>
>                 <parameter name="taskName" value="verifyXPath"/>
>                 <parameter name="xpath" value="//@statusCode='401'"/>
>                 <result>
>                     <notexecuted duration="0"/>
>                 </result>
>             </step>
>             <failure
>                 
> filename="/home/default/CanooWebTest/Home/SLAT_Tests/tests/Login_Logout/loginInvalidUser.xml"
>                 line="12" message="HTTP error 401"/>
>         </results>
>     </testresult>
> </summary>
> ---------------------------------------------
> 
> What do I need to do to get the test to proceed to the "notexecuted" section 
> where I can make the check for the 401 statusCode?
> 
> Thanks,
> Doug
> 
> ----------------------------------------------------------------------
> NOTICE: This email message is for the sole use of the intended recipient(s) 
> and may contain confidential and privileged information. Any unauthorized 
> review, use, disclosure or distribution is prohibited. If you are not the 
> intended recipient, please contact the sender by reply email and destroy all 
> copies of the original message.
> _______________________________________________
> WebTest mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/webtest
> 

_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest

Reply via email to