Class: Cucumber::Salad::Widgets::Widget

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Conversions
Defined in:
lib/cucumber/salad/widgets/widget.rb

Direct Known Subclasses

Atom, AutoTable::Row, BaseTable, Form, List

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversions

#Boolean, #List, #Timeish

Constructor Details

#initialize(settings = {}) ⇒ Widget

Returns a new instance of Widget.



36
37
38
# File 'lib/cucumber/salad/widgets/widget.rb', line 36

def initialize(settings = {})
  self.root = settings[:root] if settings[:root]
end

Class Method Details

.action(name, selector, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/cucumber/salad/widgets/widget.rb', line 9

def self.action(name, selector, options = {})
  wname = "#{name}_action"

  widget wname, selector, type: options[:type] || Action

  define_method name do
    send(wname).click
  end
end

.root(selector) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/cucumber/salad/widgets/widget.rb', line 19

def self.root(selector)
  define_method :default_root_selector do
    selector
  end

  private :default_root_selector
end

.widget(name, selector, options = {}, &block) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/cucumber/salad/widgets/widget.rb', line 27

def self.widget(name, selector, options = {}, &block)
  type = options.fetch(:type, Atom)
  t    = block_given? ? Class.new(type, &block) : type

  define_method name do
    t.new(root: root.find(selector))
  end
end

Instance Method Details

#inspectObject



40
41
42
43
44
45
# File 'lib/cucumber/salad/widgets/widget.rb', line 40

def inspect
  xml = Nokogiri::HTML(page.body).at(root.path).to_xml

  "<!-- #{self.class.name}: -->\n" <<
   Nokogiri::XML(xml, &:noblanks).to_xhtml
end