Class: Cucumber::Salad::Widgets::Widget
- Inherits:
-
Object
- Object
- Cucumber::Salad::Widgets::Widget
- Extended by:
- Cucumber::Salad::WidgetMacros, Forwardable
- Includes:
- Cucumber::Salad::WidgetContainer
- Defined in:
- lib/cucumber/salad/widgets/widget.rb
Direct Known Subclasses
AutoTable::Row, BaseTable, FieldGroup, FieldGroup::Field, List
Defined Under Namespace
Classes: Reload
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
The root node of the current widget.
Class Method Summary collapse
-
.find_in(node, options = {}) ⇒ Object
Finds a single instance of the current widget in
node
. -
.present_in?(parent_node) ⇒ Boolean
Determines if an instance of this widget class exists in
parent_node
. -
.root(selector) ⇒ Object
Sets this widget’s default selector.
-
.selector ⇒ Object
The selector specified with
root
.
Instance Method Summary collapse
-
#has_action?(name) ⇒ Boolean
Determines if the widget underlying an action exists.
-
#initialize(settings = {}) ⇒ Widget
constructor
A new instance of Widget.
- #inspect ⇒ Object
-
#reload(wait_time = Capybara.default_wait_time) { ... } ⇒ Object
Reloads the widget, waiting for its contents to change (by default), or until
wait_time
expires. - #to_s ⇒ Object
Methods included from Cucumber::Salad::WidgetMacros
action, widget, widget_delegator
Methods included from Cucumber::Salad::WidgetContainer
Constructor Details
Instance Attribute Details
#root ⇒ Object
Returns The root node of the current widget.
44 45 46 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 44 def root @root end |
Class Method Details
.find_in(node, options = {}) ⇒ Object
Finds a single instance of the current widget in node
.
27 28 29 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 27 def self.find_in(node, = {}) new(.merge(root: node.find(selector))) end |
.present_in?(parent_node) ⇒ Boolean
Determines if an instance of this widget class exists in parent_node
.
16 17 18 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 16 def self.present_in?(parent_node) parent_node.has_selector?(selector) end |
.root(selector) ⇒ Object
Sets this widget’s default selector.
34 35 36 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 34 def self.root(selector) @selector = selector end |
.selector ⇒ Object
Returns The selector specified with root
.
39 40 41 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 39 def self.selector @selector end |
Instance Method Details
#has_action?(name) ⇒ Boolean
Determines if the widget underlying an action exists.
60 61 62 63 64 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 60 def has_action?(name) raise Missing, "couldn't find `#{name}' action" unless respond_to?(name) (name) end |
#inspect ⇒ Object
66 67 68 69 70 71 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 66 def inspect xml = Nokogiri::HTML(page.body).at(root.path).to_xml "<!-- #{self.class.name}: -->\n" << Nokogiri::XML(xml, &:noblanks).to_xhtml end |
#reload(wait_time = Capybara.default_wait_time) { ... } ⇒ Object
Reloads the widget, waiting for its contents to change (by default), or until wait_time
expires.
Call this method to make sure a widget has enough time to update itself.
You can pass a block to this method to control what it means for the widget to be reloaded.
*Note: does not account for multiple changes to the widget yet.*
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 95 def reload(wait_time = Capybara.default_wait_time, &test) unless test old_inspect = inspect test = ->{ old_inspect != inspect } end root.synchronize(wait_time) do raise Reload unless test.() end self rescue Reload # raised on timeout self end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/cucumber/salad/widgets/widget.rb', line 112 def to_s node_text(root) end |