celerity 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +36 -0
- data/Manifest.txt +82 -0
- data/README.rdoc +78 -0
- data/Rakefile +25 -10
- data/celerity.gemspec +40 -0
- data/lib/celerity.rb +36 -20
- data/lib/celerity/browser.rb +396 -189
- data/lib/celerity/clickable_element.rb +25 -5
- data/lib/celerity/collections.rb +2 -2
- data/lib/celerity/container.rb +74 -61
- data/lib/celerity/default_viewer.rb +8 -4
- data/lib/celerity/disabled_element.rb +5 -5
- data/lib/celerity/element.rb +57 -35
- data/lib/celerity/element_collection.rb +22 -21
- data/lib/celerity/element_locator.rb +25 -18
- data/lib/celerity/elements/button.rb +13 -11
- data/lib/celerity/elements/file_field.rb +8 -4
- data/lib/celerity/elements/form.rb +7 -5
- data/lib/celerity/elements/frame.rb +6 -4
- data/lib/celerity/elements/image.rb +4 -4
- data/lib/celerity/elements/label.rb +1 -1
- data/lib/celerity/elements/link.rb +5 -5
- data/lib/celerity/elements/meta.rb +2 -1
- data/lib/celerity/elements/non_control_elements.rb +3 -3
- data/lib/celerity/elements/option.rb +7 -7
- data/lib/celerity/elements/radio_check.rb +18 -18
- data/lib/celerity/elements/select_list.rb +55 -25
- data/lib/celerity/elements/table.rb +21 -18
- data/lib/celerity/elements/table_cell.rb +1 -1
- data/lib/celerity/elements/table_elements.rb +1 -1
- data/lib/celerity/elements/table_row.rb +5 -5
- data/lib/celerity/elements/text_field.rb +33 -28
- data/lib/celerity/exception.rb +11 -5
- data/lib/celerity/htmlunit.rb +24 -8
- data/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.6.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.6.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.13.jar +0 -0
- data/lib/celerity/htmlunit/{xercesImpl-2.8.1.jar → xercesImpl-2.9.1.jar} +0 -0
- data/lib/celerity/ignoring_web_connection.rb +15 -0
- data/lib/celerity/input_element.rb +1 -1
- data/lib/celerity/listener.rb +23 -17
- data/lib/celerity/short_inspect.rb +20 -0
- data/lib/celerity/util.rb +5 -2
- data/lib/celerity/version.rb +3 -10
- data/lib/celerity/viewer_connection.rb +89 -0
- data/lib/celerity/watir_compatibility.rb +2 -5
- data/lib/celerity/xpath_support.rb +48 -0
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +300 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +51 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +56 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +8 -0
- data/tasks/benchmark.rake +4 -0
- data/tasks/deployment.rake +43 -0
- data/tasks/environment.rake +7 -0
- data/tasks/fix.rake +25 -0
- data/tasks/jar.rake +4 -6
- data/tasks/rspec.rake +43 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/snapshot.rake +22 -0
- data/tasks/website.rake +17 -0
- data/tasks/yard.rake +9 -0
- metadata +59 -26
- data/README.txt +0 -69
- data/lib/celerity/extra/method_generator.rb +0 -170
- data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.5-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.5-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.12-20090308.130127-11.jar +0 -0
@@ -1,170 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "uri"
|
3
|
-
require "active_support"
|
4
|
-
|
5
|
-
#--
|
6
|
-
# http://api.rubyonrails.com/classes/Inflector.html#M001621
|
7
|
-
#++
|
8
|
-
class String # :nodoc:
|
9
|
-
def underscore
|
10
|
-
gsub(/::/, '/').
|
11
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
12
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
13
|
-
tr("-", "_").
|
14
|
-
downcase
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Celerity
|
19
|
-
|
20
|
-
#
|
21
|
-
# Experimental - generate a method definition for accessing elements on the current page.
|
22
|
-
#
|
23
|
-
# Usage:
|
24
|
-
#
|
25
|
-
# MethodGenerator.new(browser, opts).parse
|
26
|
-
#
|
27
|
-
#
|
28
|
-
class MethodGenerator
|
29
|
-
|
30
|
-
ELEMENTS = %w[text_field select_list radio checkbox button].map { |e| e.to_sym }
|
31
|
-
BUGGY_ELEMENTS = %w[radio checkbox].map { |e| e.to_sym }
|
32
|
-
|
33
|
-
def initialize(ie, opts = {})
|
34
|
-
@ie = ie
|
35
|
-
@opts = opts
|
36
|
-
@browser = @opts[:browser] || '@ie'
|
37
|
-
|
38
|
-
@docs = " # Fills in the page at #{@ie.url}\n #\n"
|
39
|
-
@docs << " # Parameters:\n #\n"
|
40
|
-
@doc_elements = []
|
41
|
-
|
42
|
-
@method = " def #{@opts[:method_name] || 'generated_method'}(opts = {})\n\n"
|
43
|
-
end
|
44
|
-
|
45
|
-
def parse
|
46
|
-
ELEMENTS.each do |elem|
|
47
|
-
@method << " # buggy!\n" if BUGGY_ELEMENTS.include?(elem)
|
48
|
-
add_elements(elem)
|
49
|
-
end
|
50
|
-
add_elements(:link) if @opts[:include_links]
|
51
|
-
@method << " end\n\n"
|
52
|
-
|
53
|
-
# fix docs
|
54
|
-
max = @doc_elements.map { |symbol, _| symbol.to_s.size }.max
|
55
|
-
@doc_elements.each do |sym, desc|
|
56
|
-
@docs << " # #{sym.to_s.ljust(max)} => #{desc}\n"
|
57
|
-
end
|
58
|
-
@docs << " #\n"*2
|
59
|
-
@docs + @method
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def add_elements(symbol)
|
65
|
-
symbol = symbol.to_sym
|
66
|
-
symbol_pluralized = symbol.to_s.pluralize.to_sym
|
67
|
-
@ie.send(symbol_pluralized).each_with_index do |elem, idx|
|
68
|
-
self.send("add_#{symbol}".to_sym, elem, idx)
|
69
|
-
end
|
70
|
-
|
71
|
-
@method << "\n"
|
72
|
-
end
|
73
|
-
|
74
|
-
def add_text_field(elem, idx)
|
75
|
-
how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
|
76
|
-
@method << " #{@browser}.text_field(#{how.inspect}, #{what.inspect}).value = "
|
77
|
-
symbol = (how == :index) ? ":text_field_#{what.underscore}" : ":#{what.underscore}"
|
78
|
-
@method << "opts[#{symbol}]\n"
|
79
|
-
@doc_elements << [symbol, "value for text field #{what.inspect}"]
|
80
|
-
end
|
81
|
-
|
82
|
-
def add_select_list(elem, idx)
|
83
|
-
how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
|
84
|
-
@method << " #{@browser}.select_list(#{how.inspect}, #{what.inspect}).select("
|
85
|
-
symbol = (how == :index) ? ":select_list_#{what.underscore}" : ":#{what.underscore}"
|
86
|
-
@method << "opts[#{symbol}])\n"
|
87
|
-
@doc_elements << [symbol, "option to select for select list #{what.inspect}"]
|
88
|
-
end
|
89
|
-
|
90
|
-
def add_radio(elem, idx)
|
91
|
-
how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
|
92
|
-
@method << " #{@browser}.radio(#{how.inspect}, #{what.inspect}, "
|
93
|
-
|
94
|
-
if (value = elem.value).empty?
|
95
|
-
symbol = (how == :index) ? ":radio_#{what.underscore}" : ":#{what.underscore}"
|
96
|
-
else
|
97
|
-
symbol = ":#{what.underscore}_#{value.underscore}"
|
98
|
-
@method << "#{value.inspect}).set if opts[#{symbol}]\n"
|
99
|
-
end
|
100
|
-
|
101
|
-
@doc_elements << [symbol, "set the radio with id/value #{what.inspect}"]
|
102
|
-
end
|
103
|
-
|
104
|
-
def add_checkbox(elem, idx)
|
105
|
-
how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
|
106
|
-
@method << " #{@browser}.checkbox(#{how.inspect}, #{what.inspect}, "
|
107
|
-
symbol = (how == :index) ? ":checkbox_#{what.underscore}" : ":#{what.underscore}"
|
108
|
-
@method << "#{elem.value.inspect}).set if opts[#{symbol}]\n"
|
109
|
-
|
110
|
-
@doc_elements << [symbol, "set the checkbox with id/value #{what.inspect}"]
|
111
|
-
end
|
112
|
-
|
113
|
-
def add_button(elem, idx)
|
114
|
-
how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
|
115
|
-
@method << " #{@browser}.button(#{how.inspect}, #{what.inspect}).click\n"
|
116
|
-
end
|
117
|
-
|
118
|
-
def add_link(elem, idx)
|
119
|
-
if (href = elem.href) =~ /javascript/
|
120
|
-
how, what = :index, (idx + 1).to_s
|
121
|
-
else
|
122
|
-
how = :url
|
123
|
-
|
124
|
-
begin
|
125
|
-
uri = URI.parse(href)
|
126
|
-
what = Regexp.new(Regexp.escape(uri.to_s.sub(/.*#{uri.host}\//, '')))
|
127
|
-
rescue URI::InvalidURIError
|
128
|
-
what = href
|
129
|
-
end
|
130
|
-
end
|
131
|
-
@method << " #{@browser}.link(#{how.inspect}, #{what.inspect}).click\n"
|
132
|
-
end
|
133
|
-
|
134
|
-
def find_identifier(element)
|
135
|
-
# could use ATTRIBUTES if they were 'weighted' somehow?
|
136
|
-
attrs = element.class::ATTRIBUTES
|
137
|
-
[:id, :name].each do |attribute|
|
138
|
-
return [attribute, element.send(attribute)] if attrs.include?(attribute) && !element.send(attribute).empty?
|
139
|
-
end
|
140
|
-
nil
|
141
|
-
end
|
142
|
-
|
143
|
-
end # MethodGenerator
|
144
|
-
|
145
|
-
class Browser
|
146
|
-
|
147
|
-
#
|
148
|
-
# Experimental - generate a method definition for accessing elements on the current page
|
149
|
-
# Not loaded by default - need to require 'celerity/extra/method_generator'
|
150
|
-
#
|
151
|
-
|
152
|
-
def generate_method(opts = {})
|
153
|
-
MethodGenerator.new(self, opts).parse
|
154
|
-
end
|
155
|
-
|
156
|
-
end # Browser
|
157
|
-
end # Celerity
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
# if __FILE__ == $0
|
162
|
-
# require File.dirname(__FILE__) + "/../spec/spec_helper"
|
163
|
-
# $stdout.sync = true
|
164
|
-
# @ie = Browser.new
|
165
|
-
# @ie.goto(HTML_DIR + "/forms_with_input_elements.html")
|
166
|
-
#
|
167
|
-
# puts MethodGenerator.new(@ie).parse
|
168
|
-
# @ie.goto(HTML_DIR + "/forms3.html")
|
169
|
-
# puts MethodGenerator.new(@ie).parse
|
170
|
-
# end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|