Selenium on Rails
Selenium on Rails has moved.
New version.
Updates at the end.
One of the things I like about Rails is the built-in support for testing – it’s almost hard not to write tests. But even if I write extensive tests (currently “Code to Test Ratio: 1:3.4” according to rake stats in a small toy project) I still feel that it’s not enough. I occasionally get the urge to fire up the browser and click around to test that everything works. You shouldn’t have to “click around” to test that you haven’t broken anything that often (although it’s probably good to use the browser for checking usability).
That’s where Selenium comes in. It’s a javascript based functional test tool that uses Fit like test scripts to test web application directly in the browser. There are other ways to test in browsers, like Watir, but they don’t run in any browser/platform so I think that javascript based solutions are the way to go. And for javascript based solutions I don’t know if there are any competition at all.
However, I didn’t think that vanilla Selenium worked as smooth as it should in a Rails context. So I’ve been writing a plug-in that makes the experience much better, IMHO. It took a bit longer than what I thought, but I’ve been busy and stuff like this takes time to get into a good enough state to release to the world.
Please try it out and let me know if you have any problems using it or if you have suggestions for improvements!
Overview
Selenium on Rails provides an easy way to test Rails application with Selenium.
This plugin does four things:- The Selenium files don’t have to pollute /public, they can stay in the Selenium gem or in /vendor/selenium/javascript.
- No need to create suite files, they are generated on the fly—one suite per directory in /test/selenium (suites can be nested).
- Instead of writing the test cases in HTML you can use ERb/RHTML or Selenese (a template provided by this plugin).
- Loading of fixtures and wiping of session (/selenium/setup).
Selenium on Rails is disabled for production environments.
Installation
- Selenium needs to be available. It could either be installed as a gem (gem install selenium) or in /vendor/selenium/.
- Install Selenium on Rails: script/plugin install http://andthennothing.net/svn/public/selenium_on_rails/
- If RedCloth is available the Selenese test cases can use it for better markup.
- Run the Rakefile in the plugin’s directory to run the tests in order to see that everything works. (If RedCloth isn’t installed a few tests will fail since they assume RedCloth is installed.)
- Create a test case: script/generate selenium login
- Start the server: script/server
- Point your browser to http://localhost:3000/selenium
- If everything works as expected you should see the Selenium test runner. The north east frame contains all your test cases (just one for now), and the north frame contains your test case.
Todo
user_extension.js
Selenium has support for user_extension.js which is a way to extend the functionality of Selenium. However there is currently no easy way to add such a file in Selenium on Rails.
Partials
It would be nice if common parts of test cases could be stored in partials.
More setup/teardown support?
Currently there is only support to load fixtures and to wipe the session in /selenium/setup. Is there a need for more kinds of setups or teardowns?
Credits
- Jon Tirsen—initial inspiration
Contact
Jonas Bengtsson, jonas.b@home.se, http://andthennothing.net
Update: The first defect fix is out. It should now work on EdgeRails as well as Rails 1.0.0 (might work on other versions). And the tests ought to pass on non-Windows machines. Thanks Wayne for reporting these errors!
script/plugin update (or reinstall the plugin if that doesn’t work)
Update 2: Another defect fix to make sure .files, and files~ are handled correctly, and updated the tests (they work on Windows and NetBSD at least). Thanks Wayne, Vincent and Shinya!
Update 3: New version.
Thirty-eight comments
Hello, Thanks! I've wanted to try Selenium for quite some time, now I have no excuse :-). I'm curious about the line: > Selenium on Rails is disabled for production environments. since one thing I've wanted to be able to test is caching. Now I know caching can be turned on in development, so I guess it would just be cool if it could be tested via selenium. Any ideas?
You're welcome!
It's easy to enable the plugin for production environment, just edit init.rb. But then you must make sure that the plugin isn't installed when you're putting the app into production since you almost certainly don't want to let the users run the tests.
Sorry, but I don't know if it's possible to test caching with Selenium. Let me know if you find out :-)
There is a problem running this plugin with edge rails. I get a SeleniumController not found. It seems to be related to the reloading changes that have been checked in recently. Reverting back to revision 3492 seems to work. Also, running the tests failed for me, due to newline differences. On osx/safari, I was getting "\r\n" where the text was expecting "\n". The following test helper fixed the problem (though I'm sure there's a more elegant way...): def assert_selenese_text_equal(expected, output) assert_equal expected.gsub("\n",""), output.gsub("\t", ' ').gsub("\r\n","").gsub("\n","") end
Well scratch that, it's still not working. The current test suite pane is giving a RailsError with: undefined method `test_suite_name' There seems to be some problem with the modules/includes...
Thanks for letting me know Wayne! I'll try it on edge rail and see if I get the same error.
This looks very promising. Good work!
Wayne, could you please try the new version out?
Suite, that works! (pardon the pun...) I was still getting unbalanced newlines (and 6 test failures), so I changed your clean_text method to: text.gsub("\t", ' ').gsub("\r\n", "").gsub("\n","") to just get rid of em all. Thanks for the update!
That's just awesome thanks! I gonna start using it.
I've used the generator to produce a simple test and could run the tests. However, rake test produces errors: 28 tests, 58 assertions, 6 failures, 0 errors
any idea? I am running ruby 1.8.3 on Ubuntu
I also noticed that .svn directories are listed as test suites, so I wrote a small patch to omit hidden files:
Index: vendor/plugins/selenium_on_rails/lib/selenium_on_rails/suite_renderer.rb
===================================================================
--- vendor/plugins/selenium_on_rails/lib/selenium_on_rails/suite_renderer.rb (revision 2)
+++ vendor/plugins/selenium_on_rails/lib/selenium_on_rails/suite_renderer.rb (working copy)
@@ -37,6 +37,7 @@
dirs = [] #add dirs to an array in order for files to be processed before dirs
Dir.entries(path).each do |e|
next if ['.','..'].include? e
+ next if e.starts_with? '.'
filename = File.join path, e
if File.directory? filename
dirs << [filename, "#{suite_name}#{e.humanize}."]
Very nice plugin! I'm an author of Selenium IDE which has been released recently (see http://www.openqa.org/selenium-ide/), and I've added a custom format to Wiki that can be used to edit tests for Selenium on Rails. http://wiki.openqa.org/display/SIDE/SeleniumOnRails
Comment on Vincent's patch: I also had to modify it to skip files that end with "~", which is an Emacs backup file.
I'm trying to use this (looks great), however I get errors when it tries to use element locators like "link=some link text to match" - it shows an error "Element link=some link text to match not found" Anyone else getting this?
Check the new version out and see if it addresses your issues!
Shinya: Thanks! Selenium IDE looks great! I'll try it out some time...
Joe: link=linktext doesn't work for me either, but I have no idea why. I don't understand how this could be the plugin's fault though. Let me know if you sort it out.
Jonas, thanks for the new version. It's working very well. I found that link= locator doesn't work in Selenium gem, but works if you install Selenium from svn into vendor/selenium/javascript. It seems that the gem version is too old...
What do you think about adding an option to disable Selenium in development environment?
If you don't use fixtures, enabling Selenium in development environment would be useful. But if you do use fixtures, I prefer to disable it because it will mess up the development database.
Thanks for sorting that out Shinya!
I agree that the plugin should only be available for test environment per default. It has been available for development due to convenience, but I'll change it.
Great plugin! One thought: It would be really nice to be able to use ERB from within Selenese. This way, I could look up site configuration variables and use them in test cases, eliminating some unnecessary duplication of constants.
Thanks Erik! I'll consider it, but isn't it good with duplication in this case? If the constants change for some reason, don't you want the tests to fail?
Do you have any example of what kind of constant you're talking about?
OK, I decided to actually write some code. :-) Click on my name for a patch which enhances Selenium on Rails to support native Ruby test cases, including configuration data and URL routing.
Here's a sample:
Thanks for the cool plugin, Jonas! I agree, sometimes it's good to duplicate constants. Other times, though, I just want to write:
...and not worry about updating a bunch of test cases when the site name changes. Similarly, I may not want manually update 20 test cases if I re-route some internal URLs.
My ideal goal is "Once and Only Once": each piece of knowledge should be represented in a single place, and tested in a single place. Perhaps my traditional controller tests already check that certain URLs get routed correctly, and I don't want that information to be duplicated throughout my Selenium tests.
I hope this make some kind of deranged sense, at least. ;-) In any case--on the off chance you find my patch useful--you're welcome to do anything you want with it. It's the least I can do to thank you for making my life much easier!
Nice patch Erik, good job!
I've just browsed through the code briefly, but I have one question: don't you think it's better to use method_missing where no logic is required? It would result in less code and would support user-extensions.js.
I'm currently working on rake task support, so I will look into it further when I'm done with that.
I'm glad you like it! I included rdoc and test cases and tried to stick to your style as much as possible.
And yes, method_missing would be a perfectly valid approach. I put in stubs for two reasons:
I think that (1) is useful, and (2) is probably not important. So it's up to you how it should work!
The one thing that I didn't include was easy support for loading fixtures before generating the tables. There's a really nice version of that {{here}}, but I'm not quite sure how it might work in Selenium On Rails.
Once again, my many thanks for a great plugin! It's going to make several upcoming projects much easier.
http://svn.viney.net.nz/things/rails/plugins/selenium_testing/README Do you interface with this, use this?
No, the two plugins are two different solutions to the same problem. If you want to write the tests in Ruby and use my plugin, Erik's patch above is the closest match at the moment. Have you noticed Selenium IDE? It's a neat way to author and edit Selenese test files.
Shinya: the new version is enabled for test environment only by default.
Eric: your patch is included in the new version. Thanks a bunch!
Can't wait to try this out. Thanks for fully developing it as a plugin
The SeleniumOnRails::FixtureLoader in Selenium on Rails tries to use every file under /test/fixtures when calling /selenium/setup?fixtures=all I'm using an image fixture for testing file upload, and I have image.gif in /test/fixtures. Changing the available_fixtures method seems to fix the problem: def available_fixtures files = Dir["test/fixtures/*.{yml,csv}"] files.collect {|f| f.sub(/\.[^.]*$/, '').sub('test/fixtures/', '')} end
Thank you CH! I've updated the svn repository.
I AM STUDENT RFOM IRAQ I NEED SEARCH ABOUT SELENIUM ELEMENT IF U CAN HELP ME WITH MY REGARDS ...
Hi Jonas. Where can i see the by seleniumOnRails produces HTML-Output? I have a little problem with the .rsel-tests and AJAX. After click "commit" on ajax-form, only the partial is loaded (though is correct) but the other stuff like layouts and css is gone (i see like only the partial output not the whole page). The same test runs completely correct in selenium-IDE. Thank you in advance.
Generic Viagra and Kamagra is widely used by men to treat their ED. It contains sildenafil citrate a clinically proven drug that helps men with ED in achieving erection. Bellspharmacy.com is one of the highly acclaim distributor of generic drugs. This company is known worldwide of its quality drugs and it offer generic drugs at a very low prices. Visit them online Generic Viagra | Cheap Generic Viagra | Generic Levitra | Generic Viagra | Cheap Generic Viagra | Kamagra | Cheap Generic Viagra | Finpecia | Penegra
Generic Viagra and Kamagra is widely used by men to treat their ED. It contains sildenafil citrate a clinically proven drug that helps men with ED in achieving erection. Bellspharmacy.com is one of the highly acclaim distributor of generic drugs. This company is known worldwide of its quality drugs and it offer generic drugs at a very low prices. Visit them online Generic Viagra | Cheap Generic Viagra | Generic Levitra | Generic Viagra | Cheap Generic Viagra | Kamagra | Cheap Generic Viagra | Finpecia | Penegra
Your Pandora bracelet will scream out :I am a fake watch - look at me! The genuine timepieces.Good Quality pandora beads Watches. Similarly Pandora bracelet watches and the original Pandora watches have same level of acceptance in the market. Your friends and family members can not say which one is the original one.The �gold� on a cheap Asian pandora bracelet bracelet will look cheap and shiny. Real gold is not that shiny; in fact, it can look quite dull when compared with cheap fake gold.The Swiss made Pandora bracelet watches are considered to be the best. It is so because in Switzerland bracelets are made with almost the same components as the original and moreover the same quality control measures are applied.First of all, you can find this type of watch at all 5 grades and at different prices. This gives you the opportunity to choose from a large variety of models and special features, and in the same time to take into account the budget level.Previously it was difficult to collect one brand of the Pandora watch. Both these watches used Asia Automatic Movement which you may recall is more popularly coined as 21 jewels with the term being engraved on the dial. The Explorer II vintage edition and the upgrade version had identical casings, same diameter (40mm), and similar case finish and same bracelet.The pandora charms watches are famous for its style & class, and therefore they are expensive as well. One can choose from a wide variety of models according to their personality and taste and off course budget comes first, while considering the above 2 features.With its unparallel perfection and the outstanding style, Pandora watches will always remain in fashion and also can be passed on from one generation to another. You can also find Pandora bracelet watches at online auctions that are being properly identified, and this is fine, but why take the chance of paying too much as the result of a bidding war?
This is important because if in case your watch which you have purchased from a non-authorized dealer develops a snag then the company might not honor your warranty even if your watch happens to be a genuine one. The writing on the original pandora jewelry watch and a Pandora bracelet is clearly different: the original one must be clear and with fine lines. Plus, most counterfeits use the same serial number �R863698� and if this sign appears than you were probably a victim of those impostors.You have to make your expectations level low wherever you buy a bracelet watches. These are some of the widely acclaimed and best selling models from the stables of Pandora bracelet watches. However you would find a lot of similarities between these two watches like both these watches have self-winding mechanism, rotating bezel, trip-lock system, scratch resistant synthetic sapphire crystal and similar colors. In the Rolzeium bracelets the triple wrapped platinum in the bezels is replaced by solid platinum, which makes the Swiss-made bracelet exactly like the Genuine pandora charms. They didn�t seem to mind so much when the Pandora bracelet watches didn�t really look much like a Pandora and you could easily tell the two apart, but now the good Pandora bracelet watches are fooling even jewelers because they are so much like the genuine pandora beads. Talking about its popularity mention has to be made about one of the most popular pandora beads watches of the early 1900�s. The Pandora Explorer was followed up by the Explorer II which had many features in terms of functionality and style. But Pandora bracelet watches remove all the compromises with your expectations.
För ett ting skulle en highqualityproduktnågot liknande silver earrings säljs på gatan? Den artikel med ensamrättDaytona silver earrings kopian 2007 har den glänsande rostfritt stålostronen att låsa den armband- och 40mm rostfritt stålcasingen. Lokalvård din silver sterling silver flower earrings kopia är en ritual. Ingen känd annat än den verkliga silver earrings kan användas som synonymen för förfining och överlägsenhet i klockavärlden. Det finns formligen hundratals silver earrings säljare direktanslutet, och stunder som några av dem är bemyndigade återförsäljare, några, är inte. All silver earrings reproducerade Yachtmasters har fullständigt - det funktionella skyddsramchronographsärdrag, utan det betyder inte att de ser samma. Om dig funderare som din automatiska kopiasilver earrings saktar besegrar eller rusar - upp du kan också ta den till din lokalklocka reparerar shoppar för att ha den att trimmas och tweakeds. Nästan alla av klockor för kopia för silver earrings GMT ledar- presenterar ett försilvrarostfritt stålmusikband. Det är kassaskåpet till något att säga som ostronen som den eviga silver earrings kopian luftar konung, har bestämt både bedöva och populär look, men håll värderar också jämfört till andra frodiga klockor. Men det var inte till 1949 då silver earrings kom med de första trena knäppas ut chronographen. Ha på sig en silver earrings och uppföra något liknande en behöva grabb är stinky. Klockan för den silver earrings kopiapresidenten kan vara en av de mest prestigefulla klockorna som en man kan ha på sig. Klockan för den silver earrings kopiapresidenten kan vara en stor gåva för din fader, vän, manlign basar eller någon annan man som är respekterad till dig. Klockan för den silver earrings kopiapresidenten kan ge en man den ytterlighettillfredsställelse många annan kan saker inte. Klockan för den silver earrings kopiapresidenten är en stilfull klocka. Det idérikt iscensätter av silver earrings klockor som göras det endast för man. Mest av manlooksna ilar och stilfullt genom att ha en klocka för silver earrings kopiapresident. Något av det bra återförsäljnings- uttaget ger också förslag om vilken design köparen bör välja. Planlägg som är bäst anpassat med hans personlighet.
Jurassic parkera: Leken för utforskaren DVD är en blandning av klassikern stiger Pandora bracelets leken och Pandora bracelets-leken som undervisar dig om dinosaursstunder som har en bra tid med dina ungar. Nedanför är en lista av episoder som är inklusive på jublen (säsongen 3) DVD:. Ombunden episod 45 (: Del 1) Lufta daterar: 09-27-1984.Att nedladda DVD-filmer var aldrig detta som var lätt. Har CD ROM-minnen för Pandora bracelets blivit huvudsakligen det mest använda CD drevet för skrivbords- och anteckningsbokdatorer. Cinque (Djimon Hounsou), centralteckenet av filma, lockas från säkerheten av hans afrikanska by, fångad något liknande ett wild djur och förläggas i träldom Pandora bracelets en stor slav- handelskyttel som är destinerad för det karibiskt. Kett till däcka och proppat side-by-side i skrovet av spansk gallion, hundreds och hundratals kidnappade afrikaner uthärdar brutal och barbarisk behandling.Den Pandora bracelets shipen når den politiska medborgare intresserar när överlevandearna av Amistaden behandlas som slavar. DVD9 är också bekant en dubbellagrardiskett, och dvd5 är bekant som singeln varvad diskett. Mest filmer som nuförtiden köps, är dubbeli lagert som hjälpmedlet dem har ett extra lagrar av data och kan lagra upp till 8.För en CD vi testar på åtminstone tre olika Pandora bracelets. Annorlunda du ska för att inte vara kompetent att verifiera att huruvida det kvalitets- av det solitt produceras för det bättre av det solida systemet eller av spelare. 2) För detta exempel du önskar att förbinda en brandnew HDTV, en ny Blå-stråle DVD spelare och en full surround - solitt system.
Xi'an three municipal hospitals "franchise" Xi'an Jiaotong University replica watches,Hair Do not forget to film 5 of the most sought-after hair hair membrane products recommended replica watches,Winter Food Guide: New Year, you need to get out of the health of Misunderstanding rolex watches,Health Experts: sedentary life-threatening training should be decentralized breitling watches,Zhejiang small group over their mouths to eat pecan caused by temporomandibular joint disorder tag heuer,Winter Food Guide: New Year, you need to get out of the health of Misunderstanding tag heuer carrerareplica watches,Ningxia autonomous region in January 2010 the last week of new one cases of patients with a flow of rolex watches,Focus on white-collar Office dependence syndrome breitling watches,4 large vices for Men's Health "derailed" tag heuer,Winter Food Guide: Chrysanthemum Tea injury adds to the growing immunity tag heuer carrerareplica watches,tag heuer,To five kinds of upsetting her mother-daughter-list breitling watches Students need to be careful winter high incidence of spontaneous pneumothorax Yi,rolex watches,Winter Food Guide: sooner or later, but we must guard against two anti-aging tea, not one tag heuer carrera>replica watches,Video: "Best Live" fitness experts in the heart of Zhao coup teach you to lose weight tag heuer,Winter Food Guide: Diet Tips When to drink soup slag breitling watches,rolex watches,360 weight-loss plan: Get Fit For a winter warm-up weight-loss regimen Collection tag heuer carrera Health Experts: sedentary life-threatening training should be decentralized 10.02.02T Diet weight loss corresponds to select according to personality type louis vuitton,Winter Food Guide: Seven belt "fragrant" fruit and vegetables consumption tired louis vuitton,Diet weight loss corresponds to select according to personality type gucci handbagsVideo: "Best Live" fitness experts in the heart of Zhao coup teach you to lose weight louis vuitton,Six skin aging woman's bad habits louis vuitton,The secret of a woman to be attractive gucci handbagsStudents need to be careful winter high incidence of spontaneous pneumothorax Yi louis vuitton,Winter Food Guide: a woman eating a salt-free meals on a regular basis health louis vuittonMVA-Ⅲ tubulin painless --- the third generation of flow of people settled in Shanghai City woman ,gucci handbags Lipid-lowering therapeutic side: kelp broth fungus may be lipid-lowering disease prevention 10.02.02T
It is quite common that women usually have the desire to buy new jewelries which are seemed to be better than the old ones.sohbet| Links of london sweetie bracelet Consequently,|sohbet chat|kızlarla sohbet|sohbet gold jewelries with all-round purposes and novel way of matchingdini sohbet| are fit them well.yonja| And they will always look perfectcinsel sohbet by wearing agate and tourmaline.links of london bracelet Since jewelries are believed to make the finishingrevizyon ile organize matbaacılık brnckvvtmllttrhaberi lida revizyon ile organize matbaacilik brnckvvtmllttrhaberi cinsel sohbet chat fransa sohbet lida chat siteleri islami sohbet v-pills gold fx15 lw6090 rx1 biber hapı sohbet odaları sohbet muhabbet Chat sohbet lida bu sitemizle beraber lida dizi izle forum sohbet