Tag Archives: Java

IDEs and fancy development tools can be bad for you

23 Aug

Especially for testers (at least those without a good developer/hacker type skillset), you become reliant on them. And when you want to do something outside of them, you are lost.

I’ve seen quite a few posts from testers about how to execute Java (Selenium/TestNG) tests outside of Eclipse, and they usually have maven set up with Eclipse too.

As someone who likes to have options & builds tools & utilities from (glue) scripts and custom mini applications, whether for testing or not, it irritates me to see those questions pop up.

Either the poster is ignorant & an idiot for not knowing how to search up the solution (one search may not give you the entire solution, but search up the components that will make up your solution individually and you can piece together the puzzle to solve), or they are plain lazy to just want someone to solve it for them.

Those who work with Java toolset should know how to compile Java from scratch on command line, how to execute maven from command line, how to execute JUnit and TestNG tests from the command line test runner.

Those who work with .NET/C# should know how to compile the code from scratch on command line, how to execute NUnit/etc. tests from command line test runner, and the similar equivalents to what you do in Java.

Those who work with scripting languages should know how to run code from files on command line, run code from interpreter via command line (in GUI interpreter mode or pure command line).

Those who work with any language should know how to use libraries/packages/modules, installing, referencing them, etc. all without the fancy IDE – just command line compilation, installation, etc. Should also know how to use methods & functions of libraries/packages/modules without auto-complete in IDE, rather simply by looking up quick references and API documentation instead.

Those who work on Windows should know how to work with batch files and the Windows task scheduler. Even better to learn WSH, WMI, VBScript and/or Powershell.

Those who work on *nix should know shell scripting and cron jobs at least.


Selenium WebDriver – extracting an image on page by use of take screenshot and cropping

4 Dec

Normally, if we wanted to get an image off the web page under test, we’d download it externally using the URL extracted off the image element source attribute. Unfortunately, in today’s AJAX based web apps, that doesn’t always work. Sometimes, the elements appear like images visually to the user but are rendered by javascript into DOM elements that are not “image” elements, composed of sprites, etc. on the server side.

In such cases, you have to go an alternate route…

The technique to do it is explained here:


and an example implementation in Java here:


Side comment 1 – it would be nice if others in the community can contribute other language implementations to the Java source code example above so others can use it. Python, Ruby, C# perhaps? And a sprinkle of PHP, Perl…I may contribute code snippets when I have time.

After you’ve obtained the image, you can do whatever you want with it. Binary/MD5/SHA-1 hash compare the image against a known benchmark one?

For my case, that’s not sufficient as the image isn’t always a single image but a collection formed as one and dynamically generated. So we do some flexible fuzzy logic image comparison with our internal in house image comparison solution.

And on that topic, side comment 2:

I’ve noticed that taking screenshot then cropping to desired element location & size isn’t 100% cross platform compatible. So blogging this for reference to others and to see if anyone else have same issue. The problem here is that different browsers crop with slightly different coordinates and/or width/height ending up with cropped images that differ slightly across browsers. Now I haven’t tested across all browsers, but my findings reveal that Safari provides the most exact desired cropping, while Firefox and IE have slight variations that are not desirable. I didn’t test Chrome, nor mobile Safari with Appium.

With that in mind, you definitely can’t do hash/binary compare of the cropped images across browsers due to differences, unless you have a different benchmark image per browser. So with a single benchmark image, you’d need some flexible fuzzy logic image comparison technique. There’s multiple options here, but none readily available, other than maybe ones like Sikuli. The in house solution we use is based off ImageMagick and does the dirty work of calculating the parameters for the image comparison for you wrapped in a nice REST API.

Now anyone have experiences they can share around the topics discussed above?

Selenium file download by code and request for more platform options

23 Aug

I see in the Selenium discussion groups, the following has been a frequent topic:

How to download file with Selenium/WebDriver?

particularly a cross-browser, cross-OS solution, or when FF/Chrome profile doesn’t work for the auto download file to some location (w/o prompting) and AutoIt, etc. not perfect.

The typical suggestion is to do it via external code via HTTP libraries for your language platform. But so far, there’s only suggestion of Java:


Being an idealist, I think it would be nice if there were more options besides Java. And furthermore, could provide more library code for integrated testing to do more than just download files. I’m thinking along the lines of sharing session cookies to make HTTP POSTs and other REST API calls outside of Selenium but that require a session that is started from and available with Selenium. Think functional GUI + API testing together.

On that note at least, here’s a start for similar example to the Java one in PHP:


Now who’s with me in trying to offer more to the community than just Java (and PHP)? We should have equivalent examples in .NET, Python, Ruby, etc.

Update 4/6/2015:

Python version can be from this: https://github.com/cryzed/Selenium-Requests

and an alternate simple gist for Java: https://gist.github.com/daluu/4411221

Optimizing Selenium tests with HTTP requests

23 Aug

I found a Selenium talk by Santi from SauceLabs interesting:




and wanted to add a comment/elaborate on one of the topics.

For optimizing Selenium tests by bypassing GUI for nonessential actions (e.g. test data/state setup, etc.), you don’t necessarily need:

  • special APIs
  • hidden test pages to do the state/data setup
  • or go through the database & memcache config route

Since we’re talking about the web applications space, the first approach one should have in mind is what other methods can I test the web app with without using GUI test tools or involving a developer to provide access hooks? Or perhaps phrased differently, how else would you load/performance test the web app w/o using Selenium (Grid)?

For the latter question, ask load test pros, and they’ll probably tell you to use a tool like JMeter. Consider how to use JMeter and going back to the former question, the answer would be to use HTTP requests (normally GETs and POSTs).

And for these HTTP requests, you’re simulating a user and making the same requests but without a browser/Selenium. This also offers the benefit of test coverage closer to what Selenium gives you since all that you’re missing is rendering of the page and javascript/AJAX by a browser, but all the client-server interactions is replicated by the HTTP requests. Therefore you don’t need special (REST) APIs created or need to involve a developer (unless you lack expertise to work with HTTP requests in code). All the APIs needed are already part of the web app / website itself. You just need to find out the API (i.e. HTTP requests). How to do that?

Step 1, check if there’s existing documentation already, saves you time and serves as useful reference. If none available, goto step 2, reverse engineer the web app from the API/HTTP level. To do this, you would use tools like the network analysis feature of browser developer tools (for Chrome/Safari) like Firebug, or tools like Fiddler, Wireshark, or a web proxy that logs HTTP requests. For IE, in addition to the IE developer tools, there’s also a handy tool called ieHttpHeaders.

With these tools you spy on the network traffic that occurs whenever you perform actions like click a link/button, submit a form, login, etc. You’ll see the actual HTTP (GET or POST) requests that were made, the data that was sent along with it, any associated HTTP headers and cookies (cookies are where the session state are stored), and the response from the server.

Once you make note of the requests you need to make, the type of data to pass along, the cookies you need to create/send or extract from response, you can replicate them back using code with the HTTP libraries offered for your programming language.

In addition, this works both ways in that you could first use HTTP code to set up session cookie and make configurations then extract cookie and pass to Selenium, or you could have Selenium start some work, then extract Selenium cookie(s) and pass to HTTP code to do some other work where it’s optimal over Selenium.

It’s some amount of work to provide good code/test examples, but you can find some basic examples at least on how to extract cookie from Selenium to then pass to HTTP code (say to do a file download):

Java example for WebDriver


PHP example for Selenium RC


and last, this article I wrote a while back is also a good example and code demo of how to spy for HTTP requests from browser session then convert the traces from the manual exploration into code that makes same HTTP requests, which can be adapted for Selenium and for other languages (original is in Perl):


A Selenium IDE alternative for other browsers and another record & playback method

3 May

I see quite a few posts about Selenium IDE support for IE, etc.

While there’s no such thing and as such record & playback support, just wanted to mention an alternative:

It does require you to know Selenium RC or WebDriver API to make use of. But it also allows a form of record & playback as well.

Read my other posts for background reference:

Using Selenium with interactive interpreter shells?

Developing and debugging in Java via an interpreter

Using the interpreter shell method, you can try things out in shell (~using Selenium IDE but with RC/WebDriver commands) and when you have what you want, copy & paste to file and clean up to make into a script (Python, Ruby, Perl, PHP) or then compile code (Java, .NET/C#) (~record), and use that output to run commands again (~playback).

This method will work for whatever browser Selenium supports making it sort of an IDE that will work for the non-FF browsers.

And this method also allows you test/verify Selenium locators. You can’t find them using this method (need Firebug, or other tools for IE and other browers) but you can test them using this method to make sure locators work. And you can also run the Firebug and other plugins while using this method so combine those tools with this method and you can find and test locators at same time and know Selenium will work with them, with exception of timing problems that don’t show up under this method (compared to scripts/code).

One other benefit of this method, is it can help you find problems in other browsers like quirks for locators, windows, and other things, if you develop in the other browsers using this method rather than always starting with Firefox.

Update 1/23/2014:

Besides Selenium Builder, and my interpreter shell method above, there is a new alternative option for a Selenium IDE, see SWD Recorder, read a blog post review of it, or watch the video about it. It’s not an exact replacement but a similar one and is cross browser supported.

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(By.id(“email”)).sendKeys(new String[]{“yourusername@gmail.com”});

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.

Glass Onion Blog

Cheat sheets, post-its and random notes from the desk of a programmer

Abode QA

A Hub For Testing Minds...

The Test Therapist

Performance & Security Testing Blog


a programmer's hub

Let's Not Crash and Burn

it makes your brain tingle


“Incinerate Ignorance”

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