operawatir 0.3-jruby
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/.gitmodules +3 -0
- data/.yardopts +5 -0
- data/AUTHORS +7 -0
- data/Gemfile +9 -0
- data/LICENSE +30 -0
- data/README.md +158 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/bin/desktopwatir +106 -0
- data/bin/operawatir +95 -0
- data/lib/operadriver/APACHE_2.0_LICENSE.txt +204 -0
- data/lib/operadriver/NEW_BSD_LICENSE.txt +36 -0
- data/lib/operadriver/commons-jxpath-1.3.jar +0 -0
- data/lib/operadriver/protobuf-java-2.3.0.jar +0 -0
- data/lib/operadriver/selenium-common.jar +0 -0
- data/lib/operadriver/webdriver-opera.jar +0 -0
- data/lib/operawatir.rb +46 -0
- data/lib/operawatir/browser.rb +181 -0
- data/lib/operawatir/collection.rb +133 -0
- data/lib/operawatir/compat.rb +25 -0
- data/lib/operawatir/compat/browser.rb +20 -0
- data/lib/operawatir/compat/collection.rb +99 -0
- data/lib/operawatir/compat/deprecation.rb +46 -0
- data/lib/operawatir/compat/element.rb +165 -0
- data/lib/operawatir/compat/element_finders.rb +159 -0
- data/lib/operawatir/compat/window.rb +27 -0
- data/lib/operawatir/element.rb +228 -0
- data/lib/operawatir/exceptions.rb +38 -0
- data/lib/operawatir/helper.rb +53 -0
- data/lib/operawatir/selector.rb +111 -0
- data/lib/operawatir/version.rb +15 -0
- data/lib/operawatir/window.rb +174 -0
- data/spec/fire_event/fire_event.rb +268 -0
- data/spec/fire_event/interactive/onBlur.html +45 -0
- data/spec/fire_event/interactive/onChange.html +47 -0
- data/spec/fire_event/interactive/onClick.html +45 -0
- data/spec/fire_event/interactive/onDblClick.html +45 -0
- data/spec/fire_event/interactive/onFocus.html +45 -0
- data/spec/fire_event/interactive/onMouseDown.html +45 -0
- data/spec/fire_event/interactive/onMouseMove.html +45 -0
- data/spec/fire_event/interactive/onMouseOut.html +45 -0
- data/spec/fire_event/interactive/onMouseOver.html +45 -0
- data/spec/fire_event/interactive/onMouseUp.html +45 -0
- data/spec/fire_event/interactive/onScroll.html +14 -0
- data/spec/legacy_watirspec/area_spec.rb +106 -0
- data/spec/legacy_watirspec/areas_spec.rb +38 -0
- data/spec/legacy_watirspec/browser_spec.rb +297 -0
- data/spec/legacy_watirspec/button_spec.rb +260 -0
- data/spec/legacy_watirspec/buttons_spec.rb +54 -0
- data/spec/legacy_watirspec/checkbox_spec.rb +280 -0
- data/spec/legacy_watirspec/checkboxes_spec.rb +38 -0
- data/spec/legacy_watirspec/collections_spec.rb +18 -0
- data/spec/legacy_watirspec/dd_spec.rb +140 -0
- data/spec/legacy_watirspec/dds_spec.rb +38 -0
- data/spec/legacy_watirspec/del_spec.rb +181 -0
- data/spec/legacy_watirspec/dels_spec.rb +62 -0
- data/spec/legacy_watirspec/div_spec.rb +244 -0
- data/spec/legacy_watirspec/divs_spec.rb +38 -0
- data/spec/legacy_watirspec/dl_spec.rb +140 -0
- data/spec/legacy_watirspec/dls_spec.rb +38 -0
- data/spec/legacy_watirspec/dt_spec.rb +140 -0
- data/spec/legacy_watirspec/dts_spec.rb +38 -0
- data/spec/legacy_watirspec/element_spec.rb +86 -0
- data/spec/legacy_watirspec/em_spec.rb +114 -0
- data/spec/legacy_watirspec/ems_spec.rb +38 -0
- data/spec/legacy_watirspec/filefield_spec.rb +127 -0
- data/spec/legacy_watirspec/filefields_spec.rb +38 -0
- data/spec/legacy_watirspec/fixtures/2000_spans.html +2009 -0
- data/spec/legacy_watirspec/fixtures/bug_duplicate_attributes.html +14 -0
- data/spec/legacy_watirspec/fixtures/bug_javascript_001.html +11 -0
- data/spec/legacy_watirspec/fixtures/buttons_with_duplicate_ids.html +18 -0
- data/spec/legacy_watirspec/fixtures/collections.html +15 -0
- data/spec/legacy_watirspec/fixtures/definition_lists.html +48 -0
- data/spec/legacy_watirspec/fixtures/euc-jp_text.html +17 -0
- data/spec/legacy_watirspec/fixtures/forms_with_input_elements.html +126 -0
- data/spec/legacy_watirspec/fixtures/frame_1.html +18 -0
- data/spec/legacy_watirspec/fixtures/frame_2.html +16 -0
- data/spec/legacy_watirspec/fixtures/frames.html +11 -0
- data/spec/legacy_watirspec/fixtures/iframes.html +12 -0
- data/spec/legacy_watirspec/fixtures/images.html +27 -0
- data/spec/legacy_watirspec/fixtures/images/1.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/2.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/3.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/button.jpg +0 -0
- data/spec/legacy_watirspec/fixtures/images/circle.jpg +0 -0
- data/spec/legacy_watirspec/fixtures/images/map.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/map2.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/minus.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/originaltriangle.jpg +0 -0
- data/spec/legacy_watirspec/fixtures/images/plus.gif +0 -0
- data/spec/legacy_watirspec/fixtures/images/square.jpg +0 -0
- data/spec/legacy_watirspec/fixtures/images/triangle.jpg +0 -0
- data/spec/legacy_watirspec/fixtures/iso-2022-jp_text.html +17 -0
- data/spec/legacy_watirspec/fixtures/javascript/helpers.js +16 -0
- data/spec/legacy_watirspec/fixtures/jquery.html +28 -0
- data/spec/legacy_watirspec/fixtures/latin1_text.html +17 -0
- data/spec/legacy_watirspec/fixtures/multiple_ids.html +14 -0
- data/spec/legacy_watirspec/fixtures/non_control_elements.html +135 -0
- data/spec/legacy_watirspec/fixtures/parser_bug_001.html +12 -0
- data/spec/legacy_watirspec/fixtures/prevent_form_submit.html +20 -0
- data/spec/legacy_watirspec/fixtures/right_click.html +11 -0
- data/spec/legacy_watirspec/fixtures/shift_jis_text.html +17 -0
- data/spec/legacy_watirspec/fixtures/tables.html +121 -0
- data/spec/legacy_watirspec/fixtures/timeout.html +16 -0
- data/spec/legacy_watirspec/fixtures/timeout_window_location.html +19 -0
- data/spec/legacy_watirspec/fixtures/tiny_mce.html +27 -0
- data/spec/legacy_watirspec/fixtures/utf8_text.html +15 -0
- data/spec/legacy_watirspec/fixtures/watirspec.css +0 -0
- data/spec/legacy_watirspec/form_spec.rb +73 -0
- data/spec/legacy_watirspec/forms_spec.rb +39 -0
- data/spec/legacy_watirspec/frame_spec.rb +161 -0
- data/spec/legacy_watirspec/frames_spec.rb +75 -0
- data/spec/legacy_watirspec/guards.rb +38 -0
- data/spec/legacy_watirspec/hidden_spec.rb +120 -0
- data/spec/legacy_watirspec/hiddens_spec.rb +38 -0
- data/spec/legacy_watirspec/hn_spec.rb +101 -0
- data/spec/legacy_watirspec/hns_spec.rb +39 -0
- data/spec/legacy_watirspec/image_spec.rb +237 -0
- data/spec/legacy_watirspec/images_spec.rb +38 -0
- data/spec/legacy_watirspec/ins_spec.rb +181 -0
- data/spec/legacy_watirspec/inses_spec.rb +62 -0
- data/spec/legacy_watirspec/label_spec.rb +85 -0
- data/spec/legacy_watirspec/labels_spec.rb +38 -0
- data/spec/legacy_watirspec/li_spec.rb +135 -0
- data/spec/legacy_watirspec/link_spec.rb +194 -0
- data/spec/legacy_watirspec/links_spec.rb +39 -0
- data/spec/legacy_watirspec/lis_spec.rb +38 -0
- data/spec/legacy_watirspec/map_spec.rb +100 -0
- data/spec/legacy_watirspec/maps_spec.rb +38 -0
- data/spec/legacy_watirspec/meta_spec.rb +26 -0
- data/spec/legacy_watirspec/metas_spec.rb +36 -0
- data/spec/legacy_watirspec/ol_spec.rb +86 -0
- data/spec/legacy_watirspec/ols_spec.rb +38 -0
- data/spec/legacy_watirspec/option_spec.rb +187 -0
- data/spec/legacy_watirspec/p_spec.rb +167 -0
- data/spec/legacy_watirspec/pre_spec.rb +133 -0
- data/spec/legacy_watirspec/pres_spec.rb +38 -0
- data/spec/legacy_watirspec/ps_spec.rb +38 -0
- data/spec/legacy_watirspec/radio_spec.rb +286 -0
- data/spec/legacy_watirspec/radios_spec.rb +35 -0
- data/spec/legacy_watirspec/select_list_spec.rb +326 -0
- data/spec/legacy_watirspec/select_lists_spec.rb +39 -0
- data/spec/legacy_watirspec/server.rb +91 -0
- data/spec/legacy_watirspec/span_spec.rb +181 -0
- data/spec/legacy_watirspec/spans_spec.rb +64 -0
- data/spec/legacy_watirspec/spec_helper.rb +12 -0
- data/spec/legacy_watirspec/strong_spec.rb +97 -0
- data/spec/legacy_watirspec/strongs_spec.rb +39 -0
- data/spec/legacy_watirspec/table_bodies_spec.rb +61 -0
- data/spec/legacy_watirspec/table_body_spec.rb +119 -0
- data/spec/legacy_watirspec/table_cell_spec.rb +76 -0
- data/spec/legacy_watirspec/table_cells_spec.rb +71 -0
- data/spec/legacy_watirspec/table_footer_spec.rb +94 -0
- data/spec/legacy_watirspec/table_footers_spec.rb +61 -0
- data/spec/legacy_watirspec/table_header_spec.rb +98 -0
- data/spec/legacy_watirspec/table_headers_spec.rb +59 -0
- data/spec/legacy_watirspec/table_row_spec.rb +104 -0
- data/spec/legacy_watirspec/table_rows_spec.rb +64 -0
- data/spec/legacy_watirspec/table_spec.rb +170 -0
- data/spec/legacy_watirspec/tables_spec.rb +40 -0
- data/spec/legacy_watirspec/text_field_spec.rb +315 -0
- data/spec/legacy_watirspec/text_fields_spec.rb +38 -0
- data/spec/legacy_watirspec/ul_spec.rb +84 -0
- data/spec/legacy_watirspec/uls_spec.rb +40 -0
- data/spec/legacy_watirspec/watir_compatibility_spec.rb +176 -0
- data/spec/legacy_watirspec/watirspec_helper.rb +57 -0
- data/utils/Rakefile +79 -0
- data/utils/launchers/launcher-linux-i686 +0 -0
- data/utils/launchers/launcher-linux-x86_64 +0 -0
- data/utils/launchers/launcher-win32-i86pc.exe +0 -0
- metadata +404 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
class OperaWatir::Collection
|
5
|
+
extend Forwardable
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_accessor :parent, :selector
|
9
|
+
|
10
|
+
def initialize(parent, elms=nil)
|
11
|
+
self.parent, self.selector = parent, OperaWatir::Selector.new(self)
|
12
|
+
@_elms = elms
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_selector_from_arguments(args)
|
16
|
+
if not args.empty?
|
17
|
+
args.each do |arg|
|
18
|
+
selector.attribute arg
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def exist?
|
24
|
+
!raw_elements.empty?
|
25
|
+
rescue OperaWatir::Exceptions::UnknownObjectException
|
26
|
+
false
|
27
|
+
end
|
28
|
+
alias_method :exists?, :exist? # LOL Ruby
|
29
|
+
|
30
|
+
def single?
|
31
|
+
raw_elements.length == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def_delegators :raw_elements, :each,
|
35
|
+
:length,
|
36
|
+
:size,
|
37
|
+
:first,
|
38
|
+
:last,
|
39
|
+
:empty?
|
40
|
+
|
41
|
+
|
42
|
+
def [](n)
|
43
|
+
self.class.new(self).tap {|c| c.selector.index(n) }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set union, used for joining complex finders (specifically for Watir1)
|
47
|
+
def +(other)
|
48
|
+
self.class.new(parent, raw_elements + other.raw_elements)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Public interface to elms, used in Selector
|
52
|
+
def raw_elements
|
53
|
+
_elms.tap do |e|
|
54
|
+
raise(OperaWatir::Exceptions::UnknownObjectException) if e.empty?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# Attributes
|
60
|
+
|
61
|
+
def id
|
62
|
+
map_or_return {|elm| elm.id}
|
63
|
+
end
|
64
|
+
|
65
|
+
def attr(name)
|
66
|
+
raw_elements[0].attr(name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def attrs(name)
|
70
|
+
raw_elements.map do |el|
|
71
|
+
el.attr(name)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
# Finding
|
77
|
+
|
78
|
+
OperaWatir::Selector::BASE_TYPES.each do |type|
|
79
|
+
define_method("find_by_#{type}") do |name|
|
80
|
+
OperaWatir::Collection.new(self).tap do |c|
|
81
|
+
c.selector.send(type, name)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
alias_method :find_by_class, :find_by_class_name
|
87
|
+
alias_method :find_by_tag, :find_by_tag_name
|
88
|
+
|
89
|
+
# TODO
|
90
|
+
# - Find tag if method exists in a list of HTML5 elements
|
91
|
+
# - If ends in ? then check that all returned values are true
|
92
|
+
# - Else, return attributes from elements
|
93
|
+
def method_missing(method, *args, &blk)
|
94
|
+
map_or_return {|elm| elm.send(method, *args, &blk) }
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def _elms
|
101
|
+
@_elms ||= selector.eval
|
102
|
+
end
|
103
|
+
|
104
|
+
attr_writer :_elms
|
105
|
+
|
106
|
+
# TODO Massive hack: map is overritten in Watir1
|
107
|
+
alias_method :_map, :map
|
108
|
+
|
109
|
+
def map_or_return(&blk)
|
110
|
+
single? ? blk.call(raw_elements.first) : _map(&blk)
|
111
|
+
end
|
112
|
+
|
113
|
+
OperaWatir::Selector::BASE_TYPES.each do |type|
|
114
|
+
define_method("find_elements_by_#{type}") do |value|
|
115
|
+
_elms.inject([]) do |result, element|
|
116
|
+
result | element.send("find_elements_by_#{type}", value.to_s)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def find_elements_by_attribute(attributes)
|
122
|
+
_elms.select do |elm|
|
123
|
+
attributes.all? {|attribute, value|
|
124
|
+
elm.send(attribute).send((value.is_a?(Regexp) ? :match : :==), value)
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def find_elements_by_index(n)
|
130
|
+
(n >= 0 && n < _elms.length) ? [_elms[n]] : []
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OperaWatir
|
2
|
+
|
3
|
+
module Compat; end
|
4
|
+
|
5
|
+
# Switches on compatibility layer (Watir 1 API).
|
6
|
+
def self.compatibility!
|
7
|
+
# require 'operawatir/compat/deprecation'
|
8
|
+
require 'operawatir/compat/browser'
|
9
|
+
require 'operawatir/compat/element_finders'
|
10
|
+
require 'operawatir/compat/window'
|
11
|
+
|
12
|
+
Browser.send :include, Compat::Browser
|
13
|
+
Window.send :include, Compat::ElementFinders
|
14
|
+
Window.send :include, Compat::Window
|
15
|
+
Collection.send :include, Compat::ElementFinders
|
16
|
+
|
17
|
+
# TODO Ruby Modules can't override methods defined in their included klass
|
18
|
+
# Requiring the files is OK, but there needs to be some way of detecting
|
19
|
+
# that we are in compatibility mode.
|
20
|
+
|
21
|
+
require 'operawatir/compat/collection'
|
22
|
+
require 'operawatir/compat/element'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OperaWatir
|
2
|
+
module Compat
|
3
|
+
module Browser
|
4
|
+
|
5
|
+
def method_missing(method, *args, &blk)
|
6
|
+
if active_window.respond_to? method
|
7
|
+
active_window.send(method, *args, &blk)
|
8
|
+
else
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Quits the browser
|
14
|
+
def quit
|
15
|
+
browser.quit!
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class OperaWatir::Collection
|
2
|
+
|
3
|
+
# Aliases that Watir1 defines for certain attributes
|
4
|
+
ATTRIBUTE_ALIASES = {
|
5
|
+
:url => :href,
|
6
|
+
:class => :class_name,
|
7
|
+
:tag => :tag_name
|
8
|
+
}
|
9
|
+
|
10
|
+
# Welcome to Hacksville, population: too many
|
11
|
+
|
12
|
+
# Creates a new selector based on the arguments given to the Watir 1
|
13
|
+
# browser methods, e.g. +browser.div(:id, 'content')+.
|
14
|
+
#
|
15
|
+
# @param [Array] args The array of arguments passed to the Watir
|
16
|
+
# method.
|
17
|
+
# @param [Method] default_method The attribute to use when only a
|
18
|
+
# value is provided, e.g. browser.div('content').
|
19
|
+
# @return [OperaWatir::Selector] the generated selector
|
20
|
+
def add_selector_from_arguments(args, default_method)
|
21
|
+
# () => :index, 0
|
22
|
+
if args.empty?
|
23
|
+
type, value = :index, 0
|
24
|
+
|
25
|
+
# (:index, 1) => :index, 0
|
26
|
+
elsif args.first == :index
|
27
|
+
type, value = :index, args[1].to_i - 1
|
28
|
+
|
29
|
+
# Handle a hash of selectors
|
30
|
+
elsif args.length == 1 and args.first.is_a? Hash
|
31
|
+
args.first.each_pair do |k, v|
|
32
|
+
s = add_selector_from_arguments([k, v], default_method)
|
33
|
+
end
|
34
|
+
return s
|
35
|
+
|
36
|
+
# (:id, 3.14) => TypeError
|
37
|
+
elsif args.any? {|arg| ![String, Regexp, Fixnum, Symbol].any?{|k| arg.is_a?(k)}}
|
38
|
+
raise TypeError
|
39
|
+
|
40
|
+
# NOTE: This is purely to make WatirSpec pass
|
41
|
+
# (:no_such_how, 'some_value') => Exception
|
42
|
+
elsif args.first == :no_such_how
|
43
|
+
raise OperaWatir::Exceptions::MissingWayOfFindingObjectException
|
44
|
+
|
45
|
+
# ('foo') => :attribute, {:id => 'foo'}
|
46
|
+
elsif !args.first.is_a?(Symbol) && args[1].nil?
|
47
|
+
type, value = :attribute, {
|
48
|
+
default_method => args.first
|
49
|
+
}
|
50
|
+
|
51
|
+
# (:xpath, '//area') => :xpath, '//area'
|
52
|
+
elsif ![:id, :class, :tag].include?(args.first) && OperaWatir::Selector::BASE_TYPES.include?(args.first)
|
53
|
+
type, value = args.first, args[1]
|
54
|
+
|
55
|
+
# (:url, 'foo.html') => :attribute, {:href => 'foo.html'}
|
56
|
+
else
|
57
|
+
type, value = :attribute, {
|
58
|
+
(ATTRIBUTE_ALIASES[args.first.to_sym] || args.first) => args[1]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
selector.send(type, value)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Watir1 Collections are 1 indexed *headslap*
|
66
|
+
|
67
|
+
# Gets the element at index, starting from 1 (i.e. [0] in a normal
|
68
|
+
# array is [1] here.
|
69
|
+
#
|
70
|
+
# @param [Fixnum] index The index of the element to retreive
|
71
|
+
# @return [OperaWatir::Collection] A new collection with the
|
72
|
+
# selector pointing to the given index.
|
73
|
+
def [](index)
|
74
|
+
self.class.new(self).tap {|c| c.selector.index(index-1) }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Define methods to satisfy #respond_to? which is used in the tests.
|
78
|
+
[:name, :title, :type, :class_name, :text, :style, :value].each do |name|
|
79
|
+
define_method(name) {method_missing(name)}
|
80
|
+
end
|
81
|
+
|
82
|
+
# Fetches the string representation of this collection.
|
83
|
+
#
|
84
|
+
# @return [String] the string representation of this collection
|
85
|
+
# @raise [OperaWatir::Exceptions::UnknownObjectException]
|
86
|
+
def to_s
|
87
|
+
# This should return all of the attributes defined on each
|
88
|
+
# element. We don't have support for that, so lets just
|
89
|
+
# output the useful ones.
|
90
|
+
raw_elements.map do |el|
|
91
|
+
"tag: #{el.tag_name.downcase}\n"+
|
92
|
+
" id: #{el.id}\n" +
|
93
|
+
" class: #{el.class_name}\n" +
|
94
|
+
" title: #{el.title}\n" +
|
95
|
+
" text: #{el.text}"
|
96
|
+
end.join("\n")
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
class OperaWatir::Exceptions::DeprecationException < OperaWatir::Exceptions::OperaWatirException
|
4
|
+
|
5
|
+
def initialize(desc, fix, trace)
|
6
|
+
@desc, @fix = desc, fix
|
7
|
+
set_backtrace clean_backtrace(trace)
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"DEPRECATION: #{@desc}\n #{@fix}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
LIB_PATHS = [File.expand_path('../../../', __FILE__)] + Gem.all_load_paths
|
17
|
+
|
18
|
+
def clean_backtrace(trace)
|
19
|
+
trace.reject do |line|
|
20
|
+
LIB_PATHS.any? do |lib_path|
|
21
|
+
line.include?(lib_path)
|
22
|
+
end || line.split(':').first == ''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
module OperaWatir
|
29
|
+
module Compat
|
30
|
+
module Deprecation
|
31
|
+
|
32
|
+
def deprecation(desc, fix)
|
33
|
+
warn OperaWatir::Exceptions::DeprecationException.new(desc, fix, caller).message
|
34
|
+
end
|
35
|
+
|
36
|
+
def deprecation!(desc, fix)
|
37
|
+
raise OperaWatir::Exceptions::DeprecationException.new(desc, fix, caller)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Object
|
45
|
+
include OperaWatir::Compat::Deprecation
|
46
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
class OperaWatir::Element
|
2
|
+
|
3
|
+
# Gets the attribute called name.
|
4
|
+
#
|
5
|
+
# @param [String, Symbol] name The name of the attribute to get
|
6
|
+
# @return [String] The value of the attribute
|
7
|
+
def attr(name)
|
8
|
+
node.getAttribute(name.to_s) || ''
|
9
|
+
end
|
10
|
+
|
11
|
+
# Check the existence of the attribute on the element.
|
12
|
+
#
|
13
|
+
# @return [Boolean] true if the attribute exists on the element,
|
14
|
+
# false otherwise
|
15
|
+
def attr?(name)
|
16
|
+
!node.getAttribute(name.to_s).nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(name, *args, &blk)
|
20
|
+
if !block_given? && args.empty?
|
21
|
+
attr(name)
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Gets the text content of the element.
|
28
|
+
#
|
29
|
+
# @return [String] the text content
|
30
|
+
def text
|
31
|
+
node.getText.strip
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :to_s, :text
|
35
|
+
|
36
|
+
# On elements of type `<input>` this gets the value of the value
|
37
|
+
# attribute, on every other element type it returns the text
|
38
|
+
# content.
|
39
|
+
#
|
40
|
+
# @return [String] value of the element
|
41
|
+
def value
|
42
|
+
if tag_name == 'INPUT' or attr?(:value)
|
43
|
+
attr(:value)
|
44
|
+
else
|
45
|
+
text
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Checks whether the text content of the element contains the given
|
50
|
+
# string In the compatibility layer as the preferred way of doing
|
51
|
+
# this is.
|
52
|
+
#
|
53
|
+
# elm.text.should include('My string')
|
54
|
+
#
|
55
|
+
# @param [String] String to search for
|
56
|
+
# @param [Boolean] true if the element's text contains str, false
|
57
|
+
# otherwise
|
58
|
+
def verify_contains(str)
|
59
|
+
text.include?(str)
|
60
|
+
end
|
61
|
+
|
62
|
+
alias_method :verify_contains?, :verify_contains
|
63
|
+
|
64
|
+
alias_method :caption, :text
|
65
|
+
|
66
|
+
# Clicks on the top left of the element, or the given x, y offset.
|
67
|
+
#
|
68
|
+
# @param [optional, Fixnum] x The offset from the left of the
|
69
|
+
# element
|
70
|
+
# @param [optional, Fixnum] y The offset from the top of the element
|
71
|
+
def click(x=0, y=0)
|
72
|
+
assert_enabled!
|
73
|
+
node.click(x.to_i, y.to_i)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Focuses the element
|
77
|
+
def focus
|
78
|
+
trigger! :focus
|
79
|
+
end
|
80
|
+
|
81
|
+
alias_method :fire_event, :trigger!
|
82
|
+
|
83
|
+
# Submits a form, or the form the elment is contained in.
|
84
|
+
def submit
|
85
|
+
assert_exists
|
86
|
+
node.submit
|
87
|
+
end
|
88
|
+
|
89
|
+
# Clears a text input or textarea of any text.
|
90
|
+
def clear
|
91
|
+
assert_enabled!
|
92
|
+
node.clear
|
93
|
+
end
|
94
|
+
|
95
|
+
# If passed a value it will type text into the element, otherwise it
|
96
|
+
# will check a radio button or checkbox.
|
97
|
+
#
|
98
|
+
# @param [optional, String] value Text to type
|
99
|
+
def set(value=nil)
|
100
|
+
if value
|
101
|
+
self.text = value
|
102
|
+
else
|
103
|
+
check!
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Gets the href of an `<a>` element, or the url attribute of any
|
108
|
+
# other element.
|
109
|
+
#
|
110
|
+
# @return [String] an href or the url attribute
|
111
|
+
def url
|
112
|
+
attr(tag_name == 'A' ? :href : :url)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Gets the selected `<option>` elements in a `<select>` element.
|
116
|
+
#
|
117
|
+
# @return [OperaWatir::Collection] a collection of the selected
|
118
|
+
# `<option>`s
|
119
|
+
def selected_options
|
120
|
+
options(:selected?, true)
|
121
|
+
end
|
122
|
+
|
123
|
+
# On checkboxes, radio buttons, and option elements returns whether
|
124
|
+
# the element is checked/selected. On a select element, when passed
|
125
|
+
# an value it checks whether the selected option contains the given
|
126
|
+
# text.
|
127
|
+
#
|
128
|
+
# @param [optional, String] value Text the selected option should
|
129
|
+
# contain
|
130
|
+
# @return [Boolean] true if the element is selected/selected option
|
131
|
+
# contains value, false otherwise
|
132
|
+
def selected?(value=nil)
|
133
|
+
if option.nil?
|
134
|
+
selected_options.text.include?(value)
|
135
|
+
else
|
136
|
+
node.isSelected
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# For `<select>` elements returns either 'select-one' for
|
141
|
+
# `<select>`s where only a single `<option>` can be selected, or
|
142
|
+
# 'select-multiple' otherwise. For non-`<select>` elements returns
|
143
|
+
# the `type` attribute.
|
144
|
+
def type
|
145
|
+
if tag_name == 'SELECT'
|
146
|
+
attr(:multiple) == 'multiple' ? 'select-multiple' : 'select-one'
|
147
|
+
else
|
148
|
+
attr(:type)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Gets the colspan attribute as an integer.
|
153
|
+
#
|
154
|
+
# @return [Fixnum] the colspan
|
155
|
+
def colspan
|
156
|
+
attr(:colspan).to_i
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def assert_enabled!
|
162
|
+
raise OperaWatir::Exceptions::ObjectDisabledException if disabled?
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|