celerity 0.9.0 → 0.9.1

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.
Files changed (56) hide show
  1. data/.document +5 -0
  2. data/.gitignore +9 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +253 -596
  7. data/README.rdoc +8 -4
  8. data/Rakefile +5 -1
  9. data/benchmark/bm_2000_spans.rb +48 -0
  10. data/benchmark/bm_digg.rb +26 -0
  11. data/benchmark/bm_google_images.rb +36 -0
  12. data/benchmark/bm_input_locator.rb +69 -0
  13. data/benchmark/bm_text_input.rb +19 -0
  14. data/benchmark/loader.rb +14 -0
  15. data/celerity.gemspec +18 -114
  16. data/lib/celerity.rb +1 -3
  17. data/lib/celerity/htmlunit/commons-lang3-3.0.1.jar +0 -0
  18. data/lib/celerity/htmlunit/cssparser-0.9.6-20110829.205617-3.jar +0 -0
  19. data/lib/celerity/htmlunit/{htmlunit-2.9.jar → htmlunit-2.10-SNAPSHOT.jar} +0 -0
  20. data/lib/celerity/version.rb +1 -1
  21. data/spec/browser_authentication_spec.rb +16 -0
  22. data/spec/browser_spec.rb +428 -0
  23. data/spec/button_spec.rb +24 -0
  24. data/spec/clickable_element_spec.rb +39 -0
  25. data/spec/default_viewer_spec.rb +23 -0
  26. data/spec/element_spec.rb +77 -0
  27. data/spec/filefield_spec.rb +18 -0
  28. data/spec/htmlunit_spec.rb +63 -0
  29. data/spec/implementation.rb +7 -0
  30. data/spec/index_offset_spec.rb +24 -0
  31. data/spec/link_spec.rb +16 -0
  32. data/spec/listener_spec.rb +142 -0
  33. data/spec/spec_helper.rb +6 -0
  34. data/spec/table_spec.rb +41 -0
  35. data/spec/watir_compatibility_spec.rb +32 -0
  36. data/tasks/snapshot.rake +1 -1
  37. data/website/benchmarks.html +237 -0
  38. data/website/css/color.css +153 -0
  39. data/website/css/hacks.css +3 -0
  40. data/website/css/layout.css +179 -0
  41. data/website/css/screen.css +5 -0
  42. data/website/css/textmate.css +226 -0
  43. data/website/css/typography.css +72 -0
  44. data/website/gfx/body_bg.gif +0 -0
  45. data/website/gfx/button_bg.jpg +0 -0
  46. data/website/gfx/header_bg.jpg +0 -0
  47. data/website/gfx/header_left.jpg +0 -0
  48. data/website/gfx/header_right.jpg +0 -0
  49. data/website/gfx/nav_bg.jpg +0 -0
  50. data/website/index.html +125 -0
  51. data/website/yard/index.html +1 -0
  52. metadata +69 -22
  53. data/VERSION.yml +0 -5
  54. data/lib/celerity/htmlunit/commons-lang-2.6.jar +0 -0
  55. data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  56. data/tasks/jeweler.rake +0 -28
@@ -0,0 +1,39 @@
1
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
2
+
3
+ describe "ClickableElement" do
4
+
5
+ before :each do
6
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
7
+ end
8
+
9
+ describe "#click_and_attach" do
10
+ it 'opens a page in a new browser with the same options' do
11
+ b = browser.link(:name, /bad_attribute/).click_and_attach
12
+ b.text.include?("User administration").should be_true # to make sure it is open.
13
+ b.options.should == browser.options
14
+ b.cookies.should == browser.cookies
15
+ end
16
+
17
+ it "opens the page in a new browser with the same cookies" do
18
+ browser.add_cookie("localhost", "foo", "bar")
19
+ old_cookies = browser.cookies
20
+ old_cookies.should_not be_empty
21
+
22
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
23
+ b = browser.link(:name, /bad_attribute/).click_and_attach
24
+
25
+ b.should_not == browser
26
+ b.cookies.should == old_cookies
27
+ end
28
+ end
29
+
30
+ describe "#download" do
31
+ it 'returns a click-opened page as io' do
32
+ expected = File.read "#{WatirSpec.files}/forms_with_input_elements.html".sub("file://", '')
33
+
34
+ browser.link(:name, /bad_attribute/).download.read.should == expected
35
+ browser.link(:name, /bad_attribute/).should exist
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
2
+
3
+ describe "DefaultViewer" do
4
+
5
+ before :all do
6
+ browser.goto(WatirSpec.files + "/definition_lists.html")
7
+ end
8
+
9
+ describe ".save" do
10
+ it "saves the default image to the given path" do
11
+ fail("don't run specs with CelerityViewer") if browser.viewer != Celerity::DefaultViewer
12
+ fname = File.expand_path "default_viewer_test.png"
13
+ default = "#{File.dirname(__FILE__)}/../lib/celerity/resources/no_viewer.png"
14
+
15
+ browser.viewer.save(fname)
16
+ File.exist?(fname).should be_true
17
+ File.read(fname).should == File.read(default)
18
+
19
+ File.delete(fname)
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
3
+
4
+ describe "Element" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#identifier_string" do
11
+ it "doesn't make the next locate find the wrong element" do
12
+ elem = browser.div(:id, 'hidden_parent')
13
+ elem.should exist
14
+ elem.__send__(:identifier_string)
15
+ elem.id.should == 'hidden_parent'
16
+ end
17
+
18
+ it "uses the user specified identifier_string if one is present" do
19
+ elem = browser.div(:id, 'hidden_parent')
20
+ elem.identifier_string = "this is it"
21
+ elem.__send__(:identifier_string).should == "this is it"
22
+ end
23
+ end
24
+
25
+ describe "#method_missing" do
26
+ it "magically returns the requested attribute if the attribute is defined in the attribute list" do
27
+ browser.form(:index, Celerity.index_offset).action.should == 'post_to_me'
28
+ end
29
+
30
+ it "raises NoMethodError if the requested method isn't among the attributes" do
31
+ lambda { browser.button(:index, Celerity.index_offset).no_such_attribute_or_method }.should raise_error(NoMethodError)
32
+ end
33
+ end
34
+
35
+ describe "#xpath" do
36
+ it "gets the canonical xpath of this element" do
37
+ browser.text_field(:id, "new_user_email").xpath.should == '/html/body/form[1]/fieldset[1]/input[3]'
38
+ end
39
+ end
40
+
41
+ describe "#javascript_object" do
42
+ it "should return the JavaScript object representing the receiver" do
43
+ obj = browser.div(:id, "onfocus_test").javascript_object
44
+ obj.should be_kind_of(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)
45
+ obj.should be_instance_of(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDivElement)
46
+ obj.client_width.should be_kind_of(Integer)
47
+ end
48
+ end
49
+
50
+ describe "#locate" do
51
+ it "raises ArgumentError when used with :object and the object given isn't an HtmlElement subclass" do
52
+ lambda { Link.new(browser, :object, "foo").locate }.should raise_error(ArgumentError)
53
+ end
54
+ end
55
+
56
+ describe "#focused?" do
57
+ it "returns true if the element has focus" do
58
+ tf = browser.text_field(:id, "delete_user_comment")
59
+ tf.should_not be_focused
60
+
61
+ tf.focus
62
+ tf.should be_focused
63
+ end
64
+
65
+ end
66
+
67
+ describe "#==" do
68
+ it "returns true if passed the same element" do
69
+ browser.label(:id, 'first_label').should == browser.labels.first
70
+ end
71
+
72
+ it "returns false if passed a different element" do
73
+ browser.label(:id, 'first_label').should_not == browser.labels.last
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
3
+
4
+ describe "FileField" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#set" do
11
+ it "sends content as correct content type for common file types" do
12
+ browser.file_field(:name, "new_user_portrait").set("foo.doc")
13
+ obj = browser.file_field(:name, "new_user_portrait").locate
14
+ obj.getContentType.should == "application/msword"
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
2
+
3
+ describe "HtmlUnit bugs" do
4
+ describe "HtmlUnit bug 1968686: https://sourceforge.net/tracker/index.php?func=detail&aid=1968686&group_id=47038&atid=448266" do
5
+ it "does not raise NativeException: java.lang.StackOverflowError when going to a page where Javascripts prints a <body> tag inside another <body> tag" do
6
+ lambda { browser.goto(WatirSpec.files + "/bug_javascript_001.html") }.should_not raise_error(NativeException)
7
+ end
8
+ end
9
+
10
+ describe "HtmlUnit bug 1968708: https://sourceforge.net/tracker/index.php?func=detail&aid=1968708&group_id=47038&atid=448266" do
11
+ it "only considers the first attribute if there are duplicate attributes" do
12
+ browser.goto(WatirSpec.files + "/bug_duplicate_attributes.html")
13
+ browser.text_field(:index, Celerity.index_offset).id.should == "org_id"
14
+ end
15
+ end
16
+
17
+ describe "NekoHtml parser bug: https://sourceforge.net/tracker/?func=detail&aid=2824922&group_id=47038&atid=448266" do
18
+ it "does not run out of java heap space" do
19
+ lambda { browser.goto(WatirSpec.files + "/parser_bug_001.html") }.should_not raise_error
20
+ end
21
+ end
22
+
23
+ # disabled for CI - need fix from HtmlUnit
24
+ # describe "HtmlUnit bug XXXXXX" do
25
+ # it "returns strings as UTF-8 when there's a charset mismatch between HTTP response header and <meta> tag" do
26
+ # browser.goto(WatirSpec.host + "/charset_mismatch")
27
+ # browser.h1(:index, 1).text.should == "\303\270"
28
+ # end
29
+ # end
30
+
31
+ it "evaluates <script> tags injected in the DOM through JQuery's replaceWith() - fixed in rev. 3598" do
32
+ browser.goto(WatirSpec.files + "/jquery.html")
33
+ browser.link(:class, 'editLink').click
34
+ browser.div(:id, 'content').text.should == "typeof update: function"
35
+ end
36
+
37
+ it "doesn't return the TinyMCE DOM when executing javascript functions" do
38
+ b = WatirSpec.new_browser
39
+
40
+ b.goto(WatirSpec.files + "/tiny_mce.html")
41
+ b.text.should include("Beskrivelse")
42
+ b.checkbox(:id, "exemption").set
43
+ b.text.should include("Beskrivelse")
44
+
45
+ b.close
46
+ end
47
+
48
+ describe "HtmlUnit bug 2811607: https://sourceforge.net/tracker/?func=detail&aid=2811607&group_id=47038&atid=448266" do
49
+ it "correctly prevents default on <form>#submit()" do
50
+ browser.goto(WatirSpec.files + "/prevent_form_submit.html")
51
+ browser.button(:id, "next").click
52
+ browser.title.should == "preventDefault() on form submission"
53
+ end
54
+ end
55
+
56
+ describe "HtmlUnit bug 2974355: https://sourceforge.net/tracker/index.php?func=detail&aid=2974355&group_id=47038&atid=448266" do
57
+ it "accesses pages with characters in URI that need encoding" do
58
+ browser.goto(WatirSpec.host + '/encodable_%3Cstuff%3E')
59
+ browser.text.should include('page with characters in URI that need encoding')
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ WatirSpec.implementation do |imp|
4
+ imp.name = :celerity
5
+ imp.browser_class = Celerity::Browser
6
+ imp.browser_args = [{ :log_level => $DEBUG ? :all : :off }]
7
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
2
+
3
+ describe "Celerity.index_offset" do
4
+
5
+ # before :all do
6
+ # browser.goto(WatirSpec.files + "/non_control_elements.html")
7
+ #
8
+ # Celerity.index_offset = 0
9
+ # end
10
+ #
11
+ # it "returns the correct divs" do
12
+ # divs = browser.divs.to_a
13
+ #
14
+ # divs.each_with_index do |div, idx|
15
+ # browser.div(:index, idx).id.should == div.id
16
+ # end
17
+ # end
18
+ #
19
+ # after :all do
20
+ # Celerity.index_offset = 1
21
+ # end
22
+
23
+ end
24
+
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
3
+
4
+ describe "Link" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ describe "absolute_url" do
11
+ it "returns the absolute URL for a link with a relative href attribute" do
12
+ browser.link(:index, Celerity.index_offset + 1).absolute_url.should include("#{WatirSpec.files}/non_control_elements.html".gsub("file://", ''))
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,142 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "Listener" do
4
+ before(:each) do
5
+ @web_client = mock("WebClient").as_null_object
6
+ @listener = Celerity::Listener.new(@web_client)
7
+ end
8
+
9
+ it "implements the StatusHandler interface" do
10
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.StatusHandler)
11
+
12
+ @listener.should respond_to(:statusMessageChanged)
13
+ lambda { @listener.statusMessageChanged('page', 'message') }.should_not raise_error
14
+ end
15
+
16
+ it "implements the ConfirmHandler interface" do
17
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.ConfirmHandler)
18
+
19
+ @listener.should respond_to(:handleConfirm)
20
+ lambda { @listener.handleConfirm('page', 'message') }.should_not raise_error
21
+ end
22
+
23
+ it "implements the AttachmentHandler interface" do
24
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.attachment.AttachmentHandler)
25
+
26
+ @listener.should respond_to(:handleAttachment)
27
+ lambda { @listener.handleAttachment('page') }.should_not raise_error
28
+ end
29
+
30
+ it "implements the AlertHandler interface" do
31
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.AlertHandler)
32
+
33
+ @listener.should respond_to(:handleAlert)
34
+ lambda { @listener.handleAlert('page', 'message') }.should_not raise_error
35
+ end
36
+
37
+ it "implements the HTMLParserListener interface" do
38
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.html.HTMLParserListener)
39
+
40
+ @listener.should respond_to(:error)
41
+ @listener.should respond_to(:warning)
42
+
43
+ lambda { @listener.error('message', 'url', 1, 2, "key") }.should_not raise_error
44
+ lambda { @listener.warning('message', 'url', 1, 2, "key") }.should_not raise_error
45
+ end
46
+
47
+ it "implements the WebWindowListener interface" do
48
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.WebWindowListener)
49
+
50
+ @listener.should respond_to(:webWindowClosed)
51
+ @listener.should respond_to(:webWindowContentChanged)
52
+ @listener.should respond_to(:webWindowOpened)
53
+
54
+ lambda { @listener.webWindowClosed('event') }.should_not raise_error
55
+ lambda { @listener.webWindowContentChanged('event') }.should_not raise_error
56
+ lambda { @listener.webWindowOpened('event') }.should_not raise_error
57
+ end
58
+
59
+ it "implements the IncorrectnessListener interface" do
60
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.IncorrectnessListener)
61
+
62
+ @listener.should respond_to(:notify)
63
+ lambda { @listener.notify('message', 'origin') }.should_not raise_error
64
+ end
65
+
66
+ it "implements the PromptHandler interface" do
67
+ @listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.PromptHandler)
68
+
69
+ @listener.should respond_to(:handlePrompt)
70
+ lambda { @listener.handlePrompt('page', 'message') }.should_not raise_error
71
+ end
72
+
73
+
74
+ describe "#add_listener" do
75
+ it "adds itself as a listener for the :status type" do
76
+ @web_client.should_receive('setStatusHandler').with(@listener)
77
+ @listener.add_listener(:status) {}
78
+ end
79
+
80
+ it "adds itself as a listener for the :alert type" do
81
+ @web_client.should_receive('setAlertHandler').with(@listener)
82
+ @listener.add_listener(:alert) {}
83
+ end
84
+
85
+ it "adds itself as a listener for the :confirm type" do
86
+ @web_client.should_receive('setConfirmHandler').with(@listener)
87
+ @listener.add_listener(:confirm) {}
88
+ end
89
+
90
+ it "adds itself as a listener for the :prompt type" do
91
+ @web_client.should_receive('setPromptHandler').with(@listener)
92
+ @listener.add_listener(:prompt) {}
93
+ end
94
+
95
+ it "adds itself as a listener for the :web_window_event type" do
96
+ @web_client.should_receive('addWebWindowListener').with(@listener)
97
+ @listener.add_listener(:web_window_event) {}
98
+ end
99
+
100
+ it "adds itself as a listener for the :html_parser type" do
101
+ @web_client.should_receive('setHTMLParserListener').with(@listener)
102
+ @listener.add_listener(:html_parser) {}
103
+ end
104
+
105
+ it "adds itself as a listener for the :incorrectness type" do
106
+ @web_client.should_receive('setIncorrectnessListener').with(@listener)
107
+ @listener.add_listener(:incorrectness) {}
108
+ end
109
+
110
+ it "adds itself as a listener for the :attachment type" do
111
+ @web_client.should_receive('setAttachmentHandler').with(@listener)
112
+ @listener.add_listener(:attachment) {}
113
+ end
114
+ end
115
+
116
+ describe "#remove_listener" do
117
+ it "removes the listener at the given index" do
118
+ updates = []
119
+ first, second = lambda { updates << :first }, lambda { updates << :second }
120
+
121
+ @listener.add_listener(:prompt, &first)
122
+ @listener.add_listener(:prompt, &second)
123
+
124
+ @listener.remove_listener(:prompt, 0)
125
+ @listener.handlePrompt('foo', 'bar')
126
+ updates.should == [:second]
127
+ end
128
+ end
129
+
130
+ it "handles several invocations of all registered listeners" do
131
+ updates = []
132
+ @listener.add_listener(:alert) { updates << :first }
133
+ @listener.add_listener(:alert) { updates << :second }
134
+
135
+ @listener.handleAlert('foo', 'bar')
136
+ updates.should == [:first, :second]
137
+
138
+ @listener.handleAlert('foo', 'bar')
139
+ updates.should == [:first, :second, :first, :second]
140
+ end
141
+
142
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
2
+ require 'celerity'
3
+
4
+ include Celerity
5
+ include Celerity::Exception
6
+ java.lang.System.setProperty("java.awt.headless", "true")
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../watirspec/spec_helper", __FILE__)
3
+
4
+ describe "Table" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/tables.html")
8
+ end
9
+
10
+ describe "#locate" do
11
+ it "is not nil for existing tables" do
12
+ browser.table(:id, 'axis_example').locate.should_not be_nil
13
+ end
14
+ end
15
+
16
+ it "finds table data cells through #parent" do
17
+ browser.span(:id => "cell-child").parent.should be_kind_of(Celerity::TableCell)
18
+ end
19
+
20
+ describe "#cells" do
21
+ it "doesn't find cells in nested tables" do
22
+ browser.table(:id => "outer").cells.length.should == 6
23
+ end
24
+
25
+ it "doesn't find cells in nested tables (for rows)" do
26
+ browser.table(:id => "outer").row(:id => "outer_second").cells.length.should == 2
27
+ end
28
+ end
29
+
30
+ describe "#tds" do
31
+ it "doesn't find cells in nested tables" do
32
+ browser.table(:id => "outer").tds.length.should == 6
33
+ end
34
+
35
+ it "doesn't find cells in nested tables (for rows)" do
36
+ browser.table(:id => "outer").row(:id => "outer_second").tds.length.should == 2
37
+ end
38
+ end
39
+
40
+ end
41
+