If I come close to be a ‘programmer’ in any language, it is in Python. Actually, I teach Jython which has all the simplicity and power of Python but lets me reuse 12 years worth of Java code when I don’t feel like re-inventing the wheel.
So, by choosing Jython I get: Python and Java in one bundle.
Part of my job is to automate testing where I think it will be of future benefit (or where it lets be be lazy at some point in the future :)). This automation often takes the form of Selenium scripts. But because I do not like working within the limitations of Selenium Core, I jump straight to Selenium Remote Control so I can make better use of oracles, logging, temp files, etc. The common paradigm for writing Selenium RC scripts is through the languages *unit framework.
So, by choosing Jython I get: Selenium scripts using Python’s unittest module and Java’s JUnit in one bundle.
Jython needs at least version 1.4 of Java in order to function, but works iwth 1.5 and 1.6. At one point I had myself convinced that I needed to run the same version of Java in my metaframework as our application was running, but I have overcome this bit of nonesense. By doing that I allowed myself to start running with 1.6 which means (a lot of things, but most importantly) I can make use of JSR-233: Scripting for the Java Platform.
JSR-233 provides hooks for (currently) 25 scripting engines to be accessed from within your native Java (Jython) code. This is incredibly trick. Want Groovy? Sure. How about Awk? It’s there too. In my context however, what I want is Ruby which I can do via JRuby.
Let’s catch up again. By choosing Jython I get: Selenium scripts using Python’s unittest module, Java’s JUnit and Ruby’s unit::test module in one bundle.
In order to get unit::test based scripts to behave, you used to have to jump through some hoops. Those hoops have in the last month been removed, so you will want to get the JSR-233 code from at least 12/12/2007. Many thanks to Yoko Harada on the JRuby mailing list for not only identifying, but providing fixes for the hiccups I experienced trying this.
Now we most certainly have Selenium scripts using Python’s unittest module, Java’s JUnit and Ruby’s unit::test module in one bundle. Which means there is now very little reason for developers to not only produce unit tests for there application / business logic, but Selenium ones for the web / presentation tier as well.
For those wanting the Jython code which will initialize and execute a JRuby script, here it is.
import javax.script.ScriptContext import javax.script.ScriptEngine import javax.script.ScriptEngineManager import javax.script.ScriptException m = javax.script.ScriptEngineManager() r = m.getEngineByName("jruby") rs = open("c:\\\\temp\\\\my_selenium_file.rb", "r") y = r.eval(rs.read()) rs.close()
This is of course, a very simple example, but it works. Oh the power of the letter J. Python code executed in a Java interpretor which then creates an instance of the Ruby interpretor and runs Selenium commands written in Ruby.
Update 12/13/2007: Ruby unit::test scripts should just work with the current jsr-233 code