celerity 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +14 -0
- data/Manifest.txt +127 -151
- data/README.txt +15 -20
- data/lib/celerity.rb +13 -5
- data/lib/celerity/browser.rb +296 -0
- data/lib/celerity/clickable_element.rb +1 -0
- data/lib/celerity/collections.rb +4 -0
- data/lib/celerity/container.rb +69 -2
- data/lib/celerity/disabled_element.rb +1 -0
- data/lib/celerity/element.rb +103 -38
- data/lib/celerity/element_collections.rb +14 -8
- data/lib/celerity/element_locator.rb +61 -50
- data/lib/celerity/element_map.rb +51 -0
- data/lib/celerity/elements/button.rb +1 -0
- data/lib/celerity/elements/file_field.rb +3 -2
- data/lib/celerity/elements/form.rb +1 -0
- data/lib/celerity/elements/frame.rb +16 -1
- data/lib/celerity/elements/image.rb +15 -13
- data/lib/celerity/elements/link.rb +4 -1
- data/lib/celerity/elements/option.rb +1 -0
- data/lib/celerity/elements/radio_check.rb +19 -7
- data/lib/celerity/elements/select_list.rb +17 -2
- data/lib/celerity/elements/table.rb +34 -20
- data/lib/celerity/elements/table_body.rb +2 -2
- data/lib/celerity/elements/table_cell.rb +3 -1
- data/lib/celerity/elements/table_footer.rb +2 -2
- data/lib/celerity/elements/table_header.rb +2 -2
- data/lib/celerity/elements/table_row.rb +4 -2
- data/lib/celerity/elements/text_field.rb +20 -9
- data/lib/celerity/exception.rb +11 -18
- data/lib/celerity/extra/method_generator.rb +13 -8
- data/lib/celerity/htmlunit/download.sh +23 -0
- data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
- data/lib/celerity/htmlunit/{nekohtml-1.9.7.jar → nekohtml-1.9.8.jar} +0 -0
- data/lib/celerity/input_element.rb +1 -1
- data/lib/celerity/version.rb +1 -1
- data/lib/celerity/watir_compatibility.rb +37 -23
- data/spec/area_spec.rb +19 -4
- data/spec/areas_spec.rb +2 -3
- data/spec/{ie_spec.rb → browser_spec.rb} +66 -15
- data/spec/button_spec.rb +36 -3
- data/spec/buttons_spec.rb +2 -3
- data/spec/checkbox_spec.rb +43 -8
- data/spec/checkboxes_spec.rb +2 -3
- data/spec/div_spec.rb +31 -4
- data/spec/divs_spec.rb +2 -3
- data/spec/element_spec.rb +36 -6
- data/spec/filefield_spec.rb +28 -13
- data/spec/filefields_spec.rb +2 -3
- data/spec/form_spec.rb +6 -3
- data/spec/forms_spec.rb +2 -3
- data/spec/frame_spec.rb +14 -5
- data/spec/frames_spec.rb +71 -0
- data/spec/hidden_spec.rb +21 -3
- data/spec/hiddens_spec.rb +2 -3
- data/spec/hn_spec.rb +30 -12
- data/spec/hns_spec.rb +14 -10
- data/spec/html/form_js_bug.html +11 -0
- data/spec/html/forms_with_input_elements.html +2 -1
- data/spec/html/invalid_js.html +11 -0
- data/spec/html/latin1_text.html +1 -0
- data/spec/html/non_control_elements.html +8 -4
- data/spec/html/simple_ajax.html +22 -0
- data/spec/htmlunit_spec.rb +4 -5
- data/spec/image_spec.rb +33 -3
- data/spec/images_spec.rb +2 -3
- data/spec/label_spec.rb +16 -3
- data/spec/labels_spec.rb +2 -3
- data/spec/li_spec.rb +25 -3
- data/spec/link_spec.rb +35 -3
- data/spec/links_spec.rb +2 -3
- data/spec/lis_spec.rb +2 -3
- data/spec/map_spec.rb +19 -3
- data/spec/maps_spec.rb +2 -3
- data/spec/meta_spec.rb +3 -1
- data/spec/ol_spec.rb +17 -3
- data/spec/ols_spec.rb +2 -3
- data/spec/option_spec.rb +28 -3
- data/spec/p_spec.rb +30 -2
- data/spec/pre_spec.rb +25 -3
- data/spec/pres_spec.rb +2 -3
- data/spec/ps_spec.rb +2 -3
- data/spec/radio_spec.rb +47 -3
- data/spec/radios_spec.rb +2 -3
- data/spec/select_list_spec.rb +42 -3
- data/spec/select_lists_spec.rb +2 -3
- data/spec/span_spec.rb +32 -7
- data/spec/spans_spec.rb +2 -4
- data/spec/spec_helper.rb +5 -25
- data/spec/table_bodies_spec.rb +7 -5
- data/spec/table_body_spec.rb +11 -4
- data/spec/table_cell_spec.rb +15 -4
- data/spec/table_cells_spec.rb +3 -4
- data/spec/table_footer_spec.rb +11 -4
- data/spec/table_footers_spec.rb +7 -5
- data/spec/table_header_spec.rb +11 -4
- data/spec/table_headers_spec.rb +7 -5
- data/spec/table_row_spec.rb +31 -7
- data/spec/table_rows_spec.rb +5 -4
- data/spec/table_spec.rb +36 -7
- data/spec/tables_spec.rb +2 -3
- data/spec/text_field_spec.rb +51 -13
- data/spec/text_fields_spec.rb +2 -3
- data/spec/ul_spec.rb +18 -3
- data/spec/uls_spec.rb +2 -3
- data/spec/{watir_compatability_spec.rb → watir_compatibility_spec.rb} +42 -35
- data/support/spec_server.rb +9 -0
- metadata +167 -161
- metadata.gz.sig +0 -0
- data/benchmark/bm_2000_spans.rb +0 -48
- data/benchmark/bm_digg.rb +0 -26
- data/benchmark/bm_google_images.rb +0 -36
- data/benchmark/bm_input_locator.rb +0 -69
- data/benchmark/loader.rb +0 -9
- data/config/hoe.rb +0 -68
- data/config/requirements.rb +0 -15
- data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
- data/lib/celerity/ie.rb +0 -195
- data/setup.rb +0 -1583
- data/support/celerity_viewer/rubycocoa/CelerityViewer.icns +0 -0
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/classes.nib +0 -37
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/info.nib +0 -19
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/keyedobjects.nib +0 -0
- data/support/celerity_viewer/rubycocoa/Info.plist.erb +0 -28
- data/support/celerity_viewer/rubycocoa/MainController.rb +0 -23
- data/support/celerity_viewer/rubycocoa/README +0 -94
- data/support/celerity_viewer/rubycocoa/Rakefile +0 -100
- data/support/celerity_viewer/rubycocoa/distributed_viewer.rb +0 -86
- data/support/celerity_viewer/rubycocoa/main.m +0 -7
- data/support/celerity_viewer/rubycocoa/main.rb +0 -27
- data/tasks/benchmark.rake +0 -4
- data/tasks/environment.rake +0 -7
- data/tasks/simple_ci.rake +0 -94
metadata.gz.sig
ADDED
|
Binary file
|
data/benchmark/bm_2000_spans.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/loader"
|
|
2
|
-
|
|
3
|
-
# Create browser object
|
|
4
|
-
browser = FRAMEWORK::IE.new
|
|
5
|
-
browser.goto(TEST_HOST + "/2000_spans.html")
|
|
6
|
-
|
|
7
|
-
TESTS = 100
|
|
8
|
-
res = Benchmark.bmbm do |results|
|
|
9
|
-
results.report("Loop through all spans (n = 1)") do
|
|
10
|
-
1.times do # Hard coded 1 run
|
|
11
|
-
browser.spans.each do |span|
|
|
12
|
-
span.text
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# results.report("Loop through all spans (raw)") do
|
|
18
|
-
# TESTS.times do
|
|
19
|
-
# if RUBY_PLATFORM =~ /java/
|
|
20
|
-
# browser.document.getHtmlElementsByTagName("span").each do |span|
|
|
21
|
-
# span.asText
|
|
22
|
-
# end
|
|
23
|
-
# else
|
|
24
|
-
# browser.document.getElementsByTagName("span").each do |span|
|
|
25
|
-
# span.innerText
|
|
26
|
-
# end
|
|
27
|
-
# end
|
|
28
|
-
# end
|
|
29
|
-
# end
|
|
30
|
-
|
|
31
|
-
results.report("Last span by id (String)") do
|
|
32
|
-
TESTS.times do
|
|
33
|
-
browser.span(:id, "id_2000").exists?
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
results.report("Last span by id (Regexp)") do
|
|
38
|
-
TESTS.times do
|
|
39
|
-
browser.span(:id, "/2000/").exists?
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
puts
|
|
46
|
-
total = res.inject(0.0) { |mem, bm| mem + bm.real }
|
|
47
|
-
puts "total : " + total.to_s
|
|
48
|
-
puts "average: " + (total/res.size.to_f).to_s
|
data/benchmark/bm_digg.rb
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/loader"
|
|
2
|
-
|
|
3
|
-
TESTS = 5
|
|
4
|
-
res = Benchmark.bmbm do |results|
|
|
5
|
-
results.report("Diggs on front page") do
|
|
6
|
-
TESTS.times do
|
|
7
|
-
# Create browser object
|
|
8
|
-
browser = FRAMEWORK::IE.new
|
|
9
|
-
|
|
10
|
-
# Go to digg.com
|
|
11
|
-
browser.goto('http://digg.com/')
|
|
12
|
-
|
|
13
|
-
# Gather statistics
|
|
14
|
-
total_diggs = 0
|
|
15
|
-
digg_number_elements = browser.links.select { |link| link.id =~ /diggs/ }
|
|
16
|
-
digg_numbers = digg_number_elements.collect { |digg_number_element| digg_number_element.text }
|
|
17
|
-
digg_numbers.each { |digg_number| total_diggs += digg_number.to_i }
|
|
18
|
-
#puts "Found #{digg_numbers.size} stories, with a total of #{total_diggs} diggs."
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
puts
|
|
24
|
-
total = res.inject(0.0) { |mem, bm| mem + bm.real }
|
|
25
|
-
puts "total : " + total.to_s
|
|
26
|
-
puts "average: " + (total/res.size.to_f).to_s
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/loader"
|
|
2
|
-
|
|
3
|
-
TESTS = 5
|
|
4
|
-
res = Benchmark.bmbm do |results|
|
|
5
|
-
results.report("Google image search results") do
|
|
6
|
-
TESTS.times do
|
|
7
|
-
# Create browser object
|
|
8
|
-
browser = FRAMEWORK::IE.new
|
|
9
|
-
|
|
10
|
-
# Goto images.google.com
|
|
11
|
-
browser.goto('http://images.google.com/ncr')
|
|
12
|
-
|
|
13
|
-
# Search for Watir
|
|
14
|
-
browser.text_field(:name, 'q').set('Watir')
|
|
15
|
-
browser.button(:value, 'Search Images').click
|
|
16
|
-
|
|
17
|
-
src_pool = []
|
|
18
|
-
pages = 1
|
|
19
|
-
# Gather statistics and click Next if there are more results
|
|
20
|
-
while browser.link(:text, 'Next').exists?
|
|
21
|
-
pages += 1
|
|
22
|
-
browser.link(:text, 'Next').click unless src_pool.empty?
|
|
23
|
-
table_cells = browser.cells.select { |cell| cell.id =~ /tDataImage\d+/ }
|
|
24
|
-
table_cells.each do |cell|
|
|
25
|
-
src_pool << cell.image(:index, 1).src if cell.image(:index, 1).exists?
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
#puts "Looked at #{pages} pages of image search results. Got #{src_pool.size} images."
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
puts
|
|
34
|
-
total = res.inject(0.0) { |mem, bm| mem + bm.real }
|
|
35
|
-
puts "total : " + total.to_s
|
|
36
|
-
puts "average: " + (total/res.size.to_f).to_s
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/loader"
|
|
2
|
-
|
|
3
|
-
browser = FRAMEWORK::IE.new
|
|
4
|
-
browser.goto(TEST_HOST + "/forms_with_input_elements.html")
|
|
5
|
-
|
|
6
|
-
TESTS = 1000
|
|
7
|
-
res = Benchmark.bmbm do |results|
|
|
8
|
-
results.report("text input by id (String)") do
|
|
9
|
-
TESTS.times { browser.text_field(:id, "new_user_first_name").exists? }
|
|
10
|
-
end
|
|
11
|
-
results.report("text input by id (Regexp)") do
|
|
12
|
-
TESTS.times { browser.text_field(:id, /first_name/).exists? }
|
|
13
|
-
end
|
|
14
|
-
results.report("text input by name (String)") do
|
|
15
|
-
TESTS.times { browser.text_field(:name, "new_user_email").exists? }
|
|
16
|
-
end
|
|
17
|
-
results.report("text input by name (Regexp)") do
|
|
18
|
-
TESTS.times { browser.text_field(:name, /user_email/).exists? }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
results.report("select list by id (String)") do
|
|
22
|
-
TESTS.times { browser.select_list(:id, 'new_user_country').exists? }
|
|
23
|
-
end
|
|
24
|
-
results.report("select list by id (Regexp)") do
|
|
25
|
-
TESTS.times { browser.select_list(:id, /user_country/).exists? }
|
|
26
|
-
end
|
|
27
|
-
results.report("select list by name (String)") do
|
|
28
|
-
TESTS.times { browser.select_list(:name, 'new_user_country').exists? }
|
|
29
|
-
end
|
|
30
|
-
results.report("select list by name (Regexp)") do
|
|
31
|
-
TESTS.times { browser.select_list(:name, /user_country/).exists? }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
results.report("checkbox by id (String)") do
|
|
35
|
-
TESTS.times { browser.checkbox(:id, 'new_user_interests_books').exists? }
|
|
36
|
-
end
|
|
37
|
-
results.report("checkbox by id (Regexp)") do
|
|
38
|
-
TESTS.times { browser.checkbox(:id, /interests_books/).exists? }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
results.report("checkbox by name (String)") do
|
|
42
|
-
TESTS.times { browser.checkbox(:name, 'new_user_interests').exists? }
|
|
43
|
-
end
|
|
44
|
-
results.report("checkbox by name (Regexp)") do
|
|
45
|
-
TESTS.times { browser.checkbox(:name, /user_interests/).exists? }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
results.report("checkbox by id (String) and value (String)") do
|
|
49
|
-
TESTS.times { browser.checkbox(:id, 'new_user_interests_books', 'cars').exists? }
|
|
50
|
-
end
|
|
51
|
-
results.report("checkbox by id (Regexp) and value (Regexp)") do
|
|
52
|
-
TESTS.times { browser.checkbox(:id, /interests_books/, /car/).exists? }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
results.report("checkbox by name (String) and value (String)") do
|
|
56
|
-
TESTS.times { browser.checkbox(:name, 'new_user_interests', 'dancing').exists? }
|
|
57
|
-
end
|
|
58
|
-
results.report("checkbox by name (Regexp) and value (Regexp)") do
|
|
59
|
-
TESTS.times { browser.checkbox(:name, /user_interests/, /danc/).exists? }
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
puts
|
|
67
|
-
total = res.inject(0.0) { |mem, bm| mem + bm.real }
|
|
68
|
-
puts "total : " + total.to_s
|
|
69
|
-
puts "average: " + (total/res.size.to_f).to_s
|
data/benchmark/loader.rb
DELETED
data/config/hoe.rb
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
require 'celerity/version'
|
|
2
|
-
|
|
3
|
-
AUTHORS = ["T. Alexander Lystad", "Knut Johannes Dahle", "Jari Bakken"]
|
|
4
|
-
EMAIL = "alexander.lystad@finntech.no"
|
|
5
|
-
DESCRIPTION = <<DESC
|
|
6
|
-
Celerity is a JRuby library for easy and fast functional test automation for web applications. It is a wrapper around the HtmlUnit Java library and is currently aimed at providing the same API and functionality as Watir.
|
|
7
|
-
DESC
|
|
8
|
-
|
|
9
|
-
GEM_NAME = 'celerity'
|
|
10
|
-
RUBYFORGE_PROJECT = 'celerity'
|
|
11
|
-
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
12
|
-
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
13
|
-
|
|
14
|
-
@config_file = "~/.rubyforge/user-config.yml"
|
|
15
|
-
@config = nil
|
|
16
|
-
RUBYFORGE_USERNAME = "unknown"
|
|
17
|
-
def rubyforge_username
|
|
18
|
-
unless @config
|
|
19
|
-
begin
|
|
20
|
-
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
|
21
|
-
rescue
|
|
22
|
-
puts <<-EOS
|
|
23
|
-
ERROR: No rubyforge config file found: #{@config_file}
|
|
24
|
-
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
25
|
-
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
|
26
|
-
EOS
|
|
27
|
-
exit
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
RUBYFORGE_USERNAME.replace @config["username"]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
REV = nil
|
|
35
|
-
# UNCOMMENT IF REQUIRED:
|
|
36
|
-
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
|
37
|
-
VERS = Celerity::VERSION::STRING + (REV ? ".#{REV}" : "")
|
|
38
|
-
|
|
39
|
-
class Hoe
|
|
40
|
-
def extra_deps
|
|
41
|
-
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
|
42
|
-
@extra_deps
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Generate all the Rake tasks
|
|
47
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
48
|
-
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
49
|
-
p.author = AUTHORS
|
|
50
|
-
p.email = EMAIL
|
|
51
|
-
p.description = DESCRIPTION
|
|
52
|
-
p.summary = DESCRIPTION
|
|
53
|
-
p.url = HOMEPATH
|
|
54
|
-
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
|
55
|
-
p.test_globs = ["test/**/test_*.rb"]
|
|
56
|
-
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
|
57
|
-
|
|
58
|
-
# == Optional
|
|
59
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
|
60
|
-
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
|
61
|
-
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
|
66
|
-
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
|
67
|
-
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
|
68
|
-
$hoe.rsync_args = '-av --delete --ignore-errors'
|
data/config/requirements.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
include FileUtils
|
|
3
|
-
|
|
4
|
-
require 'rubygems'
|
|
5
|
-
%w[rake hoe newgem rubigen].each do |req_gem|
|
|
6
|
-
begin
|
|
7
|
-
require req_gem
|
|
8
|
-
rescue LoadError
|
|
9
|
-
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
|
10
|
-
puts "Installation: gem install #{req_gem} -y"
|
|
11
|
-
exit
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
|
Binary file
|
|
Binary file
|
data/lib/celerity/ie.rb
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
module Celerity
|
|
2
|
-
class IE
|
|
3
|
-
include Container
|
|
4
|
-
attr_accessor :page, :object
|
|
5
|
-
attr_reader :charset, :webclient
|
|
6
|
-
|
|
7
|
-
def self.start(uri)
|
|
8
|
-
browser = new
|
|
9
|
-
browser.goto(uri)
|
|
10
|
-
browser
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# Creates a browser object.
|
|
15
|
-
#
|
|
16
|
-
# ==== Options (opts)
|
|
17
|
-
# :javascript_exceptions<true, false, nil>::
|
|
18
|
-
# Throw exceptions on script errors. Disabled by default.
|
|
19
|
-
# :status_code_exceptions<true, false, nil>::
|
|
20
|
-
# Throw exceptions on failing status codes (404++). Disabled by default.
|
|
21
|
-
# :css<true, false, nil>::
|
|
22
|
-
# Enable CSS. Disabled by default.
|
|
23
|
-
# :secure_ssl<true, false, nil>::
|
|
24
|
-
# Disable secure SSL. Enabled by default.
|
|
25
|
-
# :log_level<:trace, :debug, :info, :warn, :error, or :fatal>::
|
|
26
|
-
# Set the log level for Apache Jakarta commons logging system (used by HtmlUnit)
|
|
27
|
-
# Defaults to :warn. (not working..)
|
|
28
|
-
# ==== Returns
|
|
29
|
-
# An instance of Celerity::IE
|
|
30
|
-
#
|
|
31
|
-
#--
|
|
32
|
-
# @public
|
|
33
|
-
def initialize(opts = {})
|
|
34
|
-
java.lang.System.getProperties.put("org.apache.commons.logging.simplelog.defaultlog", opts[:log_level] ? opts[:log_level].to_s : "warn")
|
|
35
|
-
|
|
36
|
-
browser = RUBY_PLATFORM =~ /java/ ? ::HtmlUnit::BrowserVersion::FIREFOX_2 : ::HtmlUnit::BrowserVersion.FIREFOX_2
|
|
37
|
-
@webclient = ::HtmlUnit::WebClient.new(browser)
|
|
38
|
-
@webclient.setThrowExceptionOnScriptError(false) unless opts[:javascript_exceptions]
|
|
39
|
-
@webclient.setThrowExceptionOnFailingStatusCode(false) unless opts[:status_code_exceptions]
|
|
40
|
-
@webclient.setCssEnabled(false) unless opts[:css]
|
|
41
|
-
@webclient.setUseInsecureSSL(true) if opts[:secure_ssl]
|
|
42
|
-
|
|
43
|
-
@last_url, @page = nil
|
|
44
|
-
@page_container = self
|
|
45
|
-
@error_checkers = []
|
|
46
|
-
find_viewer
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def goto(uri)
|
|
50
|
-
uri = "http://#{uri}" unless uri =~ %r{^https?://}
|
|
51
|
-
set_page @webclient.getPage(uri)
|
|
52
|
-
uri
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def close
|
|
56
|
-
@page = nil
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def set_page(value)
|
|
60
|
-
@last_url = url() if exist?
|
|
61
|
-
@page = value
|
|
62
|
-
if @page.respond_to?("getDocumentElement")
|
|
63
|
-
@object = @page.getDocumentElement
|
|
64
|
-
end
|
|
65
|
-
render if @viewer
|
|
66
|
-
run_error_checks
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def url
|
|
70
|
-
assert_exists
|
|
71
|
-
@page.getWebResponse.getUrl.toString
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def title
|
|
75
|
-
@page ? @page.getTitleText : ''
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def html
|
|
79
|
-
@page ? @page.getWebResponse.getContentAsString : ''
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def text
|
|
83
|
-
if @page.respond_to?("getContent")
|
|
84
|
-
@page.getContent
|
|
85
|
-
else
|
|
86
|
-
@page ? @page.getFirstByXPath("//body").asText : ''
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def document
|
|
91
|
-
@object
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def collection_string(collection_method)
|
|
95
|
-
collection = self.send collection_method
|
|
96
|
-
buffer = "Found #{collection.size} divs\n"
|
|
97
|
-
collection.each_with_index do |div, index|
|
|
98
|
-
buffer += "#{index+1}: #{div.attribute_string}\n"
|
|
99
|
-
end
|
|
100
|
-
return buffer
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def back
|
|
104
|
-
# FIXME: this is naive, need capability from HtmlUnit
|
|
105
|
-
goto(@last_url) if @last_url
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def refresh
|
|
109
|
-
assert_exists
|
|
110
|
-
set_page(@page.refresh)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def exist?
|
|
114
|
-
!!@page
|
|
115
|
-
end
|
|
116
|
-
alias_method :exists?, :exist?
|
|
117
|
-
|
|
118
|
-
# check that we have a @page object
|
|
119
|
-
# need to find a better way to handle this
|
|
120
|
-
def assert_exists
|
|
121
|
-
raise UnknownObjectException, "no page loaded" unless exist?
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def contains_text(expected_text)
|
|
125
|
-
return nil unless exist?
|
|
126
|
-
case expected_text
|
|
127
|
-
when Regexp
|
|
128
|
-
text().match(expected_text)
|
|
129
|
-
when String
|
|
130
|
-
text().index(expected_text)
|
|
131
|
-
else
|
|
132
|
-
raise ArgumentError, "Argument #{expected_text.inspect} should be a String or Regexp."
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def execute_script(source)
|
|
137
|
-
assert_exists
|
|
138
|
-
@page.executeJavaScript(source.to_s)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def run_error_checks
|
|
142
|
-
@error_checkers.each { |e| e.call(self) }
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def add_checker(checker = nil, &block)
|
|
146
|
-
if block_given?
|
|
147
|
-
@error_checkers << block
|
|
148
|
-
elsif Proc === checker
|
|
149
|
-
@error_checkers << checker
|
|
150
|
-
else
|
|
151
|
-
raise ArgumentError, "argument must be a Proc or block"
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def disable_checker(checker)
|
|
156
|
-
@error_checkers.delete(checker)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def method_missing(meth, *args)
|
|
160
|
-
match_data = /^show_(.*)$/.match(meth.to_s)
|
|
161
|
-
if match_data
|
|
162
|
-
begin
|
|
163
|
-
puts collection_string(match_data[1])
|
|
164
|
-
rescue NoMethodError
|
|
165
|
-
super
|
|
166
|
-
end
|
|
167
|
-
else
|
|
168
|
-
super
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
private
|
|
173
|
-
|
|
174
|
-
def render
|
|
175
|
-
begin
|
|
176
|
-
@viewer.render_html(html, url)
|
|
177
|
-
rescue Errno::ECONNREFUSED => e
|
|
178
|
-
puts e.message
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def find_viewer
|
|
183
|
-
begin
|
|
184
|
-
if `uname`.chomp == "Darwin" && `ps ax`[/CelerityViewer/]
|
|
185
|
-
require "drb"
|
|
186
|
-
@viewer = DRbObject.new_with_uri("druby://127.0.0.1:1337")
|
|
187
|
-
end
|
|
188
|
-
rescue IOError, Errno::ENOENT
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
end # IE
|
|
193
|
-
end # Celerity
|
|
194
|
-
|
|
195
|
-
Celerity::Browser = Celerity::IE
|