Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2008

Tip: Looking for answers? Try searching our database.

java.awt.Robot for popup windows

Thread view: 
Alex.From.Ohio.Java@gmail.com - 13 Mar 2008 21:36 GMT
I'm trying to use Robot to automate some work. So far it's fine except
sometimes JOptionPane produces popup window and Robot doesn't know
about it (as well as of possible new buttons on this window). Is there
way to recognize such dynamically created windows (on focus) and
buttons on them for the Robot?
Thanks in advance.
Alex.
http://www.myjavaserver.com/~alexfromohio/
Andrew Thompson - 14 Mar 2008 00:35 GMT
On Mar 14, 7:36 am, Alex.From.Ohio.J...@gmail.com wrote:
> I'm trying to use Robot to automate some work.

What work?

>..So far it's fine except
> sometimes JOptionPane

What JOptionPane?  Is this something in code that
is directly controlled by you, or do you just have
a binary?

>...produces popup window and Robot doesn't know
> about it (as well as of possible new buttons on this window). Is there
> way to recognize such dynamically created windows (on focus) and
> buttons on them for the Robot?

Failing direct access to the code, one way to
recognise changes in the GUI is to take occasional
screenshots and compare them.  There are almost
certainly better ways to approach this if you
also control the code that is the subject of the
screenshot.

--
Andrew T.
PhySci.org
Alex.From.Ohio.Java@gmail.com - 14 Mar 2008 03:52 GMT
> On Mar 14, 7:36 am, Alex.From.Ohio.J...@gmail.com wrote:
Thanks, Andrew.
> > I'm trying to use Robot to automate some work.
> What work?
Does it matter? It's definitely not military ;)

> >..So far it's fine except sometimes JOptionPane
> What JOptionPane?  Is this something in code that
> is directly controlled by you, or do you just have
> a binary?
By binary you mean jar file? ;) Which I can decompile and have source?
Of course I can do this but I don't need it because it's my program
and I have source.
But what makes you think that if I have code I can do whatever I want
with it? Of course I can do whatever I want but does it have sense?
Program will be overcomplicated if I add too many controls inside.
Like don't popup confirmation window if it's in test mode or something
like this. Or eliminate GUI or make it work with DSL and use this DSL
directly fr tests. I can do all this and this beauty of Java.

It's also beauty that I can eliminate all this crap and try to
interact with program by Robot and program (actually, class/object)
doesn't even know about it.

Let's say I wrote a game and want to test it for different tactics. If
I include these logics inside game it would be fine. But how can I
test random behavior of user or some mistakes like pushing wrong
button? Should I enter the code for each button - click it by mistake?

With Robot it's easy. It can collect all buttons and then "click" then
based on tactics. Program doesn't know who drives the game. It just
answers the clicks.
But what to do when unexpected occurs like exception is shown in
JOptionPane and who knows when and why it could be.

That was the question.
Looks there is no simple answer like get Container on focus and work
with it... Getting the picture and recognize that it has some
JOptionPane and what button to click looks more like AI and is not
good for any Robot ;(

Sincerely, Alex.
http://www.myjavaserver.com/~alexfromohio/
Andrew Thompson - 14 Mar 2008 04:17 GMT
On Mar 14, 1:52 pm, Alex.From.Ohio.J...@gmail.com wrote:
> Thanks, Andrew.
> > > I'm trying to use Robot to automate some work.
> > What work?
>
> Does it matter?

Only as much as a solution matters.  It is often
the case that people ask how to implement a strategy,
while forgetting the *goal*.  There might be far
better strategies to achieve the goal.

And it seems you have given far more info. on the
goal below.  So continuing..

>..It's definitely not military ;)

<mock scold>
Naughty you.  Don't be cheeky.
</mock scold>

Good to see you have been reading the group.  :-)

(reconsiders) Actually I wrote the above statements
on the presumption you had seen a recent thread on
c.l.j.programmer in which 'military use of software'
became the bulk of the thread.  If it was simply a
huge coincidence you chose to say that, my initial
statement would be less humorous.  :-(

> > >..So far it's fine except sometimes JOptionPane
> > What JOptionPane?  Is this something in code that
[quoted text clipped - 7 lines]
> with it? Of course I can do whatever I want but does it have sense?
> Program will be overcomplicated if I add too many controls inside.

O..K.  But the thing is, the overall combined system
of the application + the screenshot aspect might end
up more complex than altering the code of the original
program.

For example, in code that I control, I can get
screenshots without invoking the Robot (a
sledgehammer to crack a nut), and even do it
while the app. is sandboxed.

Further, the app. itself can far more easily
monitor the state of its GUI, and capture
screenshots as and when appropriate.

> Like don't popup confirmation window if it's in test mode or something
> like this.

Huhh?  I'm afraid you lost me there.

>..Or eliminate GUI or make it work with DSL and use this DSL
> directly fr tests. I can do all this and this beauty of Java.
>
> It's also beauty that I can eliminate all this crap and try to
> interact with program by Robot and program (actually, class/object)
> doesn't even know about it.

I'm afraid I missed whatever your point was,
especially when you mention DSL.

> Let's say I wrote a game and want to test it for different tactics. If
> I include these logics inside game it would be fine. But how can I
> test random behavior of user or some mistakes like pushing wrong
> button? Should I enter the code for each button - click it by mistake?

JUnit is specialised for testing GUI's.

It also uses the Robot (I expect), but that is
probably one use of the Robot that would be
justified.

> With Robot it's easy.

With JUnit it would be even easier.  Are you
familiar with it?

--
Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.