watir-webdriver 0.0.1.dev4 → 0.0.1.dev5

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1.dev4
1
+ 0.0.1.dev5
@@ -94,6 +94,7 @@ module Watir
94
94
 
95
95
  def refresh
96
96
  @driver.navigate.refresh
97
+ run_checkers
97
98
  end
98
99
 
99
100
  def status
@@ -7,15 +7,35 @@ module Watir
7
7
  @parent, @element_class = parent, element_class
8
8
  end
9
9
 
10
+ #
11
+ # @yieldparam [Watir::BaseElement] element Iterate through the elements in this collection.
12
+ #
13
+
10
14
  def each(&blk)
11
15
  to_a.each(&blk)
12
16
  end
13
17
 
18
+ #
19
+ # @return [Fixnum] The number of elements in this collection.
20
+ #
21
+
14
22
  def length
15
23
  elements.length
16
24
  end
17
25
  alias_method :size, :length
18
26
 
27
+ #
28
+ # Get the element at the given index.
29
+ # Note that this is 0-indexed and not compatible with older Watir implementations.
30
+ #
31
+ # Also note that because of Watir's lazy loading, this will return an Element
32
+ # instance even if the index is out of bounds.
33
+ #
34
+ # @param [Fixnum] n Index of wanted element, 0-indexed
35
+ # @return [Watir::BaseElement] Returns an instance of a Watir::BaseElement subclass
36
+ #
37
+
38
+
19
39
  def [](idx)
20
40
  to_a[idx] || @element_class.new(@parent, :index, idx)
21
41
  end
@@ -23,7 +43,7 @@ module Watir
23
43
  #
24
44
  # First element of this collection
25
45
  #
26
- # @return Watir::BaseElement
46
+ # @return [Watir::BaseElement] Returns an instance of a Watir::BaseElement subclass
27
47
  #
28
48
 
29
49
  def first
@@ -33,7 +53,7 @@ module Watir
33
53
  #
34
54
  # Last element of the collection
35
55
  #
36
- # @return Watir::BaseElement
56
+ # @return [Watir::BaseElement] Returns an instance of a Watir::BaseElement subclass
37
57
  #
38
58
 
39
59
  def last
@@ -1,13 +1,23 @@
1
1
  # encoding: utf-8
2
2
  module Watir
3
+
4
+ #
5
+ # Class representing button elements.
6
+ #
7
+ # This class covers both <button> and <input type="submit|reset|image|button" /> elements.
8
+ #
9
+
3
10
  class Button < HTMLElement
4
11
 
5
12
  # add the attributes from <input>
6
13
  attributes Watir::Input.typed_attributes
7
14
 
8
- def locate
9
- ButtonLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
10
- end
15
+ #
16
+ # Returns the text of the button.
17
+ #
18
+ # For input elements, returns the "value" attribute.
19
+ # For button elements, returns the inner text.
20
+ #
11
21
 
12
22
  def text
13
23
  assert_exists
@@ -21,9 +31,21 @@ module Watir
21
31
  end
22
32
  end
23
33
 
34
+ #
35
+ # Returns true if this element is enabled
36
+ #
37
+ # @return [Boolean]
38
+ #
39
+
24
40
  def enabled?
25
41
  !disabled?
26
42
  end
27
43
 
44
+ private
45
+
46
+ def locate
47
+ ButtonLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
48
+ end
49
+
28
50
  end
29
51
  end
@@ -6,6 +6,18 @@ module Watir
6
6
  container_method :checkbox
7
7
  collection_method :checkboxes
8
8
 
9
+ #
10
+ # Set this checkbox to the given value
11
+ #
12
+ # Example:
13
+ #
14
+ # checkbox.set? #=> false
15
+ # checkbox.set
16
+ # checkbox.set? #=> true
17
+ # checkbox.set(false)
18
+ # checkbox.set? #=> false
19
+ #
20
+
9
21
  def set(bool = true)
10
22
  assert_exists
11
23
  assert_enabled
@@ -17,11 +29,22 @@ module Watir
17
29
  end
18
30
  end
19
31
 
32
+ #
33
+ # returns true if the element is checked
34
+ # @return [Boolean]
35
+ #
36
+
20
37
  def set?
21
38
  assert_exists
22
39
  @element.selected?
23
40
  end
24
41
 
42
+ #
43
+ # Unset this checkbox.
44
+ #
45
+ # Same as +set(false)+
46
+ #
47
+
25
48
  def clear
26
49
  set false
27
50
  end
@@ -6,11 +6,23 @@ module Watir
6
6
  container_method :file_field
7
7
  collection_method :file_fields
8
8
 
9
+ #
10
+ # Set the file field to the given path
11
+ #
12
+ # @param [String] a value
13
+ #
14
+
9
15
  def set(value)
10
16
  assert_exists
11
17
  @element.send_keys value
12
18
  end
13
19
 
20
+ #
21
+ # Return the value of this field
22
+ #
23
+ # @return [String]
24
+ #
25
+
14
26
  def value
15
27
  # since 'value' is an attribute on input fields, we override this here
16
28
  assert_exists
@@ -2,6 +2,12 @@
2
2
  module Watir
3
3
  class Form
4
4
 
5
+ #
6
+ # Submits the form.
7
+ #
8
+ # This method should be avoided - invoke the user interface element that triggers the submit instead.
9
+ #
10
+
5
11
  def submit
6
12
  assert_exists
7
13
  @element.submit
@@ -5,12 +5,7 @@ module Watir
5
5
 
6
6
  container_method :hidden
7
7
  collection_method :hiddens
8
-
9
- # deprecate?
10
- def value=(val)
11
- raise NotImplementedError
12
- end
13
-
8
+
14
9
  def visible?
15
10
  false
16
11
  end
@@ -4,11 +4,23 @@ module Watir
4
4
 
5
5
  alias_method :loaded?, :complete?
6
6
 
7
+ #
8
+ # returns the image's width in pixels
9
+ #
10
+ # @return [Integer] width
11
+ #
12
+
7
13
  def width
8
14
  assert_exists
9
15
  driver.execute_script "return arguments[0].width", @element
10
16
  end
11
17
 
18
+ #
19
+ # returns the image's height in pixels
20
+ #
21
+ # @return [Integer] height
22
+ #
23
+
12
24
  def height
13
25
  assert_exists
14
26
  driver.execute_script "return arguments[0].height", @element
@@ -8,6 +8,13 @@ module Watir
8
8
  !disabled?
9
9
  end
10
10
 
11
+ #
12
+ # Return the type attribute of the element, or 'text' if the attribute is invalid.
13
+ # TODO: discuss.
14
+ #
15
+ # @return [String]
16
+ #
17
+
11
18
  def type
12
19
  assert_exists
13
20
  value = rescue_no_match { @element.attribute("type").to_s }
@@ -1,17 +1,34 @@
1
1
  # encoding: utf-8
2
2
  module Watir
3
+
4
+ #
5
+ # Represents an option in a select list.
6
+ #
7
+
3
8
  class Option < HTMLElement
4
9
 
10
+ #
11
+ # Select this option
12
+ #
13
+
5
14
  def select
6
15
  assert_exists
7
16
  @element.select
8
17
  end
9
-
18
+
19
+ #
20
+ # Toggle the selected state of this option
21
+ #
22
+
10
23
  def toggle
11
24
  assert_exists
12
25
  @element.toggle
13
26
  end
14
-
27
+
28
+ #
29
+ # Is this option selected?
30
+ #
31
+
15
32
  def selected?
16
33
  assert_exists
17
34
  @element.selected?
@@ -6,6 +6,10 @@ module Watir
6
6
  container_method :radio
7
7
  collection_method :radios
8
8
 
9
+ #
10
+ # Select this radio button.
11
+ #
12
+
9
13
  def set
10
14
  assert_exists
11
15
  assert_enabled
@@ -13,6 +17,10 @@ module Watir
13
17
  @element.click unless set?
14
18
  end
15
19
 
20
+ #
21
+ # Is this radio set?
22
+ #
23
+
16
24
  def set?
17
25
  assert_exists
18
26
  @element.selected?
@@ -6,10 +6,20 @@ module Watir
6
6
  container_method :select_list
7
7
  collection_method :select_lists
8
8
 
9
+ #
10
+ # Returns true if this element is enabled
11
+ #
12
+ # @return [Boolean]
13
+ #
14
+
9
15
  def enabled?
10
16
  !disabled?
11
17
  end
12
18
 
19
+ #
20
+ # Clear all selected options
21
+ #
22
+
13
23
  def clear
14
24
  assert_exists
15
25
 
@@ -20,19 +30,55 @@ module Watir
20
30
  end
21
31
  end
22
32
 
23
- def includes?(str_or_rx)
33
+ #
34
+ # Returns true if the select list has one or more options where text or label matches the given value.
35
+ #
36
+ # @param [String, Regexp] value A value.
37
+ # @return [Boolean]
38
+ #
39
+
40
+ def include?(str_or_rx)
24
41
  assert_exists
42
+ # TODO: optimize similar to selected?
25
43
  options.any? { |e| str_or_rx === e.text }
26
44
  end
45
+ alias_method :includes?, :include?
46
+
47
+ #
48
+ # Select the option(s) whose text or label matches the given string.
49
+ # If this is a multi-select and several options match the value given, all will be selected.
50
+ #
51
+ # @param [String, Regexp] value A value.
52
+ # @raise [Watir::Exception::NoValueFoundException] if the value does not exist.
53
+ # @return [String] The text of the option selected. If multiple options match, returns the first match.
54
+ #
27
55
 
28
56
  def select(str_or_rx)
29
57
  select_by :text, str_or_rx, multiple?
30
58
  end
31
59
 
60
+ #
61
+ # Selects the option(s) whose value attribute matches the given string.
62
+ #
63
+ # @see +select+
64
+ #
65
+ # @param [String, Regexp] value A value.
66
+ # @raise [Watir::Exception::NoValueFoundException] if the value does not exist.
67
+ # @return [String] The option selected. If multiple options match, returns the first match
68
+ #
69
+
32
70
  def select_value(str_or_rx)
33
71
  select_by :value, str_or_rx, multiple?
34
72
  end
35
73
 
74
+ #
75
+ # Returns true if any of the selected options' text or label match the given value.
76
+ #
77
+ # @param [String, Regexp] value A value.
78
+ # @raise [Watir::Exception::UnknownObjectException] if the value does not exist.
79
+ # @return [Boolean]
80
+ #
81
+
36
82
  def selected?(str_or_rx)
37
83
  assert_exists
38
84
  matches = @element.find_elements(:tag_name, 'option').select { |e| str_or_rx === e.text || str_or_rx === e.attribute(:label) }
@@ -44,6 +90,13 @@ module Watir
44
90
  matches.any? { |e| e.selected? }
45
91
  end
46
92
 
93
+ #
94
+ # Returns the value of the first selected option in the select list.
95
+ # Returns nil if no option is selected.
96
+ #
97
+ # @return [String, nil]
98
+ #
99
+
47
100
  def value
48
101
  o = options.find { |e| e.selected? }
49
102
  return if o.nil?
@@ -51,6 +104,11 @@ module Watir
51
104
  o.value
52
105
  end
53
106
 
107
+
108
+ #
109
+ # @return [Array<String>] An array of strings representing the text value of the currently selected options.
110
+ #
111
+
54
112
  def selected_options
55
113
  assert_exists
56
114
  options.map { |e| e.text if e.selected? }.compact
@@ -124,9 +182,9 @@ module Watir
124
182
  def option_xpath_for(how, string)
125
183
  case how
126
184
  when :text
127
- "//option[normalize-space()=#{string.inspect} or @label=#{string.inspect}]"
185
+ "//option[normalize-space()='#{string}' or @label='#{string}']"
128
186
  when :value
129
- "//option[@value=#{string.inspect}]"
187
+ "//option[@value='#{string}']"
130
188
  else
131
189
  raise Error, "unknown how: #{how.inspect}"
132
190
  end
@@ -1,15 +1,27 @@
1
1
  # encoding: utf-8
2
2
  module Watir
3
3
  class Table < HTMLElement
4
-
4
+
5
+ #
6
+ # The table as an 2D Array of strings with the text of each cell.
7
+ #
8
+ # @return [Array<Array<String>>]
9
+ #
10
+
5
11
  def to_a
6
12
  assert_exists
7
-
13
+
8
14
  trs.inject [] do |res, row|
9
- res << row.tds.map { |cell| cell.text }
15
+ res << row.wd.find_elements(:xpath, ".//td | .//th").map { |cell| cell.text }
10
16
  end
11
17
  end
12
-
18
+
19
+ #
20
+ # Get the n'th row of this table.
21
+ #
22
+ # @return Watir::TableRow
23
+ #
24
+
13
25
  def [](idx)
14
26
  row(:index, idx)
15
27
  end
@@ -1,10 +1,18 @@
1
1
  module Watir
2
2
  class TableRow < HTMLElement
3
3
 
4
+ #
5
+ # Get the n'th <td> of this element
6
+ #
7
+ # @return Watir::TableDataCell
8
+ #
9
+
4
10
  def [](idx)
5
11
  td(:index, idx)
6
12
  end
7
13
 
14
+ private
15
+
8
16
  def locate
9
17
  if @parent.kind_of?(Watir::Table)
10
18
  TableRowLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
@@ -8,28 +8,27 @@ module Watir
8
8
  container_method :text_field
9
9
  collection_method :text_fields
10
10
 
11
- def locate
12
- TextFieldLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
13
- end
14
-
15
11
  def inspect
16
- '#<%s:0x%x located=%s selector=%s>' % [self.class, hash*2, !!@element, selector_without_type.inspect]
12
+ '#<%s:0x%x located=%s selector=%s>' % [self.class, hash*2, !!@element, selector_string]
17
13
  end
18
14
 
19
- def selector_string
20
- selector_without_type.inspect
21
- end
15
+ #
16
+ # Clear the element, the type in the given value.
17
+ #
22
18
 
23
19
  def set(*args)
24
20
  assert_exists
25
21
  assert_writable
26
22
 
27
23
  @element.clear
28
-
29
- append(*args)
24
+ @element.send_keys(*args)
30
25
  end
31
26
  alias_method :value=, :set
32
27
 
28
+ #
29
+ # Append the given value to the text in the text field.
30
+ #
31
+
33
32
  def append(*args)
34
33
  assert_exists
35
34
  assert_writable
@@ -37,11 +36,18 @@ module Watir
37
36
  @element.send_keys(*args)
38
37
  end
39
38
 
39
+ #
40
+ # Clear the text field.
41
+ #
42
+
40
43
  def clear
41
44
  assert_exists
42
45
  @element.clear
43
46
  end
44
47
 
48
+ #
49
+ # Returns the text in the text field.
50
+ #
45
51
 
46
52
  def value
47
53
  # since 'value' is an attribute on input fields, we override this here
@@ -51,6 +57,14 @@ module Watir
51
57
 
52
58
  private
53
59
 
60
+ def locate
61
+ TextFieldLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
62
+ end
63
+
64
+ def selector_string
65
+ selector_without_type.inspect
66
+ end
67
+
54
68
  def selector_without_type
55
69
  s = @selector.dup
56
70
  s[:type] = '(any text type)'
@@ -3,6 +3,10 @@ module Watir
3
3
  module XpathSupport
4
4
  include Selenium
5
5
 
6
+ #
7
+ # Find the first element matching the given XPath
8
+ #
9
+
6
10
  def element_by_xpath(xpath)
7
11
  e = wd.find_element(:xpath, xpath)
8
12
  Watir.element_class_for(e.tag_name).new(self, :element, e)
@@ -10,6 +14,10 @@ module Watir
10
14
  BaseElement.new(self, :xpath, xpath)
11
15
  end
12
16
 
17
+ #
18
+ # Find all elements matching the given XPath
19
+ #
20
+
13
21
  def elements_by_xpath(xpath)
14
22
  # TODO: find the correct element class
15
23
  wd.find_elements(:xpath, xpath).map do |e|
@@ -26,7 +26,7 @@ describe "TableCell" do
26
26
  browser.cell(:index, 1337).should_not exist
27
27
  browser.cell(:xpath, "//td[@id='no_such_id']").should_not exist
28
28
  end
29
-
29
+
30
30
  it "raises TypeError when 'what' argument is invalid" do
31
31
  lambda { browser.cell(:id, 3.14).exists? }.should raise_error(TypeError)
32
32
  end
@@ -130,7 +130,7 @@ describe "Table" do
130
130
  lambda { browser.table(:id, 'outer').child_cell(1337) }.should raise_error(UnknownCellException)
131
131
  end
132
132
  end
133
-
133
+
134
134
  describe "#each" do
135
135
  it "iterates through the table's rows" do
136
136
  ids = ["outer_first", "outer_second", "outer_last"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.dev4
4
+ version: 0.0.1.dev5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-27 00:00:00 +01:00
12
+ date: 2010-02-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency