Developing and debugging in Java via an interpreter shell

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!

Update 02/17/2017: Came to know about jshell in Java/JDK 9 here: jshell: The Java Shell (Read-Eval-Print Loop), so now one has another option for working with Selenium in (native) Java shell, if you use latest Java.

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


  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

Anastasia Writes

politics, engineering, parenting, relevant things over coffee.

One Software Tester

Trying To Make Sense Of The World, One Test At A Time

the morning paper

an interesting/influential/important paper from the world of CS every weekday morning, as selected by Adrian Colyer

RoboSim (Robot Simulator)

Visualize and Simulate the Robotics concepts such as Localization, Path Planning, P.I.D Controller


open notebook

a happy knockout mouse.

my journey into computer science

Perl 6 Advent Calendar

Something cool about Perl 6 every day


Inspire and spread the power of collaboration

Niraj Bhatt - Architect's Blog

Ruminations on .NET, Architecture & Design

Pete Zybrick

Bell Labs to Big Data

Seek Nuance

Python, technology, Seattle, careers, life, et cetera...


New Era of Test Automation

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

%d bloggers like this: