Re: Using captured values in beanshell scripts
Wayne Motycka <wmotycka <at> cse.unl.edu>
2012-10-10 16:05:17 GMT
Gaurav,
On the surface that sounded like the winning combination, resulting in the
expression doing something like this:
...
File ofile = new File("screen0.png");
BufferedImage bi = script.getProperty("screenBuf");
try
{
ImageIO.write(bi, "png", ofile);
} catch (IOException e) {
...
Which did create a file, containing a png image, but alas is not the
screen that is being displayed on this phone emulator's display (it's an
empty png of the correct size of pixels however.) I'm now going to make
an extension to the Step() object because that appears to be the only
mechanism that is capable of the level of abbot.robot control I need. I
didn't want a custom version of Abbot but I guess I'll be delivering
one...
Thanks for the pointer though, it did clarify how to use script variables
from sample steps within expression steps.
Best regards,
Wayne Motycka
Unless somebody else has some
On Tue, October 9, 2012 11:34 pm, Gaurav Suri wrote:
> Hello,
> Since you want to use the value of screenBuf in expression tag,
> you can use it like.... script.getProperty("screenBuf"); assign this to
> an appropriate variable and use it in the expression.
>
> Regards,
> Gaurav H.Suri
>
>
> On 10/9/12, Wayne Motycka <wmotycka <at> cse.unl.edu> wrote:
>
>> Hi,
>>
>>
>> Well, as a follow up on my previous question, how to capture screens in
>> a Abbot XML script, I've cobbled up the script (below) which uses the
>> 'sample' tag to initiate a snapshot from the
>> abbot.tester.Robot.capture() method into a sample variable I've called
>> screenBuf.
>>
>> My question is, how should I be referring to this variable within the
>> subsequent 'expression' tag/block. As I understand it, you should be
>> able to reference this variable using the ${screenBuf} syntax but
>> beanshell is bombing out with a complaint about a lexical error, the
>> text of which I've attached after the XML source (again, below.)
>>
>> Any ideas on what my beanshell syntax problem is?
>>
>>
>> Thanks!
>> Wayne Motycka
>> ------------------- Abbot XML script starts here -------------
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>>
>> <AWTTestScript>
>>
>>
>> <component class="javax.swing.JLayeredPane" id="JLayeredPane Instance"
>> index="1" parent="JRootPane Instance" window="MicroEmulator" />
>>
>> <component class="javax.swing.JPanel" hOrder="1" id="JPanel Instance"
>> index="0" parent="JLayeredPane Instance" window="MicroEmulator" />
>>
>> <component class="javax.swing.JRootPane" id="JRootPane Instance"
>> index="0" parent="MicroEmulator" />
>>
>> <component class="org.microemu.app.Main" id="MicroEmulator" root="true"
>> title="MicroEmulator" />
>>
>> <component class="org.microemu.app.ui.swing.SwingDeviceComponent"
>> id="SwingDeviceComponent Instance" index="0" parent="JPanel Instance"
>> window="MicroEmulator" />
>>
>> <component class="org.microemu.app.ui.swing.SwingDisplayComponent"
>> id="SwingDisplayComponent Instance" index="0"
>> parent="SwingDeviceComponent Instance" window="MicroEmulator" />
>>
>> <launch
>> args="[--device,org/microemu/device/default/device.xml,lancs.mobilemedia
>> .core.ui.MainUIMidlet]"
>> class="org.microemu.app.Main"
>> classpath=".:../scripts/microemu/lib/microemulator.jar:../scripts/micro
>> emu/lib/microemu-jsr-120.jar:../source/jars/MobileMedia.jar"
>> desc="org.microemu.app.Main" method="main" />
>>
>> <sample args="SwingDisplayComponent Instance"
>> class="abbot.tester.Robot" desc="screenBuf=Robot.Capture()"
>> method="capture" property="screenBuf" />
>>
>>
>> <expression desc="import java.io.File; "><![CDATA[import java.io.File;
>>
>>
>> File ofile = new File("screen0.png");
>>
>>
>> try { ImageIO.write(${screenBuf}, "png", ofile);
>> } catch (IOException e) {
>> System.err.println("failed to output component image to file");
>> }
>> return 0;]]></expression>
>>
>> <terminate />
>>
>>
>> </AWTTestScript>
>>
>>
>> ------------- Exception Error from beanshell ----------
>>
>>
>> Error: In file: inline evaluation of: ``import java.io.File File ofile
>> =
>> new File("screen0.png") try Error: Sourced file: inline evaluation of:
>> ``import java.io.File; File ofile = new File("screen0.png"); try {
>> ImageIO.w . . . '' Token Parsing Error: Lexical error at line 6, column
>> 33. Encountered: "2" (50), after : " <at> "
>> Sourced file: inline evaluation of: ``import java.io.File; File ofile =
>> new File("screen0.png"); try { ImageIO.w . . . '' Token Parsing
>> Error: Lexical error at line 6, column 33. Encountered: "2" (50),
>> after : " <at> ": <at unknown location>
>>
>>
>> at bsh.Interpreter.eval(Interpreter.java:707) at
>> bsh.Interpreter.eval(Interpreter.java:747)
>> at bsh.Interpreter.eval(Interpreter.java:736) at
>> abbot.script.Expression.runStep(Expression.java:69)
>> at abbot.script.Step.run(Step.java:92) at
>> abbot.script.StepRunner.runStep(StepRunner.java:277)
>> at abbot.script.Sequence.runStep(Sequence.java:110) at
>> abbot.script.StepRunner.runStep(StepRunner.java:274)
>> at abbot.script.StepRunner.run(StepRunner.java:194) at
>> abbot.editor.ScriptEditor$LaunchAction.run(ScriptEditor.java:2660)
>> at java.lang.Thread.run(Thread.java:662)
>>
>>
>>
>>
>> -----------------------------------------------------------------------
>> -------
>> Don't let slow site performance ruin your business. Deploy New Relic APM
>> Deploy New Relic app performance management and know exactly
>> what is happening inside your Ruby, Python, PHP, Java, and .NET app Try
>> New Relic at no cost today and get our sweet Data Nerd shirt too!
>> http://p.sf.net/sfu/newrelic-dev2dev
>> _______________________________________________
>> abbot-users mailing list abbot-users <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/abbot-users
>>
>>
>
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev