fletcherm-culerity 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGES.md +7 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +102 -0
  5. data/Rakefile +47 -0
  6. data/VERSION.yml +5 -0
  7. data/culerity.gemspec +165 -0
  8. data/features/fixtures/jquery +4376 -0
  9. data/features/fixtures/sample_feature +14 -0
  10. data/features/installing_culerity.feature +36 -0
  11. data/features/running_cucumber_without_explicitly_running_external_services.feature +23 -0
  12. data/features/step_definitions/common_steps.rb +175 -0
  13. data/features/step_definitions/culerity_setup_steps.rb +7 -0
  14. data/features/step_definitions/jruby_steps.rb +11 -0
  15. data/features/step_definitions/rails_setup_steps.rb +36 -0
  16. data/features/support/common.rb +32 -0
  17. data/features/support/env.rb +24 -0
  18. data/features/support/matchers.rb +11 -0
  19. data/init.rb +1 -0
  20. data/lib/culerity.rb +44 -0
  21. data/lib/culerity/celerity_server.rb +81 -0
  22. data/lib/culerity/jruby_runner.rb +13 -0
  23. data/lib/culerity/remote_browser_proxy.rb +58 -0
  24. data/lib/culerity/remote_object_proxy.rb +76 -0
  25. data/rails/init.rb +1 -0
  26. data/rails_generators/culerity/culerity_generator.rb +28 -0
  27. data/rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb +28 -0
  28. data/rails_generators/culerity/templates/config/environments/culerity_development.rb +17 -0
  29. data/rails_generators/culerity/templates/features/step_definitions/culerity_steps.rb +109 -0
  30. data/rails_generators/culerity/templates/features/support/env.rb +9 -0
  31. data/rails_generators/culerity/templates/lib/tasks/culerity.rake +38 -0
  32. data/rails_generators/culerity/templates/public/javascripts/culerity.js +27 -0
  33. data/script/console +10 -0
  34. data/script/destroy +14 -0
  35. data/script/generate +14 -0
  36. data/spec/celerity_server_spec.rb +106 -0
  37. data/spec/culerity_spec.rb +33 -0
  38. data/spec/jruby_runner_spec.rb +12 -0
  39. data/spec/remote_browser_proxy_spec.rb +62 -0
  40. data/spec/remote_object_proxy_spec.rb +63 -0
  41. data/spec/spec_helper.rb +3 -0
  42. data/vendor/gems/celerity-0.7.6/HISTORY +111 -0
  43. data/vendor/gems/celerity-0.7.6/LICENSE +621 -0
  44. data/vendor/gems/celerity-0.7.6/README.rdoc +80 -0
  45. data/vendor/gems/celerity-0.7.6/Rakefile +11 -0
  46. data/vendor/gems/celerity-0.7.6/VERSION.yml +5 -0
  47. data/vendor/gems/celerity-0.7.6/celerity.gemspec +120 -0
  48. data/vendor/gems/celerity-0.7.6/lib/celerity.rb +77 -0
  49. data/vendor/gems/celerity-0.7.6/lib/celerity/browser.rb +893 -0
  50. data/vendor/gems/celerity-0.7.6/lib/celerity/clickable_element.rb +73 -0
  51. data/vendor/gems/celerity-0.7.6/lib/celerity/collections.rb +156 -0
  52. data/vendor/gems/celerity-0.7.6/lib/celerity/container.rb +767 -0
  53. data/vendor/gems/celerity-0.7.6/lib/celerity/default_viewer.rb +14 -0
  54. data/vendor/gems/celerity-0.7.6/lib/celerity/disabled_element.rb +40 -0
  55. data/vendor/gems/celerity-0.7.6/lib/celerity/element.rb +298 -0
  56. data/vendor/gems/celerity-0.7.6/lib/celerity/element_collection.rb +107 -0
  57. data/vendor/gems/celerity-0.7.6/lib/celerity/element_locator.rb +159 -0
  58. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/button.rb +54 -0
  59. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/file_field.rb +29 -0
  60. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/form.rb +33 -0
  61. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/frame.rb +86 -0
  62. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/image.rb +89 -0
  63. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/label.rb +16 -0
  64. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/link.rb +43 -0
  65. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/meta.rb +14 -0
  66. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/non_control_elements.rb +116 -0
  67. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/option.rb +38 -0
  68. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/radio_check.rb +114 -0
  69. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/select_list.rb +147 -0
  70. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table.rb +153 -0
  71. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table_cell.rb +36 -0
  72. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table_elements.rb +42 -0
  73. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table_row.rb +49 -0
  74. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/text_field.rb +168 -0
  75. data/vendor/gems/celerity-0.7.6/lib/celerity/exception.rb +83 -0
  76. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit.rb +64 -0
  77. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
  78. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  79. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
  80. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
  81. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
  82. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  83. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  84. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/htmlunit-2.7-SNAPSHOT.jar +0 -0
  85. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/htmlunit-core-js-2.7-SNAPSHOT.jar +0 -0
  86. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/nekohtml-1.9.14-20091130.152932-3.jar +0 -0
  87. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  88. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  89. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  90. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/xercesImpl-2.9.1.jar +0 -0
  91. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  92. data/vendor/gems/celerity-0.7.6/lib/celerity/identifier.rb +28 -0
  93. data/vendor/gems/celerity-0.7.6/lib/celerity/ignoring_web_connection.rb +15 -0
  94. data/vendor/gems/celerity-0.7.6/lib/celerity/input_element.rb +25 -0
  95. data/vendor/gems/celerity-0.7.6/lib/celerity/javascript_debugger.rb +32 -0
  96. data/vendor/gems/celerity-0.7.6/lib/celerity/listener.rb +143 -0
  97. data/vendor/gems/celerity-0.7.6/lib/celerity/resources/no_viewer.png +0 -0
  98. data/vendor/gems/celerity-0.7.6/lib/celerity/short_inspect.rb +20 -0
  99. data/vendor/gems/celerity-0.7.6/lib/celerity/util.rb +126 -0
  100. data/vendor/gems/celerity-0.7.6/lib/celerity/version.rb +3 -0
  101. data/vendor/gems/celerity-0.7.6/lib/celerity/viewer_connection.rb +89 -0
  102. data/vendor/gems/celerity-0.7.6/lib/celerity/watir_compatibility.rb +70 -0
  103. data/vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb +48 -0
  104. data/vendor/gems/celerity-0.7.6/tasks/benchmark.rake +4 -0
  105. data/vendor/gems/celerity-0.7.6/tasks/check.rake +24 -0
  106. data/vendor/gems/celerity-0.7.6/tasks/clean.rake +3 -0
  107. data/vendor/gems/celerity-0.7.6/tasks/fix.rake +25 -0
  108. data/vendor/gems/celerity-0.7.6/tasks/jar.rake +55 -0
  109. data/vendor/gems/celerity-0.7.6/tasks/jeweler.rake +26 -0
  110. data/vendor/gems/celerity-0.7.6/tasks/rdoc.rake +4 -0
  111. data/vendor/gems/celerity-0.7.6/tasks/snapshot.rake +22 -0
  112. data/vendor/gems/celerity-0.7.6/tasks/spec.rake +26 -0
  113. data/vendor/gems/celerity-0.7.6/tasks/website.rake +10 -0
  114. data/vendor/gems/celerity-0.7.6/tasks/yard.rake +16 -0
  115. data/vendor/jruby/jruby-complete-1.4.0.jar +0 -0
  116. metadata +194 -0
@@ -0,0 +1,16 @@
1
+ module Celerity
2
+
3
+ class Label < Element
4
+ include ClickableElement
5
+
6
+ TAGS = [ Identifier.new('label') ]
7
+ ATTRIBUTES = BASE_ATTRIBUTES | [
8
+ :accesskey,
9
+ :for,
10
+ :onblur,
11
+ :onfocus,
12
+ ]
13
+ DEFAULT_HOW = :text
14
+ end
15
+
16
+ end
@@ -0,0 +1,43 @@
1
+ module Celerity
2
+ class Link < Element
3
+ include ClickableElement
4
+
5
+ TAGS = [ Identifier.new('a') ]
6
+ ATTRIBUTES = BASE_ATTRIBUTES | [
7
+ :accesskey,
8
+ :charset,
9
+ :coords,
10
+ :href,
11
+ :hreflang,
12
+ :name,
13
+ :onblur,
14
+ :onfocus,
15
+ :rel,
16
+ :rev,
17
+ :shape,
18
+ :tabindex,
19
+ :target,
20
+ :type,
21
+ ]
22
+ DEFAULT_HOW = :href
23
+
24
+ #
25
+ # Returns the absolute URL for this link (Celerity-specific)
26
+ #
27
+ # (Watir/IE does this for href(), but we don't want that.)
28
+ #
29
+
30
+ def absolute_url
31
+ assert_exists
32
+ href = @object.getAttribute('href')
33
+
34
+ unless href.empty? || URI.parse(href).absolute?
35
+ href = URI.join(browser.url, href).to_s
36
+ end
37
+
38
+ href
39
+ end
40
+
41
+
42
+ end # Link
43
+ end # Celerity
@@ -0,0 +1,14 @@
1
+ module Celerity
2
+ class Meta < Element
3
+ ATTRIBUTES = HTML_401_TRANSITIONAL[:i18n] | [
4
+ :'http-equiv',
5
+ :content,
6
+ :id,
7
+ :name,
8
+ :scheme,
9
+ ]
10
+
11
+ DEFAULT_HOW = :id
12
+ TAGS = [ Identifier.new('meta') ]
13
+ end
14
+ end
@@ -0,0 +1,116 @@
1
+ module Celerity
2
+
3
+ #
4
+ # Superclass for for Span, Pre, Div, H1, ...
5
+ #
6
+
7
+ class NonControlElement < Element
8
+ include Exception
9
+ include ClickableElement
10
+
11
+ ATTRIBUTES = BASE_ATTRIBUTES
12
+ DEFAULT_HOW = :id
13
+ end
14
+
15
+ #
16
+ #--
17
+ # classes ordered alphabetically
18
+ #++
19
+ #
20
+
21
+ class Area < NonControlElement
22
+ ATTRIBUTES = ATTRIBUTES | [
23
+ :accesskey,
24
+ :alt,
25
+ :coords,
26
+ :href,
27
+ :nohref,
28
+ :onblur,
29
+ :onfocus,
30
+ :shape,
31
+ :tabindex,
32
+ ]
33
+ TAGS = [ Identifier.new('area') ]
34
+ end
35
+
36
+ class Dd < NonControlElement
37
+ TAGS = [ Identifier.new('dd')]
38
+ end
39
+
40
+ class Div < NonControlElement
41
+ TAGS = [ Identifier.new('div')]
42
+ end
43
+
44
+ class Dl < NonControlElement
45
+ TAGS = [ Identifier.new('dl')]
46
+ end
47
+
48
+ class Dt < NonControlElement
49
+ TAGS = [ Identifier.new('dt')]
50
+ end
51
+
52
+ class Em < NonControlElement
53
+ TAGS = [ Identifier.new('em')]
54
+ end
55
+
56
+ class H1 < NonControlElement
57
+ TAGS = [ Identifier.new('h1') ]
58
+ end
59
+
60
+ class H2 < NonControlElement
61
+ TAGS = [ Identifier.new('h2') ]
62
+ end
63
+
64
+ class H3 < NonControlElement
65
+ TAGS = [ Identifier.new('h3') ]
66
+ end
67
+
68
+ class H4 < NonControlElement
69
+ TAGS = [ Identifier.new('h4') ]
70
+ end
71
+
72
+ class H5 < NonControlElement
73
+ TAGS = [ Identifier.new('h5') ]
74
+ end
75
+
76
+ class H6 < NonControlElement
77
+ TAGS = [ Identifier.new('h6') ]
78
+ end
79
+
80
+ class Li < NonControlElement
81
+ TAGS = [ Identifier.new('li') ]
82
+ end
83
+
84
+ class Map < NonControlElement
85
+ TAGS = [ Identifier.new('map') ]
86
+ end
87
+
88
+ class Ol < NonControlElement
89
+ TAGS = [ Identifier.new('ol') ]
90
+ end
91
+
92
+ class P < NonControlElement
93
+ TAGS = [ Identifier.new('p') ]
94
+ end
95
+
96
+ class Pre < NonControlElement
97
+ TAGS = [ Identifier.new('pre')]
98
+ end
99
+
100
+ class Span < NonControlElement
101
+ TAGS = [ Identifier.new('span') ]
102
+ end
103
+
104
+ class Strong < NonControlElement
105
+ TAGS = [ Identifier.new('strong') ]
106
+ end
107
+
108
+ # class Title < NonControlElement
109
+ # TAGS = [ Identifier.new('title') ]
110
+ # end
111
+
112
+ class Ul < NonControlElement
113
+ TAGS = [ Identifier.new('ul') ]
114
+ end
115
+
116
+ end
@@ -0,0 +1,38 @@
1
+ module Celerity
2
+
3
+ #
4
+ # Represents an option in a select list.
5
+ #
6
+
7
+ class Option < Element
8
+ include ClickableElement
9
+ include DisabledElement
10
+
11
+ TAGS = [ Identifier.new('option') ]
12
+ ATTRIBUTES = BASE_ATTRIBUTES | [
13
+ :disabled,
14
+ :label,
15
+ :selected,
16
+ :value,
17
+ ]
18
+
19
+ DEFAULT_HOW = :text
20
+
21
+ alias_method :select, :click
22
+
23
+ #
24
+ # Is this option selected?
25
+ #
26
+
27
+ def selected?
28
+ assert_exists
29
+ @object.isSelected
30
+ end
31
+
32
+ def label
33
+ # overrides Container#label
34
+ assert_exists
35
+ @object.getLabelAttribute
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,114 @@
1
+ module Celerity
2
+
3
+ #
4
+ # Common superclass for radios and check boxes.
5
+ #
6
+
7
+ class RadioCheckCommon < InputElement
8
+ DEFAULT_HOW = :name
9
+
10
+ #
11
+ # Can optionally take a value parameter as a third arg, so we override initialize
12
+ #
13
+
14
+ def initialize(container, type, *args)
15
+ @type = type
16
+ case args.size
17
+ when 2
18
+ super(container, args[0] => args[1])
19
+ when 3
20
+ super(container, args[0] => args[1], :value => args[2])
21
+ else
22
+ super(container, *args)
23
+ end
24
+ end
25
+
26
+ #
27
+ # returns true if the element is checked
28
+ # @return [true, false]
29
+ #
30
+
31
+ def set?
32
+ assert_exists
33
+ @object.isChecked
34
+ end
35
+ alias_method :checked?, :set?
36
+
37
+ #
38
+ # Unset this element.
39
+ #
40
+
41
+ def clear
42
+ set(false)
43
+ end
44
+ end
45
+
46
+ #
47
+ # This class is the representation of a radio button.
48
+ #
49
+
50
+ class Radio < RadioCheckCommon
51
+ TAGS = [Identifier.new('input', :type => %w[radio])]
52
+
53
+ #
54
+ # @api private
55
+ #
56
+
57
+ def initialize(container, *args)
58
+ super(container, %w[radio], *args)
59
+ end
60
+
61
+ #
62
+ # Set the radio button to the given value.
63
+ #
64
+ # radio.set? #=> false
65
+ # radio.set
66
+ # radio.set? #=> true
67
+ # radio.set(false)
68
+ # radio.set? #=> false
69
+ #
70
+
71
+ def set(value = true)
72
+ assert_exists
73
+ assert_enabled
74
+ value ? @object.click : @object.setChecked(value)
75
+ end
76
+
77
+ end
78
+
79
+ #
80
+ # This class is the representation of a check box.
81
+ #
82
+
83
+ class CheckBox < RadioCheckCommon
84
+ TAGS = [Identifier.new('input', :type => %w[checkbox])]
85
+
86
+ #
87
+ # @api private
88
+ #
89
+
90
+ def initialize(container, *args)
91
+ super(container, %w[checkbox], *args)
92
+ end
93
+
94
+ #
95
+ # Set the checkbox to the given value.
96
+ #
97
+ # checkbox.set? #=> false
98
+ # checkbox.set
99
+ # checkbox.set? #=> true
100
+ # checkbox.set(false)
101
+ # checkbox.set? #=> false
102
+ #
103
+
104
+ def set(value = true)
105
+ assert_exists
106
+ assert_enabled
107
+
108
+ if (value && !set?) || (!value && set?)
109
+ @object.click
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,147 @@
1
+ module Celerity
2
+ class SelectList < InputElement
3
+ TAGS = [ Identifier.new('select') ]
4
+ DEFAULT_HOW = :name
5
+
6
+ #
7
+ # @return [Array<String>] An array of strings representing the text value of the select list's options.
8
+ #
9
+
10
+ def options
11
+ assert_exists
12
+ @object.getOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText }
13
+ end
14
+
15
+ #
16
+ # @return [Array<String>] An array of strings representing the text value of the currently selected options.
17
+ #
18
+
19
+ def selected_options
20
+ assert_exists
21
+ @object.getSelectedOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText }
22
+ end
23
+
24
+ #
25
+ # Clear all selected options
26
+ #
27
+
28
+ def clear
29
+ # assert_exists called by SelectList#type here
30
+ @object.getSelectedOptions.each { |e| e.setSelected(false) } unless type() == 'select-one'
31
+ end
32
+
33
+ #
34
+ # Select the option(s) whose text or label matches the given string.
35
+ # If several options match the value given, all will be selected.
36
+ #
37
+ # @param [String, Regexp] value A value.
38
+ # @raise [Celerity::Exception::NoValueFoundException] if the value does not exist.
39
+ # @return [String] The option selected. If multiple options match, returns the first match
40
+ #
41
+ #
42
+
43
+ def select(value)
44
+ assert_exists
45
+
46
+ selected = nil
47
+ @object.getOptions.select do |option|
48
+ next unless matches_option?(option, value)
49
+
50
+ selected ||= option.asText
51
+ option.click
52
+ end
53
+
54
+ unless selected
55
+ raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}"
56
+ end
57
+
58
+ selected
59
+ end
60
+ alias_method :set, :select
61
+
62
+ #
63
+ # Selects the option(s) whose value attribute matches the given string.
64
+ # @param [String, Regexp] value A value.
65
+ # @raise [Celerity::Exception::NoValueFoundException] if the value does not exist.
66
+ # @return [String] The option selected. If multiple options match, returns the first match
67
+ #
68
+
69
+ def select_value(value)
70
+ assert_exists
71
+ selected = @object.getOptions.map { |e| e.click if Util.matches?(e.getValueAttribute, value) }.compact.first
72
+
73
+ unless selected
74
+ raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}"
75
+ end
76
+
77
+ selected.asText
78
+ end
79
+
80
+ #
81
+ # Returns true if the select list has one or more options matching the given value.
82
+ #
83
+ # @param [String, Regexp] value A value.
84
+ # @return [true, false]
85
+ #
86
+
87
+ def include?(value)
88
+ assert_exists
89
+ !!@object.getOptions.find { |e| matches_option?(e, value) }
90
+ end
91
+
92
+ #
93
+ # Returns true if any of the selected options match the given value.
94
+ #
95
+ # @param [String, Regexp] value A value.
96
+ # @raise [Celerity::Exception::UnknownObjectException] if the value does not exist.
97
+ # @return [true, false]
98
+ #
99
+
100
+ def selected?(value)
101
+ assert_exists
102
+ raise UnknownObjectException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
103
+ !!@object.getOptions.find { |e| matches_option?(e, value) && e.isSelected }
104
+ end
105
+
106
+ #
107
+ # Returns 'select-multiple' if the select list has the 'multiple' attribute,
108
+ # defined, otherwise 'select-one'.
109
+ #
110
+ # @return [String]
111
+ #
112
+
113
+ def type
114
+ assert_exists
115
+ 'select-' + (@object.hasAttribute('multiple') ? 'multiple' : 'one')
116
+ end
117
+
118
+ #
119
+ # Returns true if the select list supports multiple selections
120
+ #
121
+
122
+ def multiple?
123
+ type == "select-multiple"
124
+ end
125
+
126
+ #
127
+ # Returns the value of the first selected option in the select list.
128
+ # Returns nil if no option is selected.
129
+ #
130
+ # @return [String, nil]
131
+ #
132
+
133
+ def value
134
+ assert_exists
135
+ if (option = @object.getSelectedOptions.to_a.first)
136
+ option.getValueAttribute
137
+ end
138
+ end
139
+
140
+ private
141
+
142
+ def matches_option?(option, value)
143
+ Util.matches?(option.asText, value) || (option.hasAttribute("label") && Util.matches?(option.getLabelAttribute, value))
144
+ end
145
+
146
+ end # SelectList
147
+ end # Celerity