[Webtest] String manipulations in a Canoo script

Delphine Denis Delphine Denis <delphine.denis@travelsoft.fr>
Tue, 23 Sep 2008 12:10:10 +0200


Yes, it works! Thank you so much!
And now I know how to insert Groovy steps in my tests...
Thanks again
Delphine

Florent Blondeau a écrit :
> Bonjour Delphine,
>
> As Marc said the first time, a groovy step on your stored regexp could
> help you handle your URL (3D is the hexa code for equals sign in
> encoded url, I think)
> <groovy>
>           // not sure you need this, don't have a webtest runtime to test
>          import java.util.regex.Matcher
>                import java.util.regex.Pattern
>
>            def  props = step.webtestProperties
>            def  stored_regex = props.get('MyLink')
>            def result = (stored_regex =~ /3D/).replaceAll("")
>            println result
>
>            props.putAt("MyLink_Delphine", result)
> </groovy>
>
> And you can use the property "MyLink_Delphine" in the following steps
>
> Hope that helps
>
> A bientôt
>
> Florent
> Pingwy
> 27, rue des arènes
> 49100 Angers
>   
>
>
> Delphine Denis a écrit :
>> Hi Marc,
>> I promise I am not trying to perform a request that wouldn't exist in a
>> "normal" usage... :-)
>> Actually, I try to click a link in an email.
>> With emailMessageContentFilter I can have the content of the email, but
>> chars '3D' are inserted at the begining of each value, and I need to
>> remove them before I call the link.
>> Or may be you know something about those '3D'?
>>
>> Last week, I tried to create a script in beanshell, but I am not sure
>> about the functions I can use or not...
>> I wrote this:
>> <property name="myurl"
>> value="http://www.mjr1108.com/candidate/candidateLoginMailValidated.mj?messageParameter=-2293237856199301773819138803679945509612940613654002407700"/>
>>  <script language="beanshell">
>>       print (myurl);
>>       getChar(5, myurl);
>> </script>
>>
>> But I have an exception (at the end of this email) when I run it.
>> Thank you for your help!
>> Delphine
>>
>> C:\Canoo\MeteojobTestProject\tests\StringManip.xml:9: Unexpected exception caught: org.apache.tools.ant.BuildException
>> 	at com.canoo.webtest.steps.StepUtil.handleException(StepUtil.java:120)
>> 	at com.canoo.webtest.steps.Step.handleException(Step.java:379)
>> 	at com.canoo.webtest.steps.Step.execute(Step.java:110)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at com.canoo.webtest.ant.WebtestTask.execute(WebtestTask.java:206)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
>> 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.Main.runBuild(Main.java:698)
>> 	at org.apache.tools.ant.Main.startAnt(Main.java:199)
>> 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>> 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
>> Caused by: C:\Canoo\MeteojobTestProject\tests\StringManip.xml:11: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : Command not found: getChar( int, java.lang.String ) : at Line: 3 : in file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : getChar ( 5 , myurl ) 
>>  BSF info: ANT at line: 0 column: columnNo
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.throwBuildException(ScriptRunner.java:159)
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.executeScript(ScriptRunner.java:108)
>> 	at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at com.canoo.webtest.ant.TestStepSequence.executeSteps(TestStepSequence.java:43)
>> 	at com.canoo.webtest.ant.TestStepSequence.doExecute(TestStepSequence.java:31)
>> 	at com.canoo.webtest.steps.Step.execute(Step.java:101)
>> 	... 47 more
>> Caused by: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : Command not found: getChar( int, java.lang.String ) : at Line: 3 : in file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : getChar ( 5 , myurl ) 
>>  BSF info: ANT at line: 0 column: columnNo
>> 	at bsh.util.BeanShellBSFEngine.eval(Unknown Source)
>> 	at bsh.util.BeanShellBSFEngine.exec(Unknown Source)
>> 	at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
>> 	at java.security.AccessController.doPrivileged(Native Method)
>> 	at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.executeScript(ScriptRunner.java:103)
>> 	... 57 more
>> --- Nested Exception ---
>> C:\Canoo\MeteojobTestProject\tests\StringManip.xml:11: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : Command not found: getChar( int, java.lang.String ) : at Line: 3 : in file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : getChar ( 5 , myurl ) 
>>  BSF info: ANT at line: 0 column: columnNo
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.throwBuildException(ScriptRunner.java:159)
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.executeScript(ScriptRunner.java:108)
>> 	at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at com.canoo.webtest.ant.TestStepSequence.executeSteps(TestStepSequence.java:43)
>> 	at com.canoo.webtest.ant.TestStepSequence.doExecute(TestStepSequence.java:31)
>> 	at com.canoo.webtest.steps.Step.execute(Step.java:101)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at com.canoo.webtest.ant.WebtestTask.execute(WebtestTask.java:206)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
>> 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.Main.runBuild(Main.java:698)
>> 	at org.apache.tools.ant.Main.startAnt(Main.java:199)
>> 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>> 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
>> Caused by: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : Command not found: getChar( int, java.lang.String ) : at Line: 3 : in file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : getChar ( 5 , myurl ) 
>>  BSF info: ANT at line: 0 column: columnNo
>> 	at bsh.util.BeanShellBSFEngine.eval(Unknown Source)
>> 	at bsh.util.BeanShellBSFEngine.exec(Unknown Source)
>> 	at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
>> 	at java.security.AccessController.doPrivileged(Native Method)
>> 	at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.executeScript(ScriptRunner.java:103)
>> 	... 57 more
>> --- Nested Exception ---
>> org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : Command not found: getChar( int, java.lang.String ) : at Line: 3 : in file: inline evaluation of: ``       print (myurl); 	  getChar(5, myurl); 	  System.out.println("message is "  . . . '' : getChar ( 5 , myurl ) 
>>  BSF info: ANT at line: 0 column: columnNo
>> 	at bsh.util.BeanShellBSFEngine.eval(Unknown Source)
>> 	at bsh.util.BeanShellBSFEngine.exec(Unknown Source)
>> 	at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
>> 	at java.security.AccessController.doPrivileged(Native Method)
>> 	at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
>> 	at org.apache.tools.ant.util.optional.ScriptRunner.executeScript(ScriptRunner.java:103)
>> 	at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at com.canoo.webtest.ant.TestStepSequence.executeSteps(TestStepSequence.java:43)
>> 	at com.canoo.webtest.ant.TestStepSequence.doExecute(TestStepSequence.java:31)
>> 	at com.canoo.webtest.steps.Step.execute(Step.java:101)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at com.canoo.webtest.ant.WebtestTask.execute(WebtestTask.java:206)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
>> 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>> 	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>> 	at org.apache.tools.ant.Task.perform(Task.java:348)
>> 	at org.apache.tools.ant.Target.execute(Target.java:357)
>> 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>> 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>> 	at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
>> 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>> 	at org.apache.tools.ant.Main.runBuild(Main.java:698)
>> 	at org.apache.tools.ant.Main.startAnt(Main.java:199)
>> 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>>
>>   
>> Marc Guillemot a écrit :
>>   
>>> Hi Delphine,
>>>
>>> just for my curiosity: do you want to perform a request that wouldn't
>>> exist in a "normal" usage of your app?
>>>
>>> With a Groovy (or script) step, you can access the properties and
>>> manipulate them as you want.
>>>
>>> Cheers,
>>> Marc.
>>>   
>>>     
>>
>> _______________________________________________
>> WebTest mailing list
>> WebTest@lists.canoo.com
>> http://lists.canoo.com/mailman/listinfo/webtest
>>