• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    JavaScript
  • Created over 16 years ago
  • Updated over 14 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The "official" Selenium On Rails repository, synced with OpenQA.

Welcome to the Selenium on Rails README. Exciting isn't it?

Selenium on Rails

Overview

Selenium on Rails provides an easy way to test Rails application with SeleniumCore[http://www.openqa.org/selenium-core/].

This plugin does four things:

  1. The Selenium Core files don't have to pollute /public.
  2. No need to create suite files, they are generated on the fly -- one suite per directory in /test/selenium (suites can be nested).
  3. Instead of writing the test cases in HTML you can use a number of better formats (see Formats).
  4. Loading of fixtures and wiping of session (/selenium/setup).

Installation

Rails periodically changes the way that it renders pages, which unfortunately breaks backwards versions of Selenium on Rails. Therefore there are different installation locations depending on your version of Rails:

Rails 2.2 and up:

http://svn.openqa.org/svn/selenium-on-rails/stable/selenium-on-rails

Rails 2.1:

http://svn.openqa.org/svn/selenium-on-rails/tags/rails_2_1/selenium-on-rails

Before Rails 2.1:

http://svn.openqa.org/svn/selenium-on-rails/tags/pre-rails-2-1/selenium-on-rails

The latest release is always kept on GitHub at

git clone git://github.com/paytonrules/selenium-on-rails.git

To install:

  1. Install Selenium on Rails: script/plugin install
  2. If you‘re on Windows, gem install win32-open3
  3. If the RedCloth gem is available the Selenese test cases can use it for better markup.
  4. 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.)
  5. Create a test case: script/generate selenium
  6. Start the server: script/server -e test
  7. Point your browser to localhost:3000/selenium
  8. 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.

Formats

The test cases can be written in a number of formats. Which one you choose is a matter of taste. You can generate your test files by running script/generate selenium or by creating them manually in your /test/selenium directory.

RSelenese, .rsel

RSelenese lets you write your tests in Ruby. This is my favorite format.

setup :fixtures => :all
open '/'
assert_title 'Home'
('a'..'z').each {|c| open :controller => 'user', :action => 'create', :name => c }

See SeleniumOnRails::TestBuilder for available commands. IMPORTANT NOTE: RSelenese generates the HTML tables for Selenium behind the scenes when the page is loaded - ONCE. That means code like this:

(1..10).each do |index|
	do something
end

Will only be executed when the test is loaded, not when the test is run. This is a common error and leads to tests that work the first time and fail the second time.

Selenese, .sel

Selenese is the dumbest format (in a good way). You just write your commands delimited by | characters.

|open|/selenium/setup|
|open|/|
|goBack|

If you don‘t want to write Selenese tests by hand you can use SeleniumIDE which has support for Selenese.

HTML/RHTML

You can write your tests in HTML/RHTML but that‘s mostly useful if you have existing tests you want to reuse.

Partial test cases

If you have some common actions you want to do in several test cases you can put them in a separate partial test case and include them in your other test cases. This is highly recommended, just as small functions would be recommended in structured programming.

A partial test case is just like a normal test case besides that its filename has to start with _:

#_login.rsel
open '/login'
type 'name', name
type 'password', password
click 'submit', :wait=>true

To include a partial test case in a RSelenese test case:

include_partial 'login', :name => 'Jane Doe', :password => 'Jane Doe'.reverse

in a Selenese test case:

|includePartial|login|name=John Doe|password=eoD nhoJ|

and in a RHTML test case:

<%= render :partial => 'login', :locals => {:name = 'Joe Schmo', :password => 'Joe Schmo'.reverse} %>

Configuration

There are a number of settings available. You make them by renaming selenium.yml.example to selenium.yml and placing it in your rails app's config file. Make your changes in that file.

Environments

Per default this plugin is only available in test environment. You can change this by setting environments, such as:

#selenium.yml
environments:
	- test
	- development

Selenium Core path

If you don‘t want to use the bundled Selenium Core version you can set selenium_path to the directory where Selenium Core is stored.

#config.yml
selenium_path: 'c:\selenium'

Rake Task

You can run all your Selenium tests as a Rake task. If you're using a continuous builder this is a great way to integrate selenium into your build process. First, if you‘re on Windows, you have to make sure win32-open3 is installed. Then you have to configure which browsers you want to run, like this:

#config.yml
browsers:
	firefox: 'c:\Program Files\Mozilla Firefox\firefox.exe'
	ie: 'c:\Program Files\Internet Explorer\iexplore.exe'

Now you‘re all set. First start a server:

script/server -e test

Then run the tests:

rake test:acceptance

Now it should work, otherwise let me know!

Store results

If you want to store the results from a test:acceptance you just need to set in which directory they should be stored:

#config.yml
result_dir: 'c:\result'

So when you run rake test:acceptance the tables with the results will be stored as .html files in that directory.

user_extension.js

Selenium has support for user_extension.js which is a way to extend the functionality of Selenium Core. Selenium on Rails now provides the means for you to extend it's functionality to match.

To get you started, we've included the example files lib/test_builder_user_accessors.rb.example and lib/test_builder_user_actions.rb.example that replicate the sample extensions in Selenium Core's user-extensions.js.sample.

To get these examples running, simply remove the .example and .sample extensions from the files and restart your server.

Todo

  • Standalone mode More work is needed on test:acceptance< on Windows to be able to start the server when needed.

  • Documentation update

Not todo

Contributing

Contributing is simple. Fork this repo, make your changes, then issue a pull request. IMPORTANT I will not take forks that do not have associated unit tests. There must be tests, and they must pass, so I can bring the changes in.

Credits

Information

For more information, check out the website.

More Repositories

1

typescript.koans

typescript koans, learn typescript the right way
TypeScript
35
star
2

PointerKoan

I wrote a simple pointer koan in C, to practice my pointer arithmetic. I might make it more extensive.
C
31
star
3

AirCombat

My repo for porting a Godot tutorial to rust.
Rust
24
star
4

OCDSpec

An awesome TDD framework for Objective-C
Objective-C
19
star
5

GameOfLife

A Game of Life application for iPhone to demonstrate TDD
C
12
star
6

Boberoids

A port of Asteroids in JavaScript for 8LU
JavaScript
9
star
7

learn-reactive-extensions

The exercises for my talk "Reactive Extensions without Marbles"
TypeScript
9
star
8

SimpleOpenGL-Example

Simple OpenGL Example for 8th Light U - stolen from an OReily example
C
7
star
9

iPhoneTemplates

Templates for creating UnitTesting friendly iPhone projects
C
6
star
10

clojurescript-tdd-application

This is the example tdd app for clojurescript created for a blog at 8thlight.com
Clojure
4
star
11

AgileTwitter

An iPhone Twitter Account for demonstrating TDD at Agile
Objective-C
4
star
12

PingPongScorer

A Ping Pong Scorer I'm using for an article on TDD on the iPhone
C
2
star
13

Devon-Learns-Javascript

This is a repro I'm using to teach my nephew Javascript. Probably will change a lot.
2
star
14

chiphone

The chiPhone website
JavaScript
2
star
15

Eskimo

A framework for 2D games in JavaScript with the canvas.
JavaScript
2
star
16

Capture

See me stream development of this at www.twitch.tv/paytonrules
Rust
2
star
17

vimcomfig

My vim config. If you're interested - grab it . Completely redone to use pathogen and git submodules.
Vim Script
2
star
18

clojurescript_space_invaders

An experiment in game dev, and test running that's gotten out of hand :)
Clojure
2
star
19

typescript-koans

A starting point for typescript koans. There is another repository that actually has some that work, so you probably want that one for now.
TypeScript
2
star
20

Google-Toolbox-for-Mac

This is a fork of Google Toolbox for mac - I use it for a patch and submodules.
C
2
star
21

GameOptimization

Game Optimization for class
1
star
22

ProjectEulerClojure

Clojure
1
star
23

FlashCardsiOS

My TDD'd version of Flashcards
Objective-C
1
star
24

HTML5-8LU

JavaScript
1
star
25

clojure-homework

My homework for clojure
Clojure
1
star
26

runninglog

A Running log app demonstrating some good design.
Objective-C
1
star
27

CubicleWars

Cubicle Wars - the real game
Objective-C
1
star
28

fable-space-invaders

A port of Space Invaders using FSharp and Fable
F#
1
star
29

Vim-Quicksort

I wrote quicksort, in vimscript, with specs. I'm an idiot or I rule.
Vim Script
1
star
30

TodoTDD

Sample code for the Real World Guide to TDD
JavaScript
1
star
31

photolibrary

Four Go packages that when combined make a little photolibrary I'm using on my Raspberry PI at home
Go
1
star
32

scna5k

scna5k results site
Ruby
1
star
33

HelloWorld

Hello World for 8th Light U
Objective-C
1
star
34

ContractionTimer

A timer for keeping track of contractions on the iPhone. Exercise from chiPhone.
Objective-C
1
star
35

blackjack

Rust
1
star
36

feed_the_quinn

JavaScript
1
star
37

XNANetworking

Hell - just nothing but bad luck
1
star