jarib-celerity 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +42 -0
- data/License.txt +621 -0
- data/README.txt +64 -0
- data/Rakefile +12 -0
- data/lib/celerity.rb +59 -0
- data/lib/celerity/browser.rb +410 -0
- data/lib/celerity/clickable_element.rb +26 -0
- data/lib/celerity/collections.rb +148 -0
- data/lib/celerity/container.rb +488 -0
- data/lib/celerity/default_viewer.rb +10 -0
- data/lib/celerity/disabled_element.rb +27 -0
- data/lib/celerity/element.rb +241 -0
- data/lib/celerity/element_collections.rb +68 -0
- data/lib/celerity/element_locator.rb +167 -0
- data/lib/celerity/elements/button.rb +34 -0
- data/lib/celerity/elements/file_field.rb +17 -0
- data/lib/celerity/elements/form.rb +16 -0
- data/lib/celerity/elements/frame.rb +53 -0
- data/lib/celerity/elements/image.rb +57 -0
- data/lib/celerity/elements/label.rb +9 -0
- data/lib/celerity/elements/link.rb +12 -0
- data/lib/celerity/elements/meta.rb +6 -0
- data/lib/celerity/elements/non_control_elements.rb +93 -0
- data/lib/celerity/elements/option.rb +18 -0
- data/lib/celerity/elements/radio_check.rb +85 -0
- data/lib/celerity/elements/select_list.rb +81 -0
- data/lib/celerity/elements/table.rb +117 -0
- data/lib/celerity/elements/table_cell.rb +28 -0
- data/lib/celerity/elements/table_elements.rb +41 -0
- data/lib/celerity/elements/table_row.rb +36 -0
- data/lib/celerity/elements/text_field.rb +127 -0
- data/lib/celerity/exception.rb +40 -0
- data/lib/celerity/extra/method_generator.rb +158 -0
- data/lib/celerity/htmlunit.rb +41 -0
- data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
- data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.4-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.4-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.10-20081209.100757-4.jar +0 -0
- data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
- data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
- data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
- data/lib/celerity/htmlunit/xercesImpl-2.8.1.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
- data/lib/celerity/identifier.rb +11 -0
- data/lib/celerity/input_element.rb +25 -0
- data/lib/celerity/listener.rb +106 -0
- data/lib/celerity/resources/no_viewer.png +0 -0
- data/lib/celerity/util.rb +79 -0
- data/lib/celerity/version.rb +9 -0
- data/lib/celerity/watir_compatibility.rb +85 -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 +57 -0
- data/tasks/rdoc.rake +4 -0
- data/tasks/rspec.rake +30 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/snapshot.rake +26 -0
- data/tasks/specserver.rake +21 -0
- data/tasks/website.rake +17 -0
- data/tasks/yard.rake +5 -0
- metadata +129 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module Celerity
|
2
|
+
Jars = Dir[File.dirname(__FILE__) + '/htmlunit/*.jar']
|
3
|
+
end
|
4
|
+
|
5
|
+
Celerity::Jars.each { |jar| require(jar) }
|
6
|
+
|
7
|
+
module HtmlUnit
|
8
|
+
include_package 'com.gargoylesoftware.htmlunit'
|
9
|
+
|
10
|
+
module Html
|
11
|
+
include_package 'com.gargoylesoftware.htmlunit.html'
|
12
|
+
end
|
13
|
+
|
14
|
+
module Util
|
15
|
+
include_package 'com.gargoylesoftware.htmlunit.util'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module Java::OrgW3cDom::NamedNodeMap
|
21
|
+
include Enumerable
|
22
|
+
|
23
|
+
def each
|
24
|
+
0.upto(getLength - 1) do |idx|
|
25
|
+
yield item(idx)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# this will be added in JRuby 1.1.6
|
31
|
+
module Java::JavaLang::Iterable
|
32
|
+
include Enumerable
|
33
|
+
|
34
|
+
def each
|
35
|
+
it = iterator
|
36
|
+
yield it.next while it.hasNext
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Celerity
|
2
|
+
class InputElement < Element
|
3
|
+
include ClickableElement
|
4
|
+
include DisabledElement
|
5
|
+
|
6
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:type, :name, :value, :checked, :disabled, :readonly, :size, :maxlength,
|
7
|
+
:src, :alt, :usemap, :ismap, :tabindex, :accesskey, :onfocus, :onblur,
|
8
|
+
:onselect, :onchange, :accept, :align]
|
9
|
+
|
10
|
+
def readonly?
|
11
|
+
assert_exists
|
12
|
+
@object.isAttributeDefined('readonly')
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def assert_not_readonly
|
18
|
+
if readonly?
|
19
|
+
raise ObjectReadOnlyException,
|
20
|
+
"InputElement #{identifier_string} is read only."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Celerity
|
2
|
+
|
3
|
+
# This class is used to wrap some of the various listeners available
|
4
|
+
# from HtmlUnit's WebClient.
|
5
|
+
class Listener
|
6
|
+
include com.gargoylesoftware.htmlunit.AlertHandler
|
7
|
+
include com.gargoylesoftware.htmlunit.ConfirmHandler
|
8
|
+
include com.gargoylesoftware.htmlunit.PromptHandler
|
9
|
+
include com.gargoylesoftware.htmlunit.html.HTMLParserListener
|
10
|
+
include com.gargoylesoftware.htmlunit.IncorrectnessListener
|
11
|
+
include com.gargoylesoftware.htmlunit.StatusHandler
|
12
|
+
include com.gargoylesoftware.htmlunit.WebWindowListener
|
13
|
+
include com.gargoylesoftware.htmlunit.attachment.AttachmentHandler
|
14
|
+
|
15
|
+
def initialize(webclient)
|
16
|
+
@webclient = webclient
|
17
|
+
@procs = Hash.new { |h, k| h[k] = [] }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add a listener block for one of the available types.
|
21
|
+
# @see Celerity::Browser#add_listener
|
22
|
+
def add_listener(type, &block)
|
23
|
+
case type
|
24
|
+
when :status
|
25
|
+
@webclient.setStatusHandler(self)
|
26
|
+
when :alert
|
27
|
+
@webclient.setAlertHandler(self)
|
28
|
+
when :attachment
|
29
|
+
@webclient.setAttachmentHandler(self)
|
30
|
+
when :web_window_event
|
31
|
+
@webclient.addWebWindowListener(self)
|
32
|
+
when :html_parser
|
33
|
+
@webclient.setHTMLParserListener(self)
|
34
|
+
when :incorrectness
|
35
|
+
@webclient.setIncorrectnessListener(self)
|
36
|
+
when :confirm
|
37
|
+
@webclient.setConfirmHandler(self)
|
38
|
+
when :prompt
|
39
|
+
@webclient.setPromptHandler(self)
|
40
|
+
else
|
41
|
+
raise ArgumentError, "unknown listener type #{type.inspect}"
|
42
|
+
end
|
43
|
+
|
44
|
+
@procs[type] << block
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove_listener(type, proc_or_index)
|
48
|
+
unless @procs.has_key?(type)
|
49
|
+
raise ArgumentError, "unknown listener type #{type.inspect}"
|
50
|
+
end
|
51
|
+
|
52
|
+
case proc_or_index
|
53
|
+
when Fixnum
|
54
|
+
@procs[type].delete_at proc_or_index
|
55
|
+
when Proc
|
56
|
+
@procs[type].delete proc_or_index
|
57
|
+
else
|
58
|
+
raise TypeError, "must give proc or index"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# interface StatusHandler
|
63
|
+
def statusMessageChanged(page, message)
|
64
|
+
@procs[:status].each { |h| h.call(page, message) }
|
65
|
+
end
|
66
|
+
|
67
|
+
# interface AlertHandler
|
68
|
+
def handleAlert(page, message)
|
69
|
+
@procs[:alert].each { |h| h.call(page, message) }
|
70
|
+
end
|
71
|
+
|
72
|
+
# interface ConfirmHandler
|
73
|
+
def handleConfirm(page, message)
|
74
|
+
@procs[:confirm].each { |h| h.call(page, message) }
|
75
|
+
end
|
76
|
+
|
77
|
+
# interface AttachmentHandler
|
78
|
+
def handleAttachment(page)
|
79
|
+
@procs[:attachment].each { |h| h.call(page) }
|
80
|
+
end
|
81
|
+
|
82
|
+
# interface PromptHandler
|
83
|
+
def handlePrompt(page, message)
|
84
|
+
@procs[:prompt].each { |h| h.call(page, message) }
|
85
|
+
end
|
86
|
+
|
87
|
+
# interface WebWindowListener
|
88
|
+
def webWindowClosed(web_window_event)
|
89
|
+
@procs[:web_window_event].each { |h| h.call(web_window_event) }
|
90
|
+
end
|
91
|
+
alias_method :webWindowOpened, :webWindowClosed
|
92
|
+
alias_method :webWindowContentChanged, :webWindowClosed
|
93
|
+
|
94
|
+
# interface HTMLParserListener
|
95
|
+
def error(message, url, line, column, key)
|
96
|
+
@procs[:html_parser].each { |h| h.call(message, url, line, column, key) }
|
97
|
+
end
|
98
|
+
alias_method :warning, :error
|
99
|
+
|
100
|
+
# interface IncorrectnessListener
|
101
|
+
def notify(message, origin)
|
102
|
+
@procs[:incorrectness].each { |h| h.call(message, origin) }
|
103
|
+
end
|
104
|
+
|
105
|
+
end # Listener
|
106
|
+
end # Celerity
|
Binary file
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Celerity
|
2
|
+
module Util
|
3
|
+
module_function
|
4
|
+
|
5
|
+
HtmlUnit2CelerityElement = {
|
6
|
+
HtmlUnit::Html::HtmlAnchor => Celerity::Link,
|
7
|
+
HtmlUnit::Html::HtmlArea => Celerity::Area,
|
8
|
+
HtmlUnit::Html::HtmlButton => Celerity::Button,
|
9
|
+
HtmlUnit::Html::HtmlButtonInput => Celerity::Button,
|
10
|
+
HtmlUnit::Html::HtmlCaption => Celerity::Button, # ?
|
11
|
+
HtmlUnit::Html::HtmlCheckBoxInput => Celerity::CheckBox,
|
12
|
+
HtmlUnit::Html::HtmlDivision => Celerity::Div,
|
13
|
+
HtmlUnit::Html::HtmlFileInput => Celerity::FileField,
|
14
|
+
HtmlUnit::Html::HtmlForm => Celerity::Form,
|
15
|
+
HtmlUnit::Html::HtmlFrame => Celerity::Frame,
|
16
|
+
HtmlUnit::Html::HtmlHeading1 => Celerity::H1,
|
17
|
+
HtmlUnit::Html::HtmlHeading2 => Celerity::H2,
|
18
|
+
HtmlUnit::Html::HtmlHeading3 => Celerity::H3,
|
19
|
+
HtmlUnit::Html::HtmlHeading4 => Celerity::H4,
|
20
|
+
HtmlUnit::Html::HtmlHeading5 => Celerity::H5,
|
21
|
+
HtmlUnit::Html::HtmlHeading6 => Celerity::H6,
|
22
|
+
HtmlUnit::Html::HtmlHiddenInput => Celerity::Hidden,
|
23
|
+
HtmlUnit::Html::HtmlImage => Celerity::Image,
|
24
|
+
HtmlUnit::Html::HtmlLabel => Celerity::Label,
|
25
|
+
HtmlUnit::Html::HtmlLink => Celerity::Link,
|
26
|
+
HtmlUnit::Html::HtmlListItem => Celerity::Li,
|
27
|
+
HtmlUnit::Html::HtmlMap => Celerity::Map,
|
28
|
+
HtmlUnit::Html::HtmlOption => Celerity::Option,
|
29
|
+
HtmlUnit::Html::HtmlOrderedList => Celerity::Ol,
|
30
|
+
HtmlUnit::Html::HtmlParagraph => Celerity::P,
|
31
|
+
HtmlUnit::Html::HtmlPasswordInput => Celerity::TextField,
|
32
|
+
HtmlUnit::Html::HtmlPreformattedText => Celerity::Pre,
|
33
|
+
HtmlUnit::Html::HtmlRadioButtonInput => Celerity::Radio,
|
34
|
+
HtmlUnit::Html::HtmlSelect => Celerity::SelectList,
|
35
|
+
HtmlUnit::Html::HtmlSpan => Celerity::Span,
|
36
|
+
HtmlUnit::Html::HtmlTable => Celerity::Table,
|
37
|
+
HtmlUnit::Html::HtmlTableBody => Celerity::TableBody,
|
38
|
+
HtmlUnit::Html::HtmlTableCell => Celerity::TableCell,
|
39
|
+
HtmlUnit::Html::HtmlTableFooter => Celerity::TableFooter,
|
40
|
+
HtmlUnit::Html::HtmlTableHeader => Celerity::TableHeader,
|
41
|
+
HtmlUnit::Html::HtmlTableRow => Celerity::TableRow,
|
42
|
+
HtmlUnit::Html::HtmlTextArea => Celerity::Area,
|
43
|
+
HtmlUnit::Html::HtmlTextInput => Celerity::TextField,
|
44
|
+
HtmlUnit::Html::HtmlUnorderedList => Celerity::Ul
|
45
|
+
}
|
46
|
+
|
47
|
+
def htmlunit2celerity(klass)
|
48
|
+
HtmlUnit2CelerityElement[klass]
|
49
|
+
end
|
50
|
+
|
51
|
+
# HtmlUnit will recognize most common file types, but custom ones can be added here.
|
52
|
+
# Used for FileField uploads.
|
53
|
+
ContentTypes = {
|
54
|
+
".bmp" => "image/x-ms-bmp",
|
55
|
+
".doc" => "application/msword",
|
56
|
+
".odg" => "application/vnd.oasis.opendocument.graphics",
|
57
|
+
".odp" => "application/vnd.oasis.opendocument.presentation",
|
58
|
+
".ods" => "application/vnd.oasis.opendocument.spreadsheet",
|
59
|
+
".odt" => "application/vnd.oasis.opendocument.text",
|
60
|
+
".ppt" => "application/vnd.ms-powerpoint",
|
61
|
+
".xls" => "application/vnd.ms-excel",
|
62
|
+
}
|
63
|
+
|
64
|
+
def content_type_for(path)
|
65
|
+
if ct = java.net.URLConnection.getFileNameMap.getContentTypeFor(path)
|
66
|
+
return ct
|
67
|
+
else
|
68
|
+
ContentTypes[File.extname(path).downcase]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def normalize_text(string)
|
73
|
+
string.gsub("\302\240", ' '). # non-breaking space 00A0
|
74
|
+
gsub(/\n|\t/, '' ). # get rid of newlines/tabs ( could switch back to asText()? )
|
75
|
+
strip
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Celerity
|
2
|
+
class Browser
|
3
|
+
class << self
|
4
|
+
# Added for Watir compatability - not in use by Celerity
|
5
|
+
attr_accessor :speed, :attach_timeout, :visible
|
6
|
+
# Added for Watir compatability - not in use by Celerity
|
7
|
+
alias_method :start_window, :start
|
8
|
+
# Added for Watir compatability - not in use by Celerity
|
9
|
+
def reset_attach_timeout; @attach_timeout = 2.0; end
|
10
|
+
# Added for Watir compatability - not in use by Celerity
|
11
|
+
def each; end
|
12
|
+
# Added for Watir compatability - not in use by Celerity
|
13
|
+
def quit; end
|
14
|
+
# Added for Watir compatability - not in use by Celerity
|
15
|
+
def set_fast_speed; @speed = :fast; end
|
16
|
+
# Added for Watir compatability - not in use by Celerity
|
17
|
+
def set_slow_speed; @speed = :slow; end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Added for Watir compatability - not in use by Celerity
|
21
|
+
attr_accessor :visible
|
22
|
+
|
23
|
+
# Added for Watir compatability - not in use by Celerity
|
24
|
+
def bring_to_front; true; end
|
25
|
+
# Added for Watir compatability - not in use by Celerity
|
26
|
+
def speed=(s); s end
|
27
|
+
# Added for Watir compatability - not in use by Celerity
|
28
|
+
def wait; end
|
29
|
+
# Added for Watir compatability - not in use by Celerity
|
30
|
+
def status; '' end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
module ClickableElement
|
35
|
+
alias_method :click_no_wait, :click
|
36
|
+
end
|
37
|
+
|
38
|
+
module Container
|
39
|
+
alias_method :checkbox, :check_box
|
40
|
+
alias_method :checkBox, :check_box
|
41
|
+
alias_method :body, :tbody
|
42
|
+
alias_method :bodies, :tbodies
|
43
|
+
end
|
44
|
+
|
45
|
+
class Element
|
46
|
+
alias_method :exists, :exists?
|
47
|
+
alias_method :innerText, :text
|
48
|
+
alias_method :inner_text, :text
|
49
|
+
end
|
50
|
+
|
51
|
+
class Image
|
52
|
+
alias_method :hasLoaded?, :loaded?
|
53
|
+
alias_method :has_loaded?, :loaded?
|
54
|
+
alias_method :fileSize, :file_size
|
55
|
+
alias_method :fileCreatedDate, :file_created_date
|
56
|
+
end
|
57
|
+
|
58
|
+
class Link
|
59
|
+
alias_method :click_no_wait, :click
|
60
|
+
end
|
61
|
+
|
62
|
+
class RadioCheckCommon
|
63
|
+
alias_method :is_set?, :set?
|
64
|
+
alias_method :get_state, :set?
|
65
|
+
alias_method :isSet?, :set?
|
66
|
+
alias_method :getState, :set?
|
67
|
+
end
|
68
|
+
|
69
|
+
class SelectList
|
70
|
+
alias_method :getSelectedItems, :selected_options
|
71
|
+
alias_method :getAllContents, :options
|
72
|
+
alias_method :clearSelection, :clear
|
73
|
+
alias_method :clear_selection, :clear
|
74
|
+
alias_method :select_value, :select
|
75
|
+
alias_method :includes?, :include?
|
76
|
+
end
|
77
|
+
|
78
|
+
class TextField
|
79
|
+
alias_method :dragContentsTo, :drag_contents_to
|
80
|
+
alias_method :getContents, :value
|
81
|
+
alias_method :get_contents, :value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Celerity::IE = Celerity::Browser
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#desc 'Release the website and new gem version'
|
2
|
+
#task :deploy => [:check_version, :website, :release] do
|
3
|
+
# puts "Remember to create SVN tag:"
|
4
|
+
# puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
# "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
# puts "Suggested comment:"
|
7
|
+
# puts "Tagging release #{CHANGES}"
|
8
|
+
#end
|
9
|
+
|
10
|
+
desc 'Builds and installs gem locally'
|
11
|
+
task :local_deploy => [:install_gem]
|
12
|
+
|
13
|
+
#task :check_version do
|
14
|
+
# unless ENV['VERSION']
|
15
|
+
# puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
# exit
|
17
|
+
# end
|
18
|
+
# unless ENV['VERSION'] == VERS
|
19
|
+
# puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
# exit
|
21
|
+
# end
|
22
|
+
#end
|
23
|
+
|
24
|
+
#desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
#task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
# sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
#end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
desc 'Create new Manifest.txt in diff format'
|
35
|
+
task :new do
|
36
|
+
manifest = File.new('Manifest.txt', 'w+')
|
37
|
+
Dir.glob(File.join("**", "*")).each do |f|
|
38
|
+
manifest.puts f
|
39
|
+
end
|
40
|
+
manifest.flush
|
41
|
+
puts "####\n# Remember to edit Manifest.txt and remove unwanted file entries!\n####"
|
42
|
+
end
|
43
|
+
end
|