Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » SWTBot tests using Jython
SWTBot tests using Jython [message #633070] Fri, 15 October 2010 09:15 Go to next message
Geoff Bache is currently offline Geoff BacheFriend
Messages: 33
Registered: October 2010
Member
I'm interested in trying to write SWTBot tests in Jython to be able to interface with other Python testing utilities that we have. Does anyone know if this is possible? I see people are doing things in JRuby but couldn't find any docs or examples.

A "translation" of the tutorial test into a standalone Jython or JRuby program would be really handy here.

Regards,
Geoff Bache

P.S: Regarding my previous mail, I can confirm that it works without problems if I create a personalised installation with all the jars in the same location.
Re: SWTBot tests using Jython [message #633171 is a reply to message #633070] Fri, 15 October 2010 14:43 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Hi,

I've worked with jruby and groovy before, not jython. But here's what I
did with jruby if it helps:

* Grab SWTBot's UITestApplication from http://goo.gl/zI8Z
* Change the runTests() method to:
* initialize your embedded jython runtime
* invoke the tests by calling some form of eval() that takes in the
(p/j)ython script that can run tests

There's some cucumber on jruby code on my blog (http://goo.gl/qce1).
It's not the same interface as the UITestApplication but I'm sure you'll
manage to grab something out of it :)

Keep us posted on your experiments!

--
Ketan
ketan.padegaonkar.name | eclipse.org/swtbot | @ketanpkr

On 10/15/10 2:15 AM, Geoff Bache wrote:
> I'm interested in trying to write SWTBot tests in Jython to be able to
> interface with other Python testing utilities that we have. Does anyone
> know if this is possible? I see people are doing things in JRuby but
> couldn't find any docs or examples.
>
> A "translation" of the tutorial test into a standalone Jython or JRuby
> program would be really handy here.
>
> Regards,
> Geoff Bache
>
> P.S: Regarding my previous mail, I can confirm that it works without
> problems if I create a personalised installation with all the jars in
> the same location.
>
Re: SWTBot tests using Jython [message #633190 is a reply to message #633171] Fri, 15 October 2010 15:33 Go to previous messageGo to next message
Geoff Bache is currently offline Geoff BacheFriend
Messages: 33
Registered: October 2010
Member
Thanks for the tips.

A couple of other ideas, I found this earlier today:

http://adi.roiban.ro/2010/10/03/swtbot-jython-recipe

and was trying to do something similar, but as you can see from the comments, this was only working with basic SWT and not with RCP. Is something similar to this going to be at all possible in RCP?

Also, I wondered if it was likely to work to use the @java annotations in Jython and try to make a class file which Java could just run without needing to do anything to the Eclipse "application" mechanism. Don't know if anything similar exists for JRuby/Groovy. Any idea if that is a plausible approach?

/Geoff
Re: SWTBot tests using Jython [message #633221 is a reply to message #633190] Fri, 15 October 2010 17:44 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 10/15/10 8:33 AM, Geoff Bache wrote:
> Also, I wondered if it was likely to work to use the @java annotations
> in Jython and try to make a class file which Java could just run without
> needing to do anything to the Eclipse "application" mechanism. Don't
> know if anything similar exists for JRuby/Groovy. Any idea if that is a
> plausible approach?

JRuby[1] and groovy[2] can compile straight to java bytecode. I do not
know if that is the case with python.

However the way eclipse's test application works is by 'hooking' into
the junit runner to detect failures, errors and test passes. Groovy
makes this easy because a groovy test is a junit test, writing groovy
based SWTBot tests should probably be the easiest.

You'd most likely need to handle this yourself if you plan on using any
dynamic language, but in general its probably not worth the additional
compile step to compile the .py file into a .class file simply because
the overhead of yak-shaving eclipse builds to hook in an additional
compiler is lot higher than just asking the language runtime to load up
the scripts. The performance overhead of just in time compilation is
very negligible compared to everything else.

It's a long reply, but I hope it answers your questions.

[1] - http://kenai.com/projects/jruby/pages/GeneratingJavaClasses
[2] - http://groovy.codehaus.org/The+groovyc+Ant+Task

--
Ketan
ketan.padegaonkar.name | eclipse.org/swtbot | @ketanpkr
Re: SWTBot tests using Jython [message #633498 is a reply to message #633221] Mon, 18 October 2010 08:49 Go to previous messageGo to next message
Geoff Bache is currently offline Geoff BacheFriend
Messages: 33
Registered: October 2010
Member
Yes, Jython has a compiler too, but the docs seem to heavily discourage its use (and so do you...) so I think I won't go that way.

I did wonder if you'd tried to use javax.script.ScriptEngineManager instead of the Ruby-specific interface. Using that in the headless test runner would seem to allow the possibility to write tests in any dynamic JVM language with much less fuss, i.e. with at most an additional command line argument and possibly even by inferring which ScriptEngine to use just by looking at the extension of the file provided.

/Geoff
Re: SWTBot tests using Jython [message #633634 is a reply to message #633498] Mon, 18 October 2010 15:24 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Now that you mention it, it does seem like a cool idea :) The ability to
point a runner to a folder containing cucumber tests is something I was
trying to get to. But pointing to any source file seems exciting.

The last time I tried, the jruby ScriptEngineManager was a bit buggy
with respect to classloading and other configuration bits. I do not know
about the other implementations of the script engine manager.

Perhaps you'd like to take another stab at something jython and we could
work together to pull out something useful to put into SWTBot.

--
Ketan
ketan.padegaonkar.name | eclipse.org/swtbot | @ketanpkr

On 10/18/10 1:49 AM, Geoff Bache wrote:
> Yes, Jython has a compiler too, but the docs seem to heavily discourage
> its use (and so do you...) so I think I won't go that way.
>
> I did wonder if you'd tried to use javax.script.ScriptEngineManager
> instead of the Ruby-specific interface. Using that in the headless test
> runner would seem to allow the possibility to write tests in any dynamic
> JVM language with much less fuss, i.e. with at most an additional
> command line argument and possibly even by inferring which ScriptEngine
> to use just by looking at the extension of the file provided.
>
> /Geoff
>
Re: SWTBot tests using Jython [message #633819 is a reply to message #633634] Tue, 19 October 2010 14:10 Go to previous messageGo to next message
Geoff Bache is currently offline Geoff BacheFriend
Messages: 33
Registered: October 2010
Member
Sure. I'll do my best Smile

One more question I have: I'm struggling to understand from the examples how you ensure that SWTBot runs in a separate non-UI thread which I understood was a requirement. Where is this taken care of and do I need to worry about it?

/Geoff
Re: SWTBot tests using Jython [message #634313 is a reply to message #633819] Thu, 21 October 2010 09:10 Go to previous messageGo to next message
Geoff Bache is currently offline Geoff BacheFriend
Messages: 33
Registered: October 2010
Member
In case anyone's wondering, I've now got it working to write tests in Jython. The details are posted on the swtbot-dev list as I had to change the headless test runner to make it work.
Re: SWTBot tests using Jython [message #635545 is a reply to message #633634] Wed, 27 October 2010 10:09 Go to previous message
Geoff Bache is currently offline Geoff BacheFriend
Messages: 33
Registered: October 2010
Member
Hi again,

Ketan Padegaonkar wrote on Mon, 18 October 2010 11:24

The last time I tried, the jruby ScriptEngineManager was a bit buggy
with respect to classloading and other configuration bits. I do not know
about the other implementations of the script engine manager.
>


I can report after a while of tearing my hair out that this is also the case with the jython ScriptEngineManager. I had classloader problems all over the place, and assorted other weirdness. Today I gave up and switched to the Python-specific interface and everything just worked. Smile

It would still be possible to create something generic of course, though it would probably be a question of writing

if (extension.equals("py") {
.. do python stuff
} else if (extenstion.equals("rb") {
... do ruby stuff
}

etc.

[Updated on: Wed, 27 October 2010 10:10]

Report message to a moderator

Previous Topic:How to use latest Junit with Eclipse ganymede?
Next Topic:Alternate for sleep()
Goto Forum:
  


Current Time: Sat Apr 20 01:01:35 GMT 2024

Powered by FUDForum. Page generated in 0.03556 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top