#116
Jun 30, 2008

Selenium

Selenium is a great way to test your app automatically through a browser. See how it works in this episode.
Tags: tools testing
Download (15.9 MB, 9:30)
alternative download for iPod & Apple TV (11.8 MB, 9:30)

Resources

script/plugin install git://github.com/ryanb/selenium-on-rails.git
script/generate selenium destroy_product.rsel
rake test:acceptance
# test/selenium/destroy_product.rsel
setup :fixtures => :all
product = Product.first
open '/'
click "css=#product_#{product.id} a:contains('Destroy')"
assert_confirmation('*')
wait_for_element_present "css=#flash_notice"
assert_element_not_present "css=#product_#{product.id}"
refresh
assert_element_not_present "css=#product_#{product.id}"
# config/selenium.yml
environments:
  - test

browsers:
  firefox: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
  safari: '/Applications/Safari.app/Contents/MacOS/Safari'

Full Source Code

RSS Feed for Episode Comments 35 comments

1. QuBiT Jun 30, 2008 at 00:21

Just AMAZING!

if you know java and junit inside eclipse or other testing environments from other languages you really know how useful such and IDE can be.

Selenium is really really cool.

THX Ryan for that screencast.


2. Clemens Kofler Jun 30, 2008 at 00:43

FINALLY! I've been waiting for ages to have a good screencast on Selenium. Can't wait to see this.

Cheers, Ryan!


3. Otero Jun 30, 2008 at 01:26

Nice! Running from a rake task it's very usefull!

Must try this!


4. Bryce Jun 30, 2008 at 08:14

Thanks a lot Ryan for this intro to Selenium! What a great tool to compliment the current test suite and enhance UI testing.

Do you think this will eventually replace the built in rails test suite? Will it work with autotest?

Thanks again for the great screencasts
Bryce


5. Brandon Jun 30, 2008 at 09:15

Hopefully we will see your forked changes incorporated back in to the plugin. Thanks for your work on this.


6. Ryan Bates Jun 30, 2008 at 10:06

@Bryce, Selenium is great, but I don't think it will ever replace unit or functional tests. It works very well for testing the flow between multiple pages, javascript, and making sure the full stack of your app works. I would not use it for testing complicated business logic or numerous edge cases.

AFAIK, out of the box this doesn't work with autotest, but I'm sure it's possible to hack that functionality together somehow. I haven't tried.

I personally wouldn't find autotest support very useful. To me acceptance tests are something that don't have to be run as often as unit or functional tests. However I'm still trying to figure out how best to fit Selenium into my workflow.


7. Quincy Jun 30, 2008 at 23:02

I can't install git on my laptop. It's an old Lombard with Panther 10.3. I downloaded the selenium-on-rails package from the github website, but I'm not sure how to install it. It includes one very long filename. Can anyone show me how to install it?


8. Yuchen Jul 01, 2008 at 11:56

It is indeed useful to test the flow, from functionality perspective. But most of the time we have problem with different browsers that the visual presentation of web pages differ a lot. Say it looks most of the time OK in FF, but just bad in IE. And the javascript is not surely to work on different browsers either. Can Selenium help on those issues?


9. Ryan Bates Jul 01, 2008 at 17:00

@Quincy you likely downloaded the ".tar" file. You'll need to uncompress this. Once you do you'll end up with a folder with the plugin inside. Rename the folder to 'selenium-on-rails' and move it into your vendor/plugins directory and you should be good to go.

@Yuchen testing the visual look of the page would be hard to do programatically with any tool. You may want to try scripting Selenium to take a screenshot when going to certain pages. Then you can quickly review all of these. I haven't looked into this so I'm not sure how difficult/possible it is.

As for testing Javascript, Selenium can certainly do this (as I show in the episode) and I find it to be one of the big reasons to use it.


10. jamir Jul 02, 2008 at 01:39

good one! thanks a lot>


11. t3i Jul 03, 2008 at 02:31

Very Cool.

Nice changes to the 2.1 git version.

I've watched almost all of your casts and look forward to them every week.

Thank you very much
Ben

PS i love the new intro sound, ;-)


12. Maxim Shevertalov Jul 03, 2008 at 06:10

Great screencast. I've been using Selinium for about a year now, good product and getting better all the time. About 2 weeks ago I posted a small description of how I'm testing www.graphsy.com with selenium. If anyone is interested you can check it out at:
http://www.blog.graphsy.com/?p=18
In that post I try to show how mouse events can be simulated and tested for in selenium.

Thanks for a great screencast, more people need to know about selenium.


13. Brad Jul 03, 2008 at 09:40

Another great screen cast. Keep up the nice work!


14. tesst Jul 05, 2008 at 10:09

test


15. James King Jul 05, 2008 at 14:54

Thank you Ryan!

I would be interested if anyone has any thoughts of how and when to integrate Selenium alongside a BDD workflow, especially when using Rspec and Rails.

I've been preparing to write some Rspec user stories for my app, but my first impressions of Selenium are making me think again. Selenium seems to be much quicker, more intuitive and more comprehensive by including the browser into the equation.

The only thing that's holding me back from jumping headfirst into Selenium right this minute is the fact that its geared up for testing rather than specing and I'm rather keen on the BDD conventions.


16. Maxim Shevertalov Jul 06, 2008 at 07:56

James, I think you can kind of do BDD testing with selenium, as long as you first prototype what your front end looks like. If you make the views you want to use, or at least stay consistent with you ID values of ways of referencing fields you can write selenium cases for them before actually implementing anything. Though, then you will need to write everything by hand and the Selenium IDE will not be as useful. My development process tends to be just that, first prototype the front end, then make selenium cases for it, and then hook it up to the back end. Hope that helps.


17. NO Jul 07, 2008 at 02:43

Hi

I found I always get false on assertTextPresent (assert_text_present) and verifyTextPresent (verify_text_present) with selenium_on_rails while the same test passes with Selenium-IDE.

Do you have any ideas ?

I'm trying on both the original selenium_on_rails with rails-2.0.2 and your git version with rails-2.1. But the results are same...

Anyway, this episode is great.
Thank you very much.


18. Hey Jul 07, 2008 at 08:53

Hey

/rorApp/application/vendor/rails/activesupport/lib/active_support/dependencies.rb:115:in `qualified_const_defined?': "Plugins::Selenium-on-rails::Lib" is not a valid constant name! (NameError)

Any ideas? Rails 2.1 with ryanb modified selenium plugin.


19. Hey Jul 07, 2008 at 11:58

Renamed /plugins/selenium-on-rails to selenium_on_rails and all ok :).


20. James King Jul 08, 2008 at 08:30

Maxim, Thanks for your thoughts.

Since my comment, above, I have found quite a few people who are working with both Rspec and Selenium. I did try to post a comment with links to relevant pages, but Akismet thought it was spam. If anyone is interested in working with both these tools and integrating Selenium into a BDD workflow, then just google "Rspec and Selenium" and some interesting projects come up.


21. bkola Jul 12, 2008 at 06:52

woohoo!


22. rich Jul 13, 2008 at 16:49

Have you tried Watir? I've been using that for a while now. The API is much better than Selenium. I know that Brett P. is working hard on getting Firefox(Firewatir) compatible with IE Watir Scripts.


23. Pete Jul 31, 2008 at 01:23

Hey thanks for the video Ryan. Awesome little tutorial. I had previously installed Selenium inside my Rails projects by following the writeup here:

http://siannopollo.blogspot.com/2007/02/selenium-and-ruby-they-actually-work.html

Works very well, but not quite as flexible and versatile as this method. Thanks


24. Yury Kotlyarov Aug 08, 2008 at 00:59

Hi!

Thanks for great screencast!

Any ideas how to use it to test app which serves different subdomains eg using account_location plugin?

--Yury


25. Hugo Oct 22, 2008 at 21:54

This is a really nice screencast. Testing should be pushed more and more. To many projects fail due to poor testing. Many thanks!


26. Frisee Nov 06, 2008 at 04:21

I always got a `draw_without_selenium_routes': stack level too deep (SystemStackError)
in test_environment and then it stops? Any ideas how to fix this?
-- Frisee


29. Josh Delsman Nov 25, 2008 at 08:49

It seems that this doesn't work for Rails 2.2+ yet. Eric hasn't gotten around to fixing it, either. Any ideas, Ryan?

http://clearspace.seleniumhq.org/thread/15609


30. sherlockhua Dec 01, 2008 at 18:37

<a href="http://www.3zoom.com/buy-game-card-5.html"><strong>Warhammer CD-key</strong></a> are the codes which be used to active your Warhammer Accounts.<a href="http://www.3zoom.com/uswarhammer-all/warhammer-cdkey-5-all.html"><strong>Warhamme Timecard </strong></a>then will be needed after your <strong><a href="http://www.3zoom.com/war-all/cheap-account-5-all.html">Warhammer Online Accounts</a></strong> have been activated. That means you have to use both <strong>Warhammer CD-key </strong>and <strong>Warhammer Timecard </strong>after you creat an <a href="http://www.3zoom.com/war-all/cheap-account-5-all.html"><strong>Warhammer account</strong></a>, so that you can access to the Warhammeworld.


31. sherlockhua Dec 01, 2008 at 18:38

Buy <a href=http://www.3zoom.com/buy-game-card.html>Cheap Warhammer CDkey</a> and <a href=http://www.3zoom.com/uswarhammer-all/warhammer-cdkey-5-all.html>Warhammer Prepaid Timecard</a> from us, experience our Instant delivery and Secure transaction.
<a href=http://www.3zoom.com/uswarhammer-Anlec/warhammer-gold-5-2189.html>Warhammer gold</a>, as the currency in the Warhammer world, plays an important role in the economic system. The experience plays take in game kinda depends on how much <a href=http://www.3zoom.com/euwarhammer-Alarielle/warhammer-gold-10-2156.html>Warhammer gold</a> they have.To amateur players, they do not have much time to play the game, not even farming <a href=http://www.3zoom.com/uswarhammer-Anlec/warhammer-gold-5-2189.html>Online Warhammer gold</a>. So most of Warhammer players would like to <a href=http://www.3zoom.com/>Buy Warhammer Online gold</a>. Drop by 3Zoom, and you can find <a href=http://www.3zoom.com/euwarhammer-Alarielle/warhammer-gold-10-2156.html>cheap warhammer gold</a> here.
<a href=http://www.3zoom.com/war-all/cheap-powerleveling-5-all.html>Buy Warhammer Powerlevling</a> from 3zoom, we would offer the Lowest Price, Best Service, Fastest Delivery. With the highly secured <a href=http://www.3zoom.com/euwarhammer-all/warhammer-powerleveling-10-all.html>Cheap Warhammer Power Leveling</a>, we are sure that our outstanding service would satisfy you. As well as <a href=http://www.3zoom.com/war-all/cheap-powerleveling-5-all.html>Warhammer Renown Powerleveling</a>, is available on 3Zoom now. So harmonize and delight your senses with a fast and secure <a href=http://www.3zoom.com/war-all/cheap-powerleveling-5-all.html>Renown War Leveling</a> on 3Zoom!


33. Mike Stramba Dec 07, 2008 at 04:09

Off topic, but after installing Selenium 1.0b2 from the link you provided into Firefox 3.04, I am now getting endless "spam popups". Even with Firefox's "block popups" turned on.

I'll ask around in the Firefox / Selenium/ google, but if anyone else has encountered this, or has any info I'd greatly appreciate finding out how to kill this malware.

thx

Mike


34. Anton Dec 12, 2008 at 10:43

I can't use ActiveRecord in rsel files...

Without any ActRec's like

product = Product.first

everything works fine, if I insert anything (like "Product.new()" or "Product.find(1)" or whatever (doesn't matter what class I use) I always get a

/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/module/introspection.rb:9:in `parent_name': can't modify frozen object
vendor/plugins/selenium-on-rails/lib/selenium_on_rails/rselenese.rb:29:in `render'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/module/introspection.rb:31:in `parent'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:88:in `const_missing'
(eval):9:in `render'
...


35. diablo 2 CD Key Dec 15, 2008 at 22:15

good idea.


35. Starcraft CD Keys Dec 15, 2008 at 22:15

such nice


35. blowjobs videos Dec 16, 2008 at 08:16

nice


38. bootleg movie Dec 19, 2008 at 03:45

Thanks for taking the time out for this blog post.

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player