Developing and debugging in Java via an interpreter

2 Feb

This is written from QA/automated testing perspective, but can be applied to general Java programming.

While the traditional and correct way to develop and debug in Java is using a good IDE with debugger and set breakpoints and watch variables and object references, etc., it is also useful to dynamically work and test with Java at runtime using an interpreter shell session.

You can say I got bit by the “bug” or am spoiled by such feature from Python, Ruby, etc.

I find it useful this way to test thing out quick w/o having to use full featured bloated IDE, setting breakpoints, and monitoring stuff. Just try some code, don’t work try something else from the shell.

This is particularly useful for quick test of code snippets and can be useful in QA for testing Selenium / WebDriver API calls and see if things work or not, or if you got the correct element locator or not.

With Java, you don’t really get an interpreter, but there are some options like interface to Java using Jython, JRuby, BeanShell. Don’t know all the options, but I believe BeanShell gives the closest approximation of using Java in a shell, so this article describes a bit of using it.

As an example of using Beanshell to test/debug/develop WebDriver test code, you can do the following:

Start up Beanshell with reference to Selenium library, I show Windows method, but Linux/Mac OS X method is similar:

java -cp .;selenium-server-standalone-2.15.0.jar;bsh-2.0b4.jar bsh.Console


java -cp .;selenium-server-standalone-2.15.0.jar;bsh-2.0b4.jar bsh.Interpreter

select the option you like best starting up an IDE like GUI console shell (bsh.Console) or use existing command prompt shell of your OS (bsh.Interpreter).

From there, you just use normal Java code like:

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;

WebDriver driver = new FirefoxDriver();

There may be some caveats from using interpreter shell as I’ve found for using WebDriver sendKeys() method, you have to write the command differently in the shell:

driver.findElement(“email”)).sendKeys(new String[]{“”});

see reference post here on reasoning for that:

Once you got code you like, you can then copy & paste into your real Java code in IDE to complete it and run formal test.

Happy playing with Java interpreter shell now…particularly with WebDriver and Selenium!


One Response to “Developing and debugging in Java via an interpreter”


  1. A Selenium IDE alternative for other browsers and another record & playback method « autumnator - May 3, 2012

    […] Developing and debugging in Java via an interpreter […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Der Flounder

Seldom updated, occasionally insightful.

The 4T - Trail, Tram, Trolley, Train

Exploring Portland with the 4T

Midnight Musings

Thoughts on making art

Automation Guide

The More You Learn The More You Play...!

The Performance Engineer



Thoughts related to software development

Yi Wang's Tech Notes

A blog ported from

Appium Tutorial

Technical…..Practical…..Theoretically Interesting


I swear! Meerkats can do Linux


Requeuing the packets dropped in my memory.

Two cents of software value

Writing. Training. Consulting.

@akumar overflow

wisdom exceeding 140 chars.

Lazy Programmer's Shortcut

Java, J2EE, Spring, OOAD, DDD & LIFE! .......all in one :)

Testing Mobile Apps


education and inspiration for visual storytellers

No, Seriously...

Freeing up some mind cache!

Mike Taulty

I do some developer stuff for Microsoft UK

%d bloggers like this: