2009-12-14 11:51:36 -05:00
|
|
|
require File.dirname(__FILE__) + '/test_helper'
|
2007-03-30 12:34:56 +00:00
|
|
|
|
|
|
|
|
class SeleneseTest < Test::Unit::TestCase
|
2008-12-02 10:05:41 +01:00
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
@view = TestView.new
|
2009-12-14 11:51:36 -05:00
|
|
|
@view.extend(SeleniumOnRails::PathsTestHelper)
|
2008-12-02 10:05:41 +01:00
|
|
|
@sel = SeleniumOnRails::Selenese.new(@view)
|
2007-03-30 12:34:56 +00:00
|
|
|
end
|
|
|
|
|
|
2008-12-02 10:05:41 +01:00
|
|
|
def render_selenese(page_title, input)
|
|
|
|
|
create_sel_file_from(input, "html.sel")
|
|
|
|
|
|
|
|
|
|
@sel.render ActionView::Template.new(test_path_for("html.sel")), {'page_title' => page_title}
|
2007-03-30 12:34:56 +00:00
|
|
|
end
|
|
|
|
|
|
2008-12-02 10:05:41 +01:00
|
|
|
def create_sel_file_from(input, name)
|
|
|
|
|
File.open(test_path_for(name), 'w+') { |index_file| index_file << input }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_path_for(name)
|
|
|
|
|
"#{File.expand_path(File.dirname(__FILE__) + "/../test_data")}/#{name}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def assert_selenese expected, name, input
|
|
|
|
|
assert_text_equal expected, render_selenese(name, input)
|
|
|
|
|
end
|
|
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_empty
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">Empty</th></tr>
|
|
|
|
|
</table>
|
|
|
|
|
END
|
|
|
|
|
input = ''
|
|
|
|
|
assert_selenese expected, 'Empty', ''
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_one_line
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">One line</th></tr>
|
|
|
|
|
<tr><td>open</td><td>/</td><td> </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
END
|
|
|
|
|
input = '|open|/|'
|
|
|
|
|
assert_selenese expected, 'One line', input
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_comments_only
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<p>Comment <strong>1</strong></p>
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 10:05:41 +01:00
|
|
|
<p>Comment 2</p>
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">Only comments</th></tr>
|
|
|
|
|
</table>
|
|
|
|
|
END
|
|
|
|
|
input = <<END
|
|
|
|
|
Comment *1*
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
Comment 2
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
END
|
|
|
|
|
assert_selenese expected, 'Only comments', input
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_commands_only
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">Only commands</th></tr>
|
|
|
|
|
<tr><td>goBack</td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td>open</td><td>/foo</td><td> </td></tr>
|
|
|
|
|
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
END
|
|
|
|
|
input = <<END
|
|
|
|
|
|
|
|
|
|
|goBack |
|
|
|
|
|
|
|
|
|
|
|open| /foo |
|
2008-12-02 10:05:41 +01:00
|
|
|
| fireEvent | textField | focus |
|
2007-03-30 12:34:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
assert_selenese expected, 'Only commands', input
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_commands_and_comments
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">Commands and comments</th></tr>
|
|
|
|
|
<tr><td>goBack</td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
<p>Comment 1</p>
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 10:05:41 +01:00
|
|
|
<p>Comment <strong>2</strong></p>
|
2007-03-30 12:34:56 +00:00
|
|
|
END
|
|
|
|
|
input = <<END
|
|
|
|
|
|
|
|
|
|
|goBack |
|
|
|
|
|
|
|
|
|
|
| fireEvent | textField| focus|
|
|
|
|
|
Comment 1
|
|
|
|
|
|
|
|
|
|
Comment *2*
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
assert_selenese expected, 'Commands and comments', input
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_comments_and_commands
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<p>Comment 1</p>
|
2008-12-02 10:05:41 +01:00
|
|
|
|
|
|
|
|
<p>Comment <strong>2</strong></p>
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">Comments and commands</th></tr>
|
|
|
|
|
<tr><td>goBack</td><td> </td><td> </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
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_comments_commands_comments
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<p>Comment 1</p>
|
2008-12-02 10:05:41 +01:00
|
|
|
<p>Comment <strong>2</strong></p>
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">Comments, commands and comments</th></tr>
|
|
|
|
|
<tr><td>goBack</td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td>fireEvent</td><td>textField</td><td>focus</td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
<p>Comment 3</p>
|
|
|
|
|
END
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
input = <<END
|
|
|
|
|
Comment 1
|
|
|
|
|
|
|
|
|
|
Comment *2*
|
|
|
|
|
|goBack |
|
|
|
|
|
| fireEvent | textField| focus|
|
2008-12-02 10:05:41 +01:00
|
|
|
Comment 3
|
2007-03-30 12:34:56 +00:00
|
|
|
END
|
|
|
|
|
assert_selenese expected, 'Comments, commands and comments', input
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_command_html_entity_escaping
|
2008-12-02 10:05:41 +01:00
|
|
|
expected = <<END
|
2007-03-30 12:34:56 +00:00
|
|
|
<table>
|
|
|
|
|
<tr><th colspan="3">HTML escaping</th></tr>
|
|
|
|
|
<tr><td>type</td><td>nameField</td><td><>&</td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
END
|
|
|
|
|
input = '|type|nameField|<>&|'
|
|
|
|
|
assert_selenese expected, 'HTML escaping', input
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
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|'
|
2008-12-02 10:05:41 +01:00
|
|
|
create_sel_file_from(partial, "_override.sel")
|
|
|
|
|
|
|
|
|
|
assert_selenese(expected, 'Partial support', input)
|
|
|
|
|
|
|
|
|
|
File.delete(test_path_for("_override.sel"))
|
2007-03-30 12:34:56 +00:00
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
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
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
input = <<END_INPUT
|
|
|
|
|
|includePartial|override|a=hello|b=world!|
|
|
|
|
|
|includePartial|override|a = a b c d|b=|c_123ABC= hello |
|
|
|
|
|
END_INPUT
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
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
|
2008-12-02 10:05:41 +01:00
|
|
|
|
|
|
|
|
create_sel_file_from(partial, "_override.html")
|
|
|
|
|
|
|
|
|
|
assert_selenese(expected, 'Partial support with local assigns', input)
|
2007-03-30 12:34:56 +00:00
|
|
|
|
2008-12-02 10:05:41 +01:00
|
|
|
File.delete(test_path_for("_override.html"))
|
|
|
|
|
end
|
|
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_raised_when_more_than_three_columns
|
|
|
|
|
assert_raise RuntimeError, 'There might only be a maximum of three cells!' do
|
2008-12-02 10:05:41 +01:00
|
|
|
render_selenese 'name', '|col1|col2|col3|col4|'
|
2007-03-30 12:34:56 +00:00
|
|
|
end
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
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
|
2008-12-02 10:05:41 +01:00
|
|
|
render_selenese 'name', input
|
2007-03-30 12:34:56 +00:00
|
|
|
end
|
|
|
|
|
end
|
2008-12-02 10:05:41 +01:00
|
|
|
|
2007-03-30 12:34:56 +00:00
|
|
|
def test_raised_when_incorrect_partial_format
|
|
|
|
|
assert_raise RuntimeError, "Invalid format 'invalid'. Should be '|includePartial|partial|var1=value|var2=value|." do
|
2008-12-02 10:05:41 +01:00
|
|
|
render_selenese 'name', '|includePartial|partial|a=valid|invalid|'
|
2007-03-30 12:34:56 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|