selenium_controller_test.rb
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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