Removed superfluous 'tracks' directory at the root of the repository.

Testing commits to github.
This commit is contained in:
bsag 2008-05-20 21:28:26 +01:00
parent 6a42901514
commit 4cbf5a34d3
2269 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,147 @@
require File.dirname(__FILE__) + '/test_helper'
class RendererTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller.layout_override =<<END
<html><head><title>test layout</title></head><body>
@content_for_layout
</body></html>
END
end
def test_route
get :test_file, :testname => 'html.html' #initialize the controller
assert_equal 'http://test.host/selenium/tests/suite/test_case.sel',
@controller.url_for(:controller => 'selenium', :action => 'test_file', :testname => 'suite/test_case.sel')
end
def test_html
get :test_file, :testname => 'html.html'
assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<p>Testing plain HTML</p>
<table>
<tr><th colspan="3">Test HTML</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td>&nbsp;</td></tr>
</table>
<p>and it works...</p>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_rhtml
get :test_file, :testname => 'rhtml.rhtml'
assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<table>
<tr><th colspan="3">Rhtml</th></tr>
<tr><td>open</td><td>/fi</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/fo</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/fum</td><td>&nbsp;</td></tr>
<tr><td>assertTitle</td><td>Partial from RHTML</td><td>&nbsp;</td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_selenese
get :test_file, :testname => 'selenese.sel'
assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<p>Selenese <strong>support</strong></p>
<table>
<tr><th colspan="3">Selenese</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td>&nbsp;</td></tr>
<tr><td>goBack</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>assertTitle</td><td>Partial from Selenese</td><td>&nbsp;</td></tr>
</table>
<p>works.</p>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_rselenese
get :test_file, :testname => 'rselenese.rsel'
assert_headers
expected = <<END
<html><head><title>test layout</title></head><body>
<table>
<tr><th colspan="3">Rselenese</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/selenium/setup?keep_session=true</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/selenium/setup?fixtures=all</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/selenium/setup?fixtures=foo%2Cbar</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/selenium/setup?fixtures=all&amp;amp;clear_tables=foo%2Cbar</td><td>&nbsp;</td></tr>
<tr><td>assertAbsoluteLocation</td><td>exact:http://test.host/selenium/setup</td><td>&nbsp;</td></tr>
<tr><td>assertTitle</td><td>selenium</td><td>&nbsp;</td></tr>
<tr><td>assertTitle</td><td>Partial from RSelenese</td><td>&nbsp;</td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_partial_support
get :test_file, :testname => 'partials/all_partials.rsel'
assert_headers
expected = <<END
<html><head><title>test layout</title></head><body>
<table>
<tr><th colspan="3">All partials</th></tr>
<tr><td>assertTitle</td><td>Partial from All partials</td><td>&nbsp;</td></tr>
<tr><td>type</td><td>partial</td><td>HTML partial</td></tr>
<tr><td>type</td><td>world</td><td>RHTML partial</td></tr>
<tr><td>type</td><td>partial</td><td>Selenese partial</td></tr>
<tr><td>type</td><td>world</td><td>RSelenese partial</td></tr>
<tr><td>type</td><td>nesting</td><td>Nesting partial</td></tr>
<tr><td>type</td><td>dlrow</td><td>RSelenese partial</td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_own_layout
get :test_file, :testname => 'own_layout.html'
assert_headers
expected =<<END
<html>
<head>
<title>Test case with own layout</title>
<style type="text/css"> body { background-color: #ccc; } </style>
</head>
<body>
<table>
<tr><th colspan="3">Test own layout</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td>&nbsp;</td></tr>
</table>
</body>
</html>
END
assert_text_equal expected, @response.body
end
def test_not_found
get :test_file, :testname => 'missing'
assert_response 404
assert_equal 'Not found', @response.body
end
def assert_headers
assert_response :success
assert_equal 'no-cache', @response.headers['Cache-control']
assert_equal 'no-cache', @response.headers['Pragma']
assert_equal '-1', @response.headers['Expires']
end
end

View file

@ -0,0 +1,403 @@
require File.dirname(__FILE__) + '/test_helper'
class RSeleneseTest < Test::Unit::TestCase
include ERB::Util
def rselenese name, input, partial = nil, type = nil
view = TestView.new
view.override_partial partial, type do
view.assigns['page_title'] = name
view.render_template 'rsel', input
end
end
def assert_rselenese expected, name, input, partial = nil, type = nil
assert_text_equal(expected, rselenese(name, input, partial, type))
end
def test_empty
expected = <<END
<table>
<tr><th colspan="3">Empty</th></tr>
</table>
END
input = ''
assert_rselenese expected, 'Empty', input
end
def assert_generates_command expected, name, *args
expected = expected.map {|v| h(v) }
expected << '&nbsp;' while expected.length < 3
expected = expected.map {|v| "<td>#{v}</td>" }.join
expected_html = <<END
<table>
<tr><th colspan="3">Selenese Commands</th></tr>
<tr>#{expected}</tr>
</table>
END
args_str = args.map {|a| a.inspect }.join(',')
input = "#{name}(#{args_str})"
assert_rselenese expected_html, 'Selenese Commands', input
end
def test_element_locators
assert_generates_command %w{click aCheckbox}, :click, 'aCheckbox'
assert_generates_command %w{click document.foo}, :click, 'document.foo'
assert_generates_command %w{click //a}, :click, '//a'
end
def test_collection_arguments
assert_generates_command ['assertAllLinks', 'link1,link2,link3'], :assert_all_links, ['link1', 'link2','link3']
assert_generates_command ['assertAllLinks', 'link?,link?,link?'], :assert_all_links, 'link?,link?,link?'
end
ARG_VALUE_MAP = {
# We can't test url_for style arguments here, because we don't have
# a valid controller to interpret them. See RendererTest.
:url => '/relative/url',
:string => '1234',
:pattern => 'glob:J* Smith', # Also: many other formats.
:variable => 'varname',
:locator => 'foo',
:script => 'script',
:locator_and_attribute_name => [['foo', 'attribute'], 'foo@attribute'],
:table_locator => [['table', 2, 4], 'table.2.4'],
:coll_pattern => [[['a', "b\\", 'c,']], "a,b\\\\,c\\,"],
:event_name => 'eventName',
:keycode => 123,
:option_locator => 'label=hello',
:window_id => [[nil], 'null'],
:timeout => 123,
:log_level => :debug
}
# Call _command_ with _args_ and make sure it produces a good table.
# If the input command doesn't 'selenize' cleanly (e.g. if the input command
# is :do_foo and the expected result is +dofoo+ and not +doFoo+) +command+
# can be specified as an array (e.g. +[:input_command, 'expectedResult']).
def assert_command_works command, *args
expected_values = args.inject([]) do |c, arg|
v = ARG_VALUE_MAP[arg]
if v.is_a? Array
c << v[1]
else
c << v
end
end
input_values = args.inject([]) do |c, arg|
v = ARG_VALUE_MAP[arg]
if v.is_a? Array
c.concat v[0]
else
c << v
end
end
input_name, expected_name = (command.is_a?(Array) ? command : [command, SeleniumOnRails::TestBuilder.selenize(command.to_s)])
assert_generates_command [expected_name]+expected_values, input_name.to_s, *input_values
end
def test_action_commands
assert_command_works :click, :locator
assert_command_works :click_and_wait, :locator
assert_command_works :fire_event, :locator, :event_name
assert_command_works :fire_event_and_wait, :locator, :event_name
assert_command_works :key_press, :locator, :keycode
assert_command_works :key_press_and_wait, :locator, :keycode
assert_command_works :key_down, :locator, :keycode
assert_command_works :key_down_and_wait, :locator, :keycode
assert_command_works :key_up, :locator, :keycode
assert_command_works :key_up_and_wait, :locator, :keycode
assert_command_works :mouse_over, :locator
assert_command_works :mouse_over_and_wait, :locator
assert_command_works :mouse_down, :locator
assert_command_works :mouse_down_and_wait, :locator
assert_command_works :type, :locator, :string
assert_command_works :type_and_wait, :locator, :string
assert_command_works :check, :locator
assert_command_works :check_and_wait, :locator
assert_command_works :uncheck, :locator
assert_command_works :uncheck_and_wait, :locator
assert_command_works :select, :locator, :option_locator
assert_command_works :select_and_wait, :locator, :option_locator
assert_command_works :add_selection, :locator, :option_locator
assert_command_works :add_selection_and_wait, :locator, :option_locator
assert_command_works :remove_selection, :locator, :option_locator
assert_command_works :remove_selection_and_wait, :locator, :option_locator
assert_command_works :submit, :locator
assert_command_works :open, :url
assert_command_works :select_window, :window_id
assert_command_works [:wait_for_popup, 'waitForPopUp'], :window_id, :timeout
assert_command_works :choose_cancel_on_next_confirmation
assert_command_works :choose_cancel_on_next_confirmation_and_wait
assert_command_works :answer_on_next_prompt, :string
assert_command_works :answer_on_next_prompt_and_wait, :string
assert_command_works :go_back
assert_command_works :refresh
assert_command_works :close
assert_command_works :set_context, :string
assert_command_works :set_context, :string, :log_level
assert_command_works :wait_for_condition, :script, :timeout
assert_command_works :set_timeout, :timeout
assert_command_works :wait_for_page_to_load, :timeout
end
def test_accessor_commands
assert_command_works :store_alert_present, :variable
assert_command_works :assert_alert_present
assert_command_works :assert_alert_not_present
assert_command_works :verify_alert_present
assert_command_works :verify_alert_not_present
assert_command_works :wait_for_alert_present
assert_command_works :wait_for_alert_not_present
assert_command_works :store_prompt_present, :variable
assert_command_works :assert_prompt_present
assert_command_works :assert_prompt_not_present
assert_command_works :verify_prompt_present
assert_command_works :verify_prompt_not_present
assert_command_works :wait_for_prompt_present
assert_command_works :wait_for_prompt_not_present
assert_command_works :store_confirmation_present, :variable
assert_command_works :assert_confirmation_present
assert_command_works :assert_confirmation_not_present
assert_command_works :verify_confirmation_present
assert_command_works :verify_confirmation_not_present
assert_command_works :wait_for_confirmation_present
assert_command_works :wait_for_confirmation_not_present
assert_command_works :store_alert, :variable
assert_command_works :assert_alert, :pattern
assert_command_works :assert_not_alert, :pattern
assert_command_works :verify_alert, :pattern
assert_command_works :verify_not_alert, :pattern
assert_command_works :wait_for_alert, :pattern
assert_command_works :wait_for_not_alert, :pattern
assert_command_works :store_confirmation, :variable
assert_command_works :assert_confirmation, :pattern
assert_command_works :assert_not_confirmation, :pattern
assert_command_works :verify_confirmation, :pattern
assert_command_works :verify_not_confirmation, :pattern
assert_command_works :wait_for_confirmation, :pattern
assert_command_works :wait_for_not_confirmation, :pattern
assert_command_works :store_prompt, :variable
assert_command_works :assert_prompt, :pattern
assert_command_works :assert_not_prompt, :pattern
assert_command_works :verify_prompt, :pattern
assert_command_works :verify_not_prompt, :pattern
assert_command_works :wait_for_prompt, :pattern
assert_command_works :wait_for_not_prompt, :pattern
assert_command_works :store_absolute_location, :variable
assert_command_works :assert_absolute_location, :url
assert_command_works :assert_not_absolute_location, :url
assert_command_works :verify_absolute_location, :url
assert_command_works :verify_not_absolute_location, :url
assert_command_works :wait_for_absolute_location, :url
assert_command_works :wait_for_not_absolute_location, :url
assert_command_works :store_location, :pattern, :variable
assert_command_works :assert_location, :url
assert_command_works :assert_not_location, :url
assert_command_works :verify_location, :url
assert_command_works :verify_not_location, :url
assert_command_works :wait_for_location, :url
assert_command_works :wait_for_not_location, :url
assert_command_works :store_title, :variable
assert_command_works :assert_title, :pattern
assert_command_works :assert_not_title, :pattern
assert_command_works :verify_title, :pattern
assert_command_works :verify_not_title, :pattern
assert_command_works :wait_for_title, :pattern
assert_command_works :wait_for_not_title, :pattern
assert_command_works :store_body_text, :variable
assert_command_works :assert_body_text, :pattern
assert_command_works :assert_not_body_text, :pattern
assert_command_works :verify_body_text, :pattern
assert_command_works :verify_not_body_text, :pattern
assert_command_works :wait_for_body_text, :pattern
assert_command_works :wait_for_not_body_text, :pattern
assert_command_works :store_value, :locator, :variable
assert_command_works :assert_value, :locator, :pattern
assert_command_works :assert_not_value, :locator, :pattern
assert_command_works :verify_value, :locator, :pattern
assert_command_works :verify_not_value, :locator, :pattern
assert_command_works :wait_for_value, :locator, :pattern
assert_command_works :wait_for_not_value, :locator, :pattern
assert_command_works :store_text, :locator, :variable
assert_command_works :assert_text, :locator, :pattern
assert_command_works :assert_not_text, :locator, :pattern
assert_command_works :verify_text, :locator, :pattern
assert_command_works :verify_not_text, :locator, :pattern
assert_command_works :wait_for_text, :locator, :pattern
assert_command_works :wait_for_not_text, :locator, :pattern
assert_command_works :store_eval, :script, :variable
assert_command_works :assert_eval, :script, :pattern
assert_command_works :assert_not_eval, :script, :pattern
assert_command_works :verify_eval, :script, :pattern
assert_command_works :verify_not_eval, :script, :pattern
assert_command_works :wait_for_eval, :script, :pattern
assert_command_works :wait_for_not_eval, :script, :pattern
assert_command_works :store_checked, :locator, :variable
assert_command_works :assert_checked, :locator, :pattern
assert_command_works :assert_not_checked, :locator, :pattern
assert_command_works :verify_checked, :locator, :pattern
assert_command_works :verify_not_checked, :locator, :pattern
assert_command_works :wait_for_checked, :locator, :pattern
assert_command_works :wait_for_not_checked, :locator, :pattern
assert_command_works :store_table, :table_locator, :variable
assert_command_works :assert_table, :table_locator, :pattern
assert_command_works :assert_not_table, :table_locator, :pattern
assert_command_works :verify_table, :table_locator, :pattern
assert_command_works :verify_not_table, :table_locator, :pattern
assert_command_works :wait_for_table, :table_locator, :pattern
assert_command_works :wait_for_not_table, :table_locator, :pattern
assert_raise RuntimeError do
assert_command_works :store_selected, :locator, :option_locator, :variable
end
assert_command_works :assert_selected, :locator, :option_locator
assert_command_works :assert_not_selected, :locator, :option_locator
assert_command_works :verify_selected, :locator, :option_locator
assert_command_works :verify_not_selected, :locator, :option_locator
assert_command_works :wait_for_selected, :locator, :option_locator
assert_command_works :wait_for_not_selected, :locator, :option_locator
assert_command_works :store_selected_options, :locator, :variable
assert_command_works :assert_selected_options, :locator, :coll_pattern
assert_command_works :assert_not_selected_options, :locator, :coll_pattern
assert_command_works :verify_selected_options, :locator, :coll_pattern
assert_command_works :verify_not_selected_options, :locator, :coll_pattern
assert_command_works :wait_for_selected_options, :locator, :coll_pattern
assert_command_works :wait_for_not_selected_options, :locator, :coll_pattern
assert_command_works :store_select_options, :locator, :variable
assert_command_works :assert_select_options, :locator, :coll_pattern
assert_command_works :assert_not_select_options, :locator, :coll_pattern
assert_command_works :verify_select_options, :locator, :coll_pattern
assert_command_works :verify_not_select_options, :locator, :coll_pattern
assert_command_works :wait_for_select_options, :locator, :coll_pattern
assert_command_works :wait_for_not_select_options, :locator, :coll_pattern
assert_command_works :store_attribute, :locator_and_attribute_name, :variable
assert_command_works :assert_attribute, :locator_and_attribute_name, :pattern
assert_command_works :assert_not_attribute, :locator_and_attribute_name, :pattern
assert_command_works :verify_attribute, :locator_and_attribute_name, :pattern
assert_command_works :verify_not_attribute, :locator_and_attribute_name, :pattern
assert_command_works :wait_for_attribute, :locator_and_attribute_name, :pattern
assert_command_works :wait_for_not_attribute, :locator_and_attribute_name, :pattern
assert_command_works :store_text_present, :pattern, :variable
assert_command_works :assert_text_present, :pattern
assert_command_works :assert_text_not_present, :pattern
assert_command_works :verify_text_present, :pattern
assert_command_works :verify_text_not_present, :pattern
assert_command_works :wait_for_text_present, :pattern
assert_command_works :wait_for_text_not_present, :pattern
assert_command_works :store_element_present, :locator, :variable
assert_command_works :assert_element_present, :locator
assert_command_works :assert_element_not_present, :locator
assert_command_works :verify_element_present, :locator
assert_command_works :verify_element_not_present, :locator
assert_command_works :wait_for_element_present, :locator
assert_command_works :wait_for_element_not_present, :locator
assert_command_works :store_visible, :locator, :variable
assert_command_works :assert_visible, :locator
assert_command_works :assert_not_visible, :locator
assert_command_works :verify_visible, :locator
assert_command_works :verify_not_visible, :locator
assert_command_works :wait_for_visible, :locator
assert_command_works :wait_for_not_visible, :locator
assert_command_works :store_editable, :locator, :variable
assert_command_works :assert_editable, :locator
assert_command_works :assert_not_editable, :locator
assert_command_works :verify_editable, :locator
assert_command_works :verify_not_editable, :locator
assert_command_works :wait_for_editable, :locator
assert_command_works :wait_for_not_editable, :locator
assert_command_works :store_all_buttons, :variable
assert_command_works :assert_all_buttons, :coll_pattern
assert_command_works :assert_not_all_buttons, :coll_pattern
assert_command_works :verify_all_buttons, :coll_pattern
assert_command_works :verify_not_all_buttons, :coll_pattern
assert_command_works :wait_for_all_buttons, :coll_pattern
assert_command_works :wait_for_not_all_buttons, :coll_pattern
assert_command_works :store_all_links, :variable
assert_command_works :assert_all_links, :coll_pattern
assert_command_works :assert_not_all_links, :coll_pattern
assert_command_works :verify_all_links, :coll_pattern
assert_command_works :verify_not_all_links, :coll_pattern
assert_command_works :wait_for_all_links, :coll_pattern
assert_command_works :wait_for_not_all_links, :coll_pattern
assert_command_works :store_all_fields, :variable
assert_command_works :assert_all_fields, :coll_pattern
assert_command_works :assert_not_all_fields, :coll_pattern
assert_command_works :verify_all_fields, :coll_pattern
assert_command_works :verify_not_all_fields, :coll_pattern
assert_command_works :wait_for_all_fields, :coll_pattern
assert_command_works :wait_for_not_all_fields, :coll_pattern
assert_command_works :store_html_source, :variable
assert_command_works :assert_html_source, :pattern
assert_command_works :assert_not_html_source, :pattern
assert_command_works :verify_html_source, :pattern
assert_command_works :verify_not_html_source, :pattern
assert_command_works :wait_for_html_source, :pattern
assert_command_works :wait_for_not_html_source, :pattern
assert_command_works :store_expression, :script, :variable
assert_command_works :assert_expression, :script, :pattern
assert_command_works :assert_not_expression, :script, :pattern
assert_command_works :verify_expression, :script, :pattern
assert_command_works :verify_not_expression, :script, :pattern
assert_command_works :wait_for_expression, :script, :pattern
assert_command_works :wait_for_not_expression, :script, :pattern
end
def test_partial_support
expected = <<END
<table>
<tr><th colspan="3">Partial support</th></tr>
<tr><td>type</td><td>partial</td><td>RSelenese partial</td></tr>
</table>
END
input = "include_partial 'override'"
partial = "type 'partial', 'RSelenese partial'"
assert_rselenese expected, 'Partial support', input, partial, 'rsel'
end
def test_partial_support_with_local_assigns
expected = <<END_EXPECTED
<table>
<tr><th colspan="3">Partial support with local variables</th></tr>
<tr><td>type</td><td>partial</td><td>RSelenese partial</td></tr>
<tr><td>type</td><td>local</td><td>par</td></tr>
<tr><td>type</td><td>local</td><td>tial</td></tr>
</table>
END_EXPECTED
input = "include_partial 'override', :locator => 'local', :input => ['par', 'tial']"
partial = <<END_PARTIAL
type 'partial', 'RSelenese partial'
input.each do |i|
type locator, i
end
END_PARTIAL
assert_rselenese expected, 'Partial support with local variables', input, partial, 'rsel'
end
end

View file

@ -0,0 +1,229 @@
require File.dirname(__FILE__) + '/test_helper'
class SeleneseTest < Test::Unit::TestCase
def selenese name, input, partial = nil, type = nil
view = TestView.new
view.override_partial partial, type do
view.assigns['page_title'] = name
view.render_template 'sel', input
end
end
def assert_selenese expected, name, input, partial = nil, type = nil
assert_text_equal expected, selenese(name, input, partial, type)
end
def test_empty
expected = <<END
<table>
<tr><th colspan="3">Empty</th></tr>
</table>
END
input = ''
assert_selenese expected, 'Empty', ''
end
def test_one_line
expected = <<END
<table>
<tr><th colspan="3">One line</th></tr>
<tr><td>open</td><td>/</td><td>&nbsp;</td></tr>
</table>
END
input = '|open|/|'
assert_selenese expected, 'One line', input
end
def test_comments_only
expected = <<END
<p>Comment <strong>1</strong></p>
<p>Comment 2</p>
<table>
<tr><th colspan="3">Only comments</th></tr>
</table>
END
input = <<END
Comment *1*
Comment 2
END
assert_selenese expected, 'Only comments', input
end
def test_commands_only
expected = <<END
<table>
<tr><th colspan="3">Only commands</th></tr>
<tr><td>goBack</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>open</td><td>/foo</td><td>&nbsp;</td></tr>
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
</table>
END
input = <<END
|goBack |
|open| /foo |
| fireEvent | textField | focus |
END
assert_selenese expected, 'Only commands', input
end
def test_commands_and_comments
expected = <<END
<table>
<tr><th colspan="3">Commands and comments</th></tr>
<tr><td>goBack</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
</table>
<p>Comment 1</p>
<p>Comment <strong>2</strong></p>
END
input = <<END
|goBack |
| fireEvent | textField| focus|
Comment 1
Comment *2*
END
assert_selenese expected, 'Commands and comments', input
end
def test_comments_and_commands
expected = <<END
<p>Comment 1</p>
<p>Comment <strong>2</strong></p>
<table>
<tr><th colspan="3">Comments and commands</th></tr>
<tr><td>goBack</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
</table>
END
input = <<END
Comment 1
Comment *2*
|goBack |
| fireEvent | textField|focus|
END
assert_selenese expected, 'Comments and commands', input
end
def test_comments_commands_comments
expected = <<END
<p>Comment 1</p>
<p>Comment <strong>2</strong></p>
<table>
<tr><th colspan="3">Comments, commands and comments</th></tr>
<tr><td>goBack</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
</table>
<p>Comment 3</p>
END
input = <<END
Comment 1
Comment *2*
|goBack |
| fireEvent | textField| focus|
Comment 3
END
assert_selenese expected, 'Comments, commands and comments', input
end
def test_command_html_entity_escaping
expected = <<END
<table>
<tr><th colspan="3">HTML escaping</th></tr>
<tr><td>type</td><td>nameField</td><td>&lt;&gt;&amp;</td></tr>
</table>
END
input = '|type|nameField|<>&|'
assert_selenese expected, 'HTML escaping', input
end
def test_partial_support
expected = <<END
<table>
<tr><th colspan="3">Partial support</th></tr>
<tr><td>type</td><td>partial</td><td>Selenese partial</td></tr>
</table>
END
input = '|includePartial|override|'
partial = '|type|partial|Selenese partial|'
assert_selenese expected, 'Partial support', input, partial, 'sel'
end
def test_partial_support_with_local_assigns
expected = <<END_EXPECTED
<table>
<tr><th colspan="3">Partial support with local assigns</th></tr>
<tr><td>type</td><td>assigns</td><td>a=hello,b=world!,c_123ABC=</td></tr>
<tr><td>type</td><td>assigns</td><td>a=a b c d,b=,c_123ABC=hello</td></tr>
</table>
END_EXPECTED
input = <<END_INPUT
|includePartial|override|a=hello|b=world!|
|includePartial|override|a = a b c d|b=|c_123ABC= hello |
END_INPUT
partial = <<END_PARTIAL
<table><tr><th>whatever</th></tr>
<tr><td>type</td><td>assigns</td><td>
a=<%= a if defined? a%>,
b=<%= b if defined? b%>,
c_123ABC=<%= c_123ABC if defined? c_123ABC%>
</td></tr>
</table>
END_PARTIAL
assert_selenese expected, 'Partial support with local assigns', input, partial, 'rhtml'
end
def test_raised_when_more_than_three_columns
assert_raise RuntimeError, 'There might only be a maximum of three cells!' do
selenese 'name', '|col1|col2|col3|col4|'
end
end
def test_raised_when_more_than_one_set_of_commands
assert_raise RuntimeError, 'You cannot have comments in the middle of commands!' do
input = <<END
comment
|command|
comment
|command|
END
selenese 'name', input
end
end
def test_raised_when_incorrect_partial_format
assert_raise RuntimeError, "Invalid format 'invalid'. Should be '|includePartial|partial|var1=value|var2=value|." do
selenese 'name', '|includePartial|partial|a=valid|invalid|'
end
end
end

View file

@ -0,0 +1,48 @@
require File.dirname(__FILE__) + '/test_helper'
require "selenium_controller"
class SeleniumControllerTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@result_dir = File.join(File.dirname(__FILE__), "..", "test_result")
end
def teardown
FileUtils.rm_rf @result_dir
end
def test_record_with_result
SeleniumOnRailsConfig.configs["result_dir"] = @result_dir
suite = <<EOS
<script>
</script>
<table>
<tr><td bgcolor="#ccffcc"><a href="/selenium/tests/foo.sel">Foo</a></td></tr>
<tr><td bgcolor="#ccffcc"><a href="/selenium/tests/bar.sel">Bar</a></td></tr>
</table>
EOS
post :record, :suite => suite,
"testTable.1" => "<table></table>",
"testTable.2" => "<table></table>"
cur_result_dir = File.join(@result_dir, "default")
assert File.directory?(cur_result_dir)
assert_equal ["blank.html", "index.html", "suite.html", "test1.html", "test2.html"],
Dir.glob("#{cur_result_dir}/*.html").map{|path| File.basename(path)}.sort
expected = <<EOS
<html>
<head>
<link rel="stylesheet" type="text/css" href="selenium-test.css">
</head>
<body>
<table>
<tr><td bgcolor="#ccffcc"><a href="test1.html" target="testcase">Foo</a></td></tr>
<tr><td bgcolor="#ccffcc"><a href="test2.html" target="testcase">Bar</a></td></tr>
</table>
</body></html>
EOS
assert_equal expected, File.read("#{cur_result_dir}/suite.html")
end
end

View file

@ -0,0 +1,33 @@
require File.dirname(__FILE__) + '/test_helper'
class SeleniumSupportTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_route
get :support_file, :filename => 'TestRunner.html' #initialize the controller
assert_equal 'http://test.host/selenium/TestRunner.html',
@controller.url_for(:controller => 'selenium', :action => 'support_file', :filename => 'TestRunner.html')
end
def test_test_runner_existance
get :support_file, :filename => 'TestRunner.html'
assert_response :success
assert @response.body.include?('Selenium')
end
def test_default_file
get :support_file, :filename => ''
assert_redirected_to :filename => 'TestRunner.html', :test => 'tests'
end
def test_missing_file
get :support_file, :filename => 'missing.html'
assert_response 404
assert_equal 'Not found', @response.body
end
end

View file

@ -0,0 +1,29 @@
require File.dirname(__FILE__) + '/test_helper'
class SetupTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_session_reset
@request.session['key'] = 'value'
get :setup
assert_nil session['key']
assert_response :success
assert_tag :content => 'The session is wiped clean.'
end
def test_session_no_reset
@request.session['key'] = 'value'
get :setup, :keep_session => true
assert_equal 'value', session['key']
assert_response :success
assert_no_tag :content => 'The session is wiped clean.'
end
#
# Don't have the nerve to test fixtures since this is a plugin
#
end

View file

@ -0,0 +1,173 @@
require File.dirname(__FILE__) + '/test_helper'
class SuiteRendererTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller.layout_override =<<END
<html><head><title>test layout</title></head><body>
@content_for_layout
</body></html>
END
end
def test_empty_suite
get :test_file, :testname => 'empty_suite'
assert_response :success
expected =<<END
<html><head><title>test layout</title></head><body>
<script type="text/javascript">
<!--
function openSuite(selector) {
var suite = selector.options[selector.selectedIndex].value;
if(suite == "header") return;
if(top.location.href != location.href) //inside a frame
top.location = "/selenium/TestRunner.html?test=tests" + suite
else
window.location = "/selenium/tests" + suite
}
//-->
</script>
<select onchange="openSuite(this)">
<option value="header">Suites:</option>
<option value="">..</option>
</select>
<table>
<tr><th>Empty suite</th></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_root_suite
_test_root_suite ''
end
def test_test_suite_html
#TestSuite.html is the default name the Selenium Runner tries to run
_test_root_suite 'TestSuite.html'
end
def _test_root_suite testname
get :test_file, :testname => testname
assert_response :success
expected =<<END
<html><head><title>test layout</title></head><body>
<script type="text/javascript">
<!--
function openSuite(selector) {
var suite = selector.options[selector.selectedIndex].value;
if(suite == "header") return;
if(top.location.href != location.href) //inside a frame
top.location = "/selenium/TestRunner.html?test=tests" + suite
else
window.location = "/selenium/tests" + suite
}
//-->
</script>
<select onchange="openSuite(this)">
<option value="header">Suites:</option>
<option value="/empty_suite">Empty suite</option>
<option value="/partials">Partials</option>
<option value="/suite_one">Suite one</option>
<option value="/suite_two">Suite two</option>
<option value="/suite_one/subsuite">Suite one.Subsuite</option>
</select>
<table>
<tr><th>All test cases</th></tr>
<tr><td><a href="/selenium/tests/html.html">Html</a></td></tr>
<tr><td><a href="/selenium/tests/own_layout.html">Own layout</a></td></tr>
<tr><td><a href="/selenium/tests/rhtml.rhtml">Rhtml</a></td></tr>
<tr><td><a href="/selenium/tests/rselenese.rsel">Rselenese</a></td></tr>
<tr><td><a href="/selenium/tests/selenese.sel">Selenese</a></td></tr>
<tr><td><a href="/selenium/tests/partials/all_partials.rsel">Partials.All partials</a></td></tr>
<tr><td><a href="/selenium/tests/suite_one/suite_one_testcase1.sel">Suite one.Suite one testcase1</a></td></tr>
<tr><td><a href="/selenium/tests/suite_one/suite_one_testcase2.sel">Suite one.Suite one testcase2</a></td></tr>
<tr><td><a href="/selenium/tests/suite_one/subsuite/suite_one_subsuite_testcase.sel">Suite one.Subsuite.Suite one subsuite testcase</a></td></tr>
<tr><td><a href="/selenium/tests/suite_two/suite_two_testcase.sel">Suite two.Suite two testcase</a></td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_suite_one
get :test_file, :testname => 'suite_one'
assert_response :success
expected =<<END
<html><head><title>test layout</title></head><body>
<script type="text/javascript">
<!--
function openSuite(selector) {
var suite = selector.options[selector.selectedIndex].value;
if(suite == "header") return;
if(top.location.href != location.href) //inside a frame
top.location = "/selenium/TestRunner.html?test=tests" + suite
else
window.location = "/selenium/tests" + suite
}
//-->
</script>
<select onchange="openSuite(this)">
<option value="header">Suites:</option>
<option value="">..</option>
<option value="/suite_one/subsuite">Subsuite</option>
</select>
<table>
<tr><th>Suite one</th></tr>
<tr><td><a href="/selenium/tests/suite_one/suite_one_testcase1.sel">Suite one testcase1</a></td></tr>
<tr><td><a href="/selenium/tests/suite_one/suite_one_testcase2.sel">Suite one testcase2</a></td></tr>
<tr><td><a href="/selenium/tests/suite_one/subsuite/suite_one_subsuite_testcase.sel">Subsuite.Suite one subsuite testcase</a></td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_sub_suite
get :test_file, :testname => 'suite_one/subsuite'
assert_response :success
expected =<<END
<html><head><title>test layout</title></head><body>
<script type="text/javascript">
<!--
function openSuite(selector) {
var suite = selector.options[selector.selectedIndex].value;
if(suite == "header") return;
if(top.location.href != location.href) //inside a frame
top.location = "/selenium/TestRunner.html?test=tests" + suite
else
window.location = "/selenium/tests" + suite
}
//-->
</script>
<select onchange="openSuite(this)">
<option value="header">Suites:</option>
<option value="/suite_one">..</option>
</select>
<table>
<tr><th>Subsuite</th></tr>
<tr><td><a href="/selenium/tests/suite_one/subsuite/suite_one_subsuite_testcase.sel">Suite one subsuite testcase</a></td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_missing_tests_directory
def @controller.selenium_tests_path
File.join(File.dirname(__FILE__), 'invalid')
end
get :test_file, :testname => ''
assert_response 404
assert_equal "Did not find the Selenium tests path (#{File.join(File.dirname(__FILE__), 'invalid')}). Run script/generate selenium", @response.body
end
end

View file

@ -0,0 +1,70 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
require 'test_help'
require 'controllers/selenium_controller'
module SeleniumOnRails::Paths
def selenium_tests_path
File.expand_path(File.dirname(__FILE__) + '/../test_data')
end
end
class SeleniumController
attr_accessor :layout_override
# Re-raise errors caught by the controller.
def rescue_action e
raise e
end
def render options = nil, deprecated_status = nil
if override_layout? options
options[:layout] = false
super options, deprecated_status
return response.body = @layout_override.gsub('@content_for_layout', response.body)
end
super options, deprecated_status
end
private
def override_layout? options
return false unless @layout_override
if options[:action] or options[:template]
options[:layout] != false #for action and template the default layout is used if not explicitly disabled
else
not [nil, false].include? options[:layout] #otherwise a layout has to be specified
end
end
end
class Test::Unit::TestCase
def assert_text_equal expected, actual
assert_equal clean_text(expected), clean_text(actual)
end
def clean_text text
text.gsub("\t", ' ').gsub("\r", '').gsub("\n", '').gsub(/ *</, '<')
end
end
class TestView < ActionView::Base
include SeleniumOnRails::PartialsSupport
alias_method :render_partial_without_override, :render_partial
def render_partial partial_path = default_template_name, object = nil, local_assigns = nil, status = nil
if @override
partial = render :inline => @override, :type => @override_type, :locals => local_assigns
extract_commands_from_partial partial
else
render_partial_without_override partial_path, object, local_assigns, status
end
end
def override_partial partial, type
@override, @override_type = partial, type
result = yield
@override, @override_type = nil, nil
result
end
end