mechanize 0.4.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mechanize might be problematic. Click here for more details.
- data/CHANGELOG +17 -0
- data/EXAMPLES +23 -44
- data/NOTES +49 -0
- data/lib/mechanize.rb +95 -80
- data/lib/mechanize/cookie.rb +147 -148
- data/lib/mechanize/cookie.rb.rej +16 -0
- data/lib/mechanize/errors.rb +29 -0
- data/lib/mechanize/form.rb +211 -186
- data/lib/mechanize/form_elements.rb +31 -71
- data/lib/mechanize/list.rb +34 -0
- data/lib/mechanize/mech_version.rb +3 -1
- data/lib/mechanize/module.rb +1 -1
- data/lib/mechanize/page.rb +162 -180
- data/lib/mechanize/page_elements.rb +53 -40
- data/lib/mechanize/parsing.rb +11 -3
- data/lib/mechanize/pluggable_parsers.rb +147 -0
- data/test/data/server.crt +14 -0
- data/test/data/server.csr +11 -0
- data/test/data/server.key +18 -0
- data/test/data/server.pem +15 -0
- data/test/htdocs/no_title_test.html +6 -0
- data/test/parse.rb +39 -0
- data/test/proxy.rb +30 -0
- data/test/server.rb +2 -0
- data/test/servlets.rb +8 -0
- data/test/ssl_server.rb +49 -0
- data/test/tc_authenticate.rb +8 -6
- data/test/tc_cookie_class.rb +28 -18
- data/test/tc_cookie_jar.rb +88 -27
- data/test/tc_cookies.rb +41 -44
- data/test/tc_errors.rb +9 -23
- data/test/tc_forms.rb +36 -32
- data/test/tc_frames.rb +6 -4
- data/test/tc_links.rb +7 -6
- data/test/tc_mech.rb +43 -46
- data/test/tc_page.rb +24 -0
- data/test/tc_pluggable_parser.rb +103 -0
- data/test/tc_post_form.rb +41 -0
- data/test/tc_proxy.rb +25 -0
- data/test/tc_response_code.rb +13 -10
- data/test/tc_save_file.rb +25 -0
- data/test/tc_ssl_server.rb +27 -0
- data/test/tc_upload.rb +8 -6
- data/test/tc_watches.rb +5 -2
- data/test/test_includes.rb +3 -3
- data/test/ts_mech.rb +11 -2
- metadata +100 -86
- data/test/tc_filter.rb +0 -34
data/test/tc_cookies.rb
CHANGED
@@ -3,122 +3,119 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'rubygems'
|
5
5
|
require 'mechanize'
|
6
|
-
require 'net/http'
|
7
|
-
require 'uri'
|
8
6
|
require 'test_includes'
|
9
7
|
|
10
8
|
class CookiesMechTest < Test::Unit::TestCase
|
11
9
|
include TestMethods
|
12
10
|
|
11
|
+
def setup
|
12
|
+
@agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
13
|
+
end
|
14
|
+
|
13
15
|
def test_send_cookies
|
14
|
-
|
15
|
-
page = agent.get("http://localhost:#{
|
16
|
-
page = agent.get("http://localhost:#{@port}/send_cookies")
|
16
|
+
page = @agent.get("http://localhost:#{PORT}/many_cookies")
|
17
|
+
page = @agent.get("http://localhost:#{PORT}/send_cookies")
|
17
18
|
assert_equal(2, page.links.length)
|
18
19
|
assert_not_nil(page.links.find { |l| l.text == "name:Aaron" })
|
19
20
|
assert_not_nil(page.links.find { |l| l.text == "no_expires:nope" })
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_no_space_cookies
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
foo_cookie = agent.cookies.find { |k| k.name == 'foo' }
|
24
|
+
page = @agent.get("http://localhost:#{PORT}/one_cookie_no_space")
|
25
|
+
assert_equal(1, @agent.cookies.length)
|
26
|
+
foo_cookie = @agent.cookies.find { |k| k.name == 'foo' }
|
27
27
|
assert_not_nil(foo_cookie, 'Foo cookie was nil')
|
28
28
|
assert_equal('bar', foo_cookie.value)
|
29
29
|
assert_equal('/', foo_cookie.path)
|
30
|
-
assert_equal(true,
|
30
|
+
assert_equal(true, Time.now < foo_cookie.expires)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_many_cookies_as_string
|
34
|
-
|
35
|
-
|
36
|
-
assert_equal(4, agent.cookies.length)
|
34
|
+
page = @agent.get("http://localhost:#{PORT}/many_cookies_as_string")
|
35
|
+
assert_equal(4, @agent.cookies.length)
|
37
36
|
|
38
|
-
name_cookie = agent.cookies.find { |k| k.name == "name" }
|
37
|
+
name_cookie = @agent.cookies.find { |k| k.name == "name" }
|
39
38
|
assert_not_nil(name_cookie, "Name cookie was nil")
|
40
39
|
assert_equal("Aaron", name_cookie.value)
|
41
40
|
assert_equal("/", name_cookie.path)
|
42
|
-
assert_equal(true,
|
41
|
+
assert_equal(true, Time.now < name_cookie.expires)
|
43
42
|
|
44
|
-
expired_cookie = agent.cookies.find { |k| k.name == "expired" }
|
43
|
+
expired_cookie = @agent.cookies.find { |k| k.name == "expired" }
|
45
44
|
assert_nil(expired_cookie, "Expired cookie was not nil")
|
46
45
|
|
47
|
-
no_exp_cookie = agent.cookies.find { |k| k.name == "no_expires" }
|
46
|
+
no_exp_cookie = @agent.cookies.find { |k| k.name == "no_expires" }
|
48
47
|
assert_not_nil(no_exp_cookie, "No expires cookie is nil")
|
49
48
|
assert_equal("nope", no_exp_cookie.value)
|
50
49
|
assert_equal("/", no_exp_cookie.path)
|
51
50
|
assert_nil(no_exp_cookie.expires)
|
52
51
|
|
53
|
-
path_cookie = agent.cookies.find { |k| k.name == "a_path" }
|
52
|
+
path_cookie = @agent.cookies.find { |k| k.name == "a_path" }
|
54
53
|
assert_not_nil(path_cookie, "Path cookie is nil")
|
55
54
|
assert_equal("some_path", path_cookie.value)
|
56
|
-
assert_equal(true,
|
55
|
+
assert_equal(true, Time.now < path_cookie.expires)
|
57
56
|
|
58
|
-
no_path_cookie = agent.cookies.find { |k| k.name == "no_path" }
|
57
|
+
no_path_cookie = @agent.cookies.find { |k| k.name == "no_path" }
|
59
58
|
assert_not_nil(no_path_cookie, "No path cookie is nil")
|
60
59
|
assert_equal("no_path", no_path_cookie.value)
|
61
60
|
assert_equal("/many_cookies_as_string", no_path_cookie.path)
|
62
|
-
assert_equal(true,
|
61
|
+
assert_equal(true, Time.now < no_path_cookie.expires)
|
63
62
|
end
|
64
63
|
|
65
64
|
def test_many_cookies
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal(4, agent.cookies.length)
|
65
|
+
page = @agent.get("http://localhost:#{PORT}/many_cookies")
|
66
|
+
assert_equal(4, @agent.cookies.length)
|
69
67
|
|
70
|
-
name_cookie = agent.cookies.find { |k| k.name == "name" }
|
68
|
+
name_cookie = @agent.cookies.find { |k| k.name == "name" }
|
71
69
|
assert_not_nil(name_cookie, "Name cookie was nil")
|
72
70
|
assert_equal("Aaron", name_cookie.value)
|
73
71
|
assert_equal("/", name_cookie.path)
|
74
|
-
assert_equal(true,
|
72
|
+
assert_equal(true, Time.now < name_cookie.expires)
|
75
73
|
|
76
|
-
expired_cookie = agent.cookies.find { |k| k.name == "expired" }
|
74
|
+
expired_cookie = @agent.cookies.find { |k| k.name == "expired" }
|
77
75
|
assert_nil(expired_cookie, "Expired cookie was not nil")
|
78
76
|
|
79
|
-
no_exp_cookie = agent.cookies.find { |k| k.name == "no_expires" }
|
77
|
+
no_exp_cookie = @agent.cookies.find { |k| k.name == "no_expires" }
|
80
78
|
assert_not_nil(no_exp_cookie, "No expires cookie is nil")
|
81
79
|
assert_equal("nope", no_exp_cookie.value)
|
82
80
|
assert_equal("/", no_exp_cookie.path)
|
83
81
|
assert_nil(no_exp_cookie.expires)
|
84
82
|
|
85
|
-
path_cookie = agent.cookies.find { |k| k.name == "a_path" }
|
83
|
+
path_cookie = @agent.cookies.find { |k| k.name == "a_path" }
|
86
84
|
assert_not_nil(path_cookie, "Path cookie is nil")
|
87
85
|
assert_equal("some_path", path_cookie.value)
|
88
|
-
assert_equal(true,
|
86
|
+
assert_equal(true, Time.now < path_cookie.expires)
|
89
87
|
|
90
|
-
no_path_cookie = agent.cookies.find { |k| k.name == "no_path" }
|
88
|
+
no_path_cookie = @agent.cookies.find { |k| k.name == "no_path" }
|
91
89
|
assert_not_nil(no_path_cookie, "No path cookie is nil")
|
92
90
|
assert_equal("no_path", no_path_cookie.value)
|
93
91
|
assert_equal("/many_cookies", no_path_cookie.path)
|
94
|
-
assert_equal(true,
|
92
|
+
assert_equal(true, Time.now < no_path_cookie.expires)
|
95
93
|
end
|
96
94
|
|
97
95
|
def test_get_cookie
|
98
|
-
agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
99
96
|
assert_equal(true,
|
100
|
-
agent.cookie_jar.empty?(
|
101
|
-
URI::parse("http://localhost:#{
|
97
|
+
@agent.cookie_jar.empty?(
|
98
|
+
URI::parse("http://localhost:#{PORT}/one_cookie")))
|
102
99
|
|
103
|
-
assert_equal(0, agent.cookies.length)
|
100
|
+
assert_equal(0, @agent.cookies.length)
|
104
101
|
|
105
|
-
page = agent.get("http://localhost:#{
|
106
|
-
assert_equal(1, agent.cookies.length)
|
102
|
+
page = @agent.get("http://localhost:#{PORT}/one_cookie")
|
103
|
+
assert_equal(1, @agent.cookies.length)
|
107
104
|
|
108
|
-
cookie = agent.cookies.first
|
105
|
+
cookie = @agent.cookies.first
|
109
106
|
assert_equal("foo", cookie.name)
|
110
107
|
assert_equal("bar", cookie.value)
|
111
108
|
assert_equal("/", cookie.path)
|
112
109
|
assert_equal("localhost", cookie.domain)
|
113
110
|
|
114
111
|
assert_equal(false,
|
115
|
-
agent.cookie_jar.empty?(
|
116
|
-
URI::parse("http://localhost:#{
|
117
|
-
page = agent.get("http://localhost:#{
|
112
|
+
@agent.cookie_jar.empty?(
|
113
|
+
URI::parse("http://localhost:#{PORT}/one_cookie")))
|
114
|
+
page = @agent.get("http://localhost:#{PORT}/one_cookie")
|
118
115
|
|
119
|
-
assert_equal(1, agent.cookies.length)
|
116
|
+
assert_equal(1, @agent.cookies.length)
|
120
117
|
|
121
|
-
cookie = agent.cookies.first
|
118
|
+
cookie = @agent.cookies.first
|
122
119
|
assert_equal("foo", cookie.name)
|
123
120
|
assert_equal("bar", cookie.value)
|
124
121
|
assert_equal("/", cookie.path)
|
data/test/tc_errors.rb
CHANGED
@@ -8,55 +8,41 @@ require 'test_includes'
|
|
8
8
|
class MechErrorsTest < Test::Unit::TestCase
|
9
9
|
include TestMethods
|
10
10
|
|
11
|
-
def
|
12
|
-
agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
13
|
-
page = agent.get("http://localhost:#{@port}/bad_content_type")
|
14
|
-
assert_raise(WWW::Mechanize::ContentTypeError) {
|
15
|
-
page.root
|
16
|
-
}
|
17
|
-
begin
|
18
|
-
page.root
|
19
|
-
rescue WWW::Mechanize::ContentTypeError => ex
|
20
|
-
assert_equal('text/xml', ex.content_type)
|
21
|
-
end
|
11
|
+
def setup
|
12
|
+
@agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
22
13
|
end
|
23
14
|
|
24
15
|
def test_bad_form_method
|
25
|
-
|
26
|
-
page = agent.get("http://localhost:#{@port}/bad_form_test.html")
|
16
|
+
page = @agent.get("http://localhost:#{PORT}/bad_form_test.html")
|
27
17
|
assert_raise(RuntimeError) {
|
28
|
-
agent.submit(page.forms.first)
|
18
|
+
@agent.submit(page.forms.first)
|
29
19
|
}
|
30
20
|
end
|
31
21
|
|
32
22
|
def test_too_many_radio
|
33
|
-
|
34
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
23
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
35
24
|
form = page.forms.name('post_form1').first
|
36
25
|
form.radiobuttons.each { |r| r.checked = true }
|
37
26
|
assert_raise(RuntimeError) {
|
38
|
-
agent.submit(form)
|
27
|
+
@agent.submit(form)
|
39
28
|
}
|
40
29
|
end
|
41
30
|
|
42
31
|
def test_unknown_agent
|
43
|
-
agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
44
32
|
assert_raise(RuntimeError) {
|
45
|
-
agent.user_agent_alias = "Aaron's Browser"
|
33
|
+
@agent.user_agent_alias = "Aaron's Browser"
|
46
34
|
}
|
47
35
|
end
|
48
36
|
|
49
37
|
def test_bad_url
|
50
|
-
agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
51
38
|
assert_raise(RuntimeError) {
|
52
|
-
agent.get('/foo.html')
|
39
|
+
@agent.get('/foo.html')
|
53
40
|
}
|
54
41
|
end
|
55
42
|
|
56
43
|
def test_unsupported_scheme
|
57
|
-
agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
58
44
|
assert_raise(RuntimeError) {
|
59
|
-
agent.get('ftp://server.com/foo.html')
|
45
|
+
@agent.get('ftp://server.com/foo.html')
|
60
46
|
}
|
61
47
|
end
|
62
48
|
end
|
data/test/tc_forms.rb
CHANGED
@@ -9,17 +9,19 @@ require 'test_includes'
|
|
9
9
|
class FormsMechTest < Test::Unit::TestCase
|
10
10
|
include TestMethods
|
11
11
|
|
12
|
+
def setup
|
13
|
+
@agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
14
|
+
end
|
15
|
+
|
12
16
|
def test_no_form_action
|
13
|
-
|
14
|
-
page = mech.get('http://localhost:2000/form_no_action.html')
|
17
|
+
page = @agent.get('http://localhost:2000/form_no_action.html')
|
15
18
|
page.forms.first.fields.first.value = 'Aaron'
|
16
|
-
page =
|
19
|
+
page = @agent.submit(page.forms.first)
|
17
20
|
assert_match('/form_no_action.html?first=Aaron', page.uri.to_s)
|
18
21
|
end
|
19
22
|
# Test submitting form with two fields of the same name
|
20
23
|
def test_post_multival
|
21
|
-
|
22
|
-
page = agent.get("http://localhost:#{@port}/form_multival.html")
|
24
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
23
25
|
form = page.forms.name('post_form').first
|
24
26
|
|
25
27
|
assert_not_nil(form)
|
@@ -28,7 +30,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
28
30
|
form.fields.name('first')[0].value = 'Aaron'
|
29
31
|
form.fields.name('first')[1].value = 'Patterson'
|
30
32
|
|
31
|
-
page = agent.submit(form)
|
33
|
+
page = @agent.submit(form)
|
32
34
|
|
33
35
|
assert_not_nil(page)
|
34
36
|
|
@@ -39,8 +41,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
39
41
|
|
40
42
|
# Test submitting form with two fields of the same name
|
41
43
|
def test_get_multival
|
42
|
-
|
43
|
-
page = agent.get("http://localhost:#{@port}/form_multival.html")
|
44
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
44
45
|
form = page.forms.name('get_form').first
|
45
46
|
|
46
47
|
assert_not_nil(form)
|
@@ -49,7 +50,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
49
50
|
form.fields.name('first')[0].value = 'Aaron'
|
50
51
|
form.fields.name('first')[1].value = 'Patterson'
|
51
52
|
|
52
|
-
page = agent.submit(form)
|
53
|
+
page = @agent.submit(form)
|
53
54
|
|
54
55
|
assert_not_nil(page)
|
55
56
|
|
@@ -59,8 +60,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def test_post
|
62
|
-
|
63
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
63
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
64
64
|
post_form = page.forms.find { |f| f.name == "post_form1" }
|
65
65
|
assert_not_nil(post_form, "Post form is null")
|
66
66
|
assert_equal("post", post_form.method.downcase)
|
@@ -110,7 +110,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
110
110
|
}.checked = true
|
111
111
|
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
112
112
|
post_form.checkboxes.find { |f| f.name == "green[eggs]" }.checked = true
|
113
|
-
page = agent.submit(post_form, post_form.buttons.first)
|
113
|
+
page = @agent.submit(post_form, post_form.buttons.first)
|
114
114
|
|
115
115
|
# Check that the submitted fields exist
|
116
116
|
assert_equal(5, page.links.size, "Not enough links")
|
@@ -137,8 +137,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_select_box
|
140
|
-
|
141
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
140
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
142
141
|
post_form = page.forms.find { |f| f.name == "post_form1" }
|
143
142
|
assert_not_nil(post_form, "Post form is null")
|
144
143
|
assert_not_nil(page.header)
|
@@ -159,7 +158,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
159
158
|
|
160
159
|
# Now set all the fields
|
161
160
|
post_form.fields.name(/country/).value = s.options[1]
|
162
|
-
page = agent.submit(post_form, post_form.buttons.first)
|
161
|
+
page = @agent.submit(post_form, post_form.buttons.first)
|
163
162
|
|
164
163
|
# Check that the submitted fields exist
|
165
164
|
assert_not_nil(
|
@@ -169,8 +168,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
169
168
|
end
|
170
169
|
|
171
170
|
def test_get
|
172
|
-
|
173
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
171
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
174
172
|
get_form = page.forms.find { |f| f.name == "get_form1" }
|
175
173
|
assert_not_nil(get_form, "Get form is null")
|
176
174
|
assert_equal("get", get_form.method.downcase)
|
@@ -210,7 +208,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
210
208
|
}.checked = true
|
211
209
|
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
212
210
|
get_form.checkboxes.find { |f| f.name == "green[eggs]" }.checked = true
|
213
|
-
page = agent.submit(get_form, get_form.buttons.first)
|
211
|
+
page = @agent.submit(get_form, get_form.buttons.first)
|
214
212
|
|
215
213
|
# Check that the submitted fields exist
|
216
214
|
assert_equal(7, page.links.size, "Not enough links")
|
@@ -245,8 +243,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
245
243
|
end
|
246
244
|
|
247
245
|
def test_post_with_space_in_action
|
248
|
-
|
249
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
246
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
250
247
|
post_form = page.forms.find { |f| f.name == "post_form2" }
|
251
248
|
assert_not_nil(post_form, "Post form is null")
|
252
249
|
assert_equal("post", post_form.method.downcase)
|
@@ -279,7 +276,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
279
276
|
f.name == "gender" && f.value == "male"
|
280
277
|
}.checked = true
|
281
278
|
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
282
|
-
page = agent.submit(post_form, post_form.buttons.first)
|
279
|
+
page = @agent.submit(post_form, post_form.buttons.first)
|
283
280
|
|
284
281
|
# Check that the submitted fields exist
|
285
282
|
assert_equal(3, page.links.size, "Not enough links")
|
@@ -298,8 +295,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
298
295
|
end
|
299
296
|
|
300
297
|
def test_get_with_space_in_action
|
301
|
-
|
302
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
298
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
303
299
|
get_form = page.forms.find { |f| f.name == "get_form2" }
|
304
300
|
assert_not_nil(get_form, "Get form is null")
|
305
301
|
assert_equal("get", get_form.method.downcase)
|
@@ -332,7 +328,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
332
328
|
f.name == "gender" && f.value == "male"
|
333
329
|
}.checked = true
|
334
330
|
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
335
|
-
page = agent.submit(get_form, get_form.buttons.first)
|
331
|
+
page = @agent.submit(get_form, get_form.buttons.first)
|
336
332
|
|
337
333
|
# Check that the submitted fields exist
|
338
334
|
assert_equal(3, page.links.size, "Not enough links")
|
@@ -351,8 +347,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
351
347
|
end
|
352
348
|
|
353
349
|
def test_post_with_param_in_action
|
354
|
-
|
355
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
350
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
356
351
|
post_form = page.forms.find { |f| f.name == "post_form3" }
|
357
352
|
assert_not_nil(post_form, "Post form is null")
|
358
353
|
assert_equal("post", post_form.method.downcase)
|
@@ -385,7 +380,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
385
380
|
f.name == "gender" && f.value == "male"
|
386
381
|
}.checked = true
|
387
382
|
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
388
|
-
page = agent.submit(post_form, post_form.buttons.first)
|
383
|
+
page = @agent.submit(post_form, post_form.buttons.first)
|
389
384
|
|
390
385
|
# Check that the submitted fields exist
|
391
386
|
assert_equal(3, page.links.size, "Not enough links")
|
@@ -404,8 +399,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
404
399
|
end
|
405
400
|
|
406
401
|
def test_get_with_param_in_action
|
407
|
-
|
408
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
402
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
409
403
|
get_form = page.forms.find { |f| f.name == "get_form3" }
|
410
404
|
assert_not_nil(get_form, "Get form is null")
|
411
405
|
assert_equal("get", get_form.method.downcase)
|
@@ -438,7 +432,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
438
432
|
f.name == "gender" && f.value == "male"
|
439
433
|
}.checked = true
|
440
434
|
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
441
|
-
page = agent.submit(get_form, get_form.buttons.first)
|
435
|
+
page = @agent.submit(get_form, get_form.buttons.first)
|
442
436
|
|
443
437
|
# Check that the submitted fields exist
|
444
438
|
assert_equal(5, page.links.size, "Not enough links")
|
@@ -465,10 +459,20 @@ class FormsMechTest < Test::Unit::TestCase
|
|
465
459
|
end
|
466
460
|
|
467
461
|
def test_field_addition
|
468
|
-
|
469
|
-
page = agent.get("http://localhost:#{@port}/form_test.html")
|
462
|
+
page = @agent.get("http://localhost:#{PORT}/form_test.html")
|
470
463
|
get_form = page.forms.find { |f| f.name == "get_form1" }
|
471
464
|
get_form.field("first_name").value = "Gregory"
|
472
465
|
assert_equal( "Gregory", get_form.field("first_name").value )
|
473
466
|
end
|
467
|
+
|
468
|
+
def test_fields_as_accessors
|
469
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
470
|
+
form = page.forms.name('post_form').first
|
471
|
+
|
472
|
+
assert_not_nil(form)
|
473
|
+
assert_equal(2, form.fields.name('first').length)
|
474
|
+
|
475
|
+
form.first = 'Aaron'
|
476
|
+
assert_equal('Aaron', form.first)
|
477
|
+
end
|
474
478
|
end
|
data/test/tc_frames.rb
CHANGED
@@ -8,9 +8,12 @@ require 'test_includes'
|
|
8
8
|
class FramesMechTest < Test::Unit::TestCase
|
9
9
|
include TestMethods
|
10
10
|
|
11
|
+
def setup
|
12
|
+
@agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
|
13
|
+
end
|
14
|
+
|
11
15
|
def test_frames
|
12
|
-
|
13
|
-
page = agent.get("http://localhost:#{@port}/frame_test.html")
|
16
|
+
page = @agent.get("http://localhost:#{PORT}/frame_test.html")
|
14
17
|
assert_equal(3, page.frames.size)
|
15
18
|
assert_equal("frame1", page.frames[0].name)
|
16
19
|
assert_equal("frame2", page.frames[1].name)
|
@@ -21,8 +24,7 @@ class FramesMechTest < Test::Unit::TestCase
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_iframes
|
24
|
-
|
25
|
-
page = agent.get("http://localhost:#{@port}/iframe_test.html")
|
27
|
+
page = @agent.get("http://localhost:#{PORT}/iframe_test.html")
|
26
28
|
assert_equal(1, page.iframes.size)
|
27
29
|
assert_equal("frame4", page.iframes.first.name)
|
28
30
|
assert_equal("/file_upload.html", page.iframes.first.src)
|