Test Jifty with Selenium, on different browsers.作者：gugod 發佈於： ，更新於：
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):
- Install Java Runtime
- Download Selenium-RC
- Download Putty, the greatest windows SSH client with worst user experiences. No offense, but I really have to complain that it’s setting screen works against my intuition.
- Run the selenium-server.jar in the downloaded selenium-rc with this (do this in your CMD window):
java -jar selenium-server.jar
- Use putty to connect to one of your server where Jifty are all setup. Let’s say it’s example.com. Also open a tunnel to forward port 4444 on remote to port 4444 on localhost.
- Note: With UNIX commands it’s this:
ssh -R4444:localhost:4444 example.com
- Putty users can see the screenshot down below to find where to open that tunnel
Setup these environment variables on your remote host, they’ll be recognized by
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 rechable from each other. VPN should be OK. 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 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