We’ve recently working with Jifty team for a big internal update. Jifty team has been using Selenium as one of their testing tools, specifically, it’s Selenium-RC. In short, one current test application is first started and ask selenium server to connect to its URL and follow by a sequences of instructions to test the framework itself. Since this is a web application framework, it’s good and important to know a feature will be working on all browsers. Therefore, we need to write tests and run the tests on different browsers.
It’s simple to run those tests, just do somethingl like:
cd jifty/ prove -lr t/TestApp-*/
t/TestApp-* contains Jifty applications that are specially designed for running tests. Their sub-tests lives under
t/TestApp-*/t/. For instance, our recent work goes under
t/TestApp-JiftyJS/t/. If you run the prove command above, then you’ll see your Firefox browser pops up and start doing something. That means it’s doing it’s job just well. Of course you’ll need to install a bunches of Perl modules including
WWW::Selenium. And your OS needs to be able to run Java. I’m a Mac user, so this all works for me.
Then I need to run these tests on Windows browsers to see if they all works. What should I do ? First way, I can install whole Jifty suit on my Windows box, also install Java for running selenium-rc. Sounds simple, but it’ll take too much windows-fu from me. I might gain a lots of experiences value, but 85% of my health points will be lost. Not a good choice.
Give it a second thought, it’s mindless to prepare multiple instance of Jifty environments just to run tests on different browsers.
Here’s what I’ve done on my windows box (it’s really a virtual machine, but that makes no difference at all):
java -jar selenium-server.jar
ssh -R4444:localhost:4444 example.com
Jifty::Test::WWW::Seleniummodules to do the right thing :
export SELENIUM_RC_SERVER=localhost:4444 export SELENIUM_RC_TEST_AGAINST=example.com export SELENIUM_RC_BROWSER='*iexplore'
Now run the prove command on example.com, you should see your local Internet Explorer pops up and do something.
The concept here is to only run selenium-server on Windows, but running the Jifty test applications on somewhere else. The caveat is that these two machines need to be connected. VPN is fine. The
SELENIUM_RC_TEST_AGAINST variable is set to the remote host hostname or IP address on remote. Because it’s telling selenium server where the Jifty testing application is.
With this technique, I can use my Mac to run the selenium server, and ssh into that example.com with
ssh -R5555:localhost:4444, change
localhost:5555. Then I can test Jifty with my Mac browsers, without the need to setup another Jifty environment again.
If I’m not running my Windows in a virtual machine, but on a real machine where it has it’s own public IP, or it’s a private IP but it’s accessible from example.com. Then I don’t even need to use Putty to open up a ssh tunnel. I’ll just configure
SELENIUM_RC_SERVER to it’s IP, like
192.168.10.123:4444. And directly run the prove on example.com, it’ll just work.
PS: This post is cross-posted to Handlino Blog