April 2008
Monthly Archive
Selenium RC and Proxy Chaining (Double Proxies)
We had a proxy problem with Selenium RC today. The site-under-test is behind a proxy, and has the same domain name as the production site (let’s call it shop.mystore.com). Normally, developers set their proxy server in their browser, which then causes requests for shop.mystore.com to go to the proxy server which then sends the request to the developer site-under-test, instead of going to the production site.
We want to set up Selenium so the developers can created automated tests around visiting the site-under-test.
Selenium does have the ability to do a “double proxy”, using system properties:
java -Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=3128 -jar selenium-server.jar
But it turns out, unfortunately, that this doesn’t seem to work in practice. After some investigation of my own, I discovered that the proxy configuration file (proxy.pac) in Selenium is not generated properly. My own tests, and a timely visit to this discussion of the proxy chaining issue, it appears that there’s a simple workaround:
java -Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=3128 -jar selenium-server.jar -avoidProxy
Setting -avoidProxy causes the proxy configuration (proxy.pac) to work properly, sending the selenium requests to the developer site-under-test.
Agile and /Subbarao30 Apr 2008 06:55 am
The ThoughtWorks Anthology : Book Review
The ThoughtWorks Anthology by ThoughtWorks is a collection of essays which covers a broad range of problems facing IT industry and developers in particular throughout the software development life cycle. You’ll find tons of pragmatic advice to improve the efficiency of your development efforts.
In this book, you’ll find essays on varied topics like refactoring build files, testing for enterprise applications, single click software release and many more.
This book well justifies its addition to the prestigious ranks of Pragmatic Bookshelf. It is well taken and timely, some of the material covered is just mind blowing. This is the real book you need if you are using TDD or planning to, an absolute must-read on the subject.
The book is aimed at several different audiences. The book’s coverage of its subject matter is exhaustive and obviously expert.
Highly Recommended. Stay tuned for a detailed chapter wise review.
Code Coverage and /Brothers23 Apr 2008 02:43 pm
Interesting Clover Behavior - wiping out coverage database between test tasks
This was discovered with Clover 2.2.1
We have a build.xml file with the following pseudo-flow:
- clover-setup
- // this causes all future compilations to use the clover compiler to instrument the files.
- compile
- test_A
- javac _unit_test_source_ // yes, this is a subset of all source
- junit _unit_tests_
- test_B
- javac _unit_test_source_ // yes, this is a subset of all source, and redundant with test_A
- junit _integration_tests_
- clover-report
By inserting < clover-log / > at the end of test_A and test_B, I figured out what was going on.
- after test_A, we have a nice coverage level
- but at the end of test_B, we have been reset back to 0
My hypothesis is that there is a bug in Clover that causes it to:
a) wipe out all of the coverage data thus far when new code is compiled.
b) prevent new code from updating the coverage database.
And sure enough, by removing the javac compilation step from test_B, we have an accurate combined coverage report.
Moral of the story:
- Do all of your compiling before you run any of your automated tests
- < clover-log / > is your friend.
Scrum training May 5th and 6th
Jim York, a long time Stelligent friend, a Certified Scrum Trainer and lean and agile coach, is conducting a Certified ScrumMaster class May 5-6 in Vienna, VA.
Learn the essentials of working as ScrumMasters, Product Owners, and Scrum team members in this highly-interactive 2-day class. Jim creates an energized learning environment where participants engage in discussion, hands-on simulations, and role play to explore the nuances of Scrum in action. More than an intellectual exercise, Jim challenges attendees to connect Scrum practices to their underlying guiding principles. This class provides what you can’t get from a book — guided experiential learning in realistic scenarios.
Sign up today as space is limited!
Have a rip snorter of a time at CITCON Asia-Pacific!
Calling all blokes and sheilas– this year’s Asia-Pacific CITCON will be in Melbourne, Australia on June 27th & 28th– registration is now open so claim your spot before space runs out (space is limited to the first 150 tall poppies, surfies, and all around dags)!
If you dream about CI, yabber about TDD, live for BDD, or constantly think about automated deployments, then the Continuous Integration and Testing Conference is a ripper of a time, mates! The conference is free and is run as an OpenSpaces event, so there’s no reason not come. Remember, space is limited so sign up now!
Handy Dandy Hudson trick
Let’s say you have a fairly complicated build structure, with multiple batch files that fire off different aspects of the build (even if, at the end of the day, they just call ant).
And let’s assume that for various historical reasons, these batch files encapsulate their environment variables using SETLOCAL and ENDLOCAL.
At first glance, this is a pretty cool way to scope out your environment variables. But then, you find out that Hudson determines if a build has succeeded or failed by looking at the %ERRORLEVEL% environment variable. If it is not 0, the build has failed.
Uh oh. Your build is failing, but the moment ENDLOCAL is called, %ERRORLEVEL% is set back to its previous value, which, most likely, will be 0.
Given this situation, how do you get the %ERRORLEVEL% back up to Hudson? Well, don’t call ENDLOCAL. Instead use:
EXIT %ERRORLEVEL%
at the end of your batch file. This works because there’s an implicit ENDLOCAL at the end of your batch file, and EXIT will return the ERRORLEVEL as the exit value.
Quick Guide to Selenium RC
So you want to build a set of automated tests using Selenium against your webapp. I’m going to assume you have already figured out how to launch your app and set the database into a known state.
Now, you want to write some tests that mimic visiting the website and interacting with the UI in various ways.
I’ve been playing with Selenium quite a bit recently, and I’ve assembled a short list of things that will hopefully make other people’s lives easier.
Building your Tests : Navigation
- Use Selenium IDE (Firefox Plugin) to develop the navigation flow for you. The last thing you want to be doing is debugging your navigation steps in your test case so you can get to the target. With Selenium IDE, you get your app running, and record the clicks and actions you take to get to your destination.
- When you finish recording, you can export your test as a java program, or in several other languages. Take advantage of this!
- To click on a link - if you assume you have a link like: < a xhref=" Your Text Here < / a > you can get the Selenium browser object to activate the link by issuing browser.click(”Your Text Here“);
Building your Tests: Validating Results
Selenium has XPath support, and XPath is a very powerful tool for processing HTML. But the syntax of XPath is quite arcane, and I spent waaaaaay too much time trying to decipher what was wrong with my XPath query.
- Use XPath Checker (firefox plugin) - go to the results page, and control-click to bring up the XPath Checker browser. Then you can experiment with various XPath expressions until you get the one that works for your particular page and content.
- To find if text appears anywhere on the page (also known as the quick-and-dirty method) - use assertTrue(browser.isTextPresent(”Your Text Here“));
- To find if text appears in a specific sub-location, the easiest way I have found is:
- assertEquals(”Text“, browser.getText(”//table[@id=’whatever’]//tr[2]/td[1]”));
- Selenium is smart about pulling all of the text out of a set of cells, subtags, whatever, so even if that text was nested inside a div, a span and a link, it would still find it.
Running Your Tests
- You can’t use Selenium inside your tests unless the Selenium RC Server is running - launch it before you start your tests, like you would Cargo, your database, etc.
- It’s a proxy, so you have to make sure that the port you use in your code (default: 4444) is the same as the port that Selenium server is running on.
Hopefully this will help some future person get up to speed faster.
Free Webinar on Continuous Integration
Wednesday, April 16th: 3:00pm – 4:00pm ET
Are you seeking to improve the development practices of your organization? Has your team adopted a continuous integration strategy? Are you looking for the best tool to manage your builds? If so, this webinar hosted by Paul Duvall, author of the Jolt award-winning book on Continuous Integration, needs to be penciled into your calendar.
Entitled, “Continuous Integration: Improving Software Quality and Reducing Risk,” the webinar will tackle key topics and practices in the areas of continuous database integration, testing, inspection, deployment and feedback.
If you’re a lead engineer, architect, or development manager striving for greater confidence in your software product, you should tune in to find out more about how CI helps reduce key project risks such as late defect discovery, low-quality software, lack of visibility, and lack of deployable software. Additional topics on the discussion table include:
- How to use CI leveraging a combination of CI, build, test and inspection tools
- How to make integration a “non-event” on your software development projects
- How to reduce the amount of repetitive processes you perform when building your software
- Effective practices and techniques for using CI with your teams
Registration is required for this event and available at: https://www1.gotomeeting.com/register/656993026?Portal=www.gotomeeting.com
Developer Testing and /Glover and Agile02 Apr 2008 07:38 pm
Java power tools bootcamp this May
John Ferguson Smart, a long time friend of Stelligent and author of O’Reilly’s “Java Power Tools” will be holding the Java Power Tools bootcamp this May 12th through the 15th in San Francisco, CA. The timing couldn’t be better– it’s right after JavaOne! The course is 4 days of intense hands on workshops covering TDD with JUnit 4, all things Maven 2, CI with Hudson, and much, much more! For more information, visit the course website and sign up today!
Saving the day with BDD
The software development process is a big black box for basically everyone on the planet earth, except for a few, proud individuals who speak geek and wear silly tee-shirts. To everyone else who doesn’t read code or wear silly tee-shirts but work with people who do, the last bit of sanity they have is during the time they get to tell development what they want. After that, stakeholders are left praying that at the end of the developmental process, they get something out of it that works. More often than not, if that developmental process takes a long time, stakeholders don’t get want they want.

Along came iterative processes and customer involvement and things got better. A little. Stuff still broke. And developers still had horrible manners and wore silly tee-shirts. A few of them also appeared not to have learned basic hygiene.
Then came test driven development. Developers’ manners were the same and they still wore silly tee-shirts, but at least the code wasn’t as horrible. Hygienic concerns remained.
Iterative processes became more popular and the stakeholder wanted more. The stakeholder wanted visibility into that black box that those silly tee-shirt wearing developers called the “dev cycle” or the “software construction phrase” but what the normal people called “sit tight and pray a lot” time or “oh gosh, what’s this gonna cost this time?”. After all, they were paying for it and the tee-shirts those developers wore didn’t make any sense (hygienic concerns not withstanding).
Along came the gurus shouting “traceability!” which makes total sense since stakeholders are paying the bill. Emboldened, stakeholders declared:
“When a user selects 3 items, then they should receive a 10% discount.”
Heads nodded. The look of approval was unmistakable. Business was accelerating forward and everyone was happy.
Soon, stakeholders were summoned. The silly tee-shirt wearing developers proudly showed the stakeholders a test case proving the requirement was met and even tested.

The stakehoders looked puzzled. Confused even. And they weren’t trying to read those silly tee-shirts or ponder hygienic skills. Development put their finest heads together and clarified the situation with some documentation:

The stakeholders did their best to understand what they were looking at. In fact, the code even tried to convey more meaning. Yet, no matter how hard they tried, the stakeholders couldn’t speak geek. They couldn’t read the code. They couldn’t laugh at the tee-shirts. They couldn’t not brush their teeth.
Then one of the stakeholders (who used to wear silly tee-shirts) got an interesting idea– why not leverage the same language for both defining the requirements and validating them? In fact, by leveraging BDD constructs and paying attention to what was originally asked for, things can become quite easy.
This is what was originally asked for:
“When a user selects 3 items, then they should receive a 10% discount.”
The key word being should– in fact, the mechanism by which the requirement was requested sounded an awful lot like a story, which could be written like so:

Then working with a few developers (who showered that morning), the stakeholder convinced them to author the story using a BDD framework (like easyb), which yielded a file containing the requirements like so:

After the code was implemented, the stakeholder was pleased. Other stakeholders were summoned. Other developers were also summoned. Soon heads nodded. Approval was in the air. Business had been accelerated and all involved parties understood each other, for indeed, stakeholders could read what development had finally produced:

Stakeholders rejoiced! Developmental jollification ensued. Speaking geek was no longer needed. Things were written in plain English. Those silly tee-shirts still didn’t make sense, but it didn’t matter anymore– stakeholders got what they wanted. They got validation. They got assurance that indeed their requirements had coverage. They didn’t get some of the developers to shower, but they weren’t asking for miracles, just progress. The “sit tight and pray a lot” time became a collaborative effort. BDD had saved the day.