Class: YuiRestClient::Widgets::Base

Inherits:
Object
  • Object
show all
Includes:
YuiRestClient::Waitable
Defined in:
lib/yui_rest_client/widgets/base.rb

Instance Method Summary collapse

Methods included from YuiRestClient::Waitable

#wait_until, #wait_while

Constructor Details

#initialize(widget_controller, filter) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/yui_rest_client/widgets/base.rb', line 8

def initialize(widget_controller, filter)
  @widget_controller = widget_controller
  @filter = filter
end

Instance Method Details

#action(params) ⇒ Object

This method can be used to send any action to widget. Can be called against any widget.

Examples:

Send action ‘press’ to button widget.

app.button(id: 'test').action(action: 'press')

Parameters:

  • params (Hash)

    actions to be sent (e.g. action: ‘press’).



75
76
77
78
79
80
81
82
# File 'lib/yui_rest_client/widgets/base.rb', line 75

def action(params)
  unless @filter.regex.empty?
    widget = find_widgets.first
    @filter = FilterExtractor.new(widget)
  end
  YuiRestClient.logger.info("Send #{params} action for #{class_name} #{@filter}")
  @widget_controller.send_action(@filter.plain, params)
end

#collect_allArray

Get all widgets found with filter. The method is mainly introduced for “class” filter, which can return an array of widgets. It only makes sense to use this method whenever server side filters allow to find individually those collected widgets, otherwise those will not be able to access their internal properties. Then actions that are specified for the widget can be called while iterating over the returned array.

Examples:

Get all checkboxes and check all of them

checkboxes = app.checkbox(class: "YCheckBox").collect_all
checkboxes.each{ |checkbox| puts checkbox.check }

Returns:

  • (Array)

    array of deserialized widgets.



93
94
95
96
97
98
99
100
# File 'lib/yui_rest_client/widgets/base.rb', line 93

def collect_all
  YuiRestClient.logger.info("Collect all #{class_name} widgets with filter #{@filter}")
  widgets = find_widgets
  YuiRestClient.logger.info("Found widgets for filter #{@filter}: #{widgets}")
  widgets.map do |widget|
    self.class.new(@widget_controller, FilterExtractor.new(widget))
  end
end

#debug_labelString

Returns debug_label value for widget. Can be called against any widget.

Examples:

Get debug_label value for button

{
  "class": "YQWizardButton",
  "debug_label": "Cancel",
  "fkey": 9,
  "id": "cancel",
  "label": "&Cancel"
}
debug_label = app.button(id: 'cancel').debug_label # Cancel

Returns:

  • (String)

    value of debug_label property



51
52
53
# File 'lib/yui_rest_client/widgets/base.rb', line 51

def debug_label
  property(:debug_label)
end

#enabled?Boolean

Allows to check if widget enabled or disabled. Can be called against any widget. Widget that does not have “enabled” property is counted as enabled.

Examples:

Check if button with id ‘test’ enabled

app.button(id: 'test').enabled? # true

Returns:

  • (Boolean)

    true if widget enabled, false otherwise.



33
34
35
36
# File 'lib/yui_rest_client/widgets/base.rb', line 33

def enabled?
  enabled_prop = property(:enabled)
  enabled_prop.nil? || enabled_prop == true
end

#exists?Boolean

Allows to check if widget exists on the current screen or not. Can be called against any widget.

Examples:

Check if button with id ‘test’ exists

app.button(id: 'test').exists? # true

Returns:

  • (Boolean)

    true if widget exists, false otherwise.



18
19
20
21
22
23
24
25
26
# File 'lib/yui_rest_client/widgets/base.rb', line 18

def exists?
  YuiRestClient.logger.info("Checking if #{class_name} with #{@filter} exists")
  find_widgets
  YuiRestClient.logger.info("#{class_name} exists: #{@filter}")
  true
rescue Error::WidgetNotFoundError
  YuiRestClient.logger.info("#{class_name} does not exist: #{@filter}")
  false
end

#property(property) ⇒ Object

Returns value of widget property. This method can be used to retrieve value of some specific property, but widget does not have a method to return the value. Can be called against any widget.

Examples:

Get value of “label” property for button with id “test”

value = app.button(id: 'test').property(:label)

Parameters:

  • property (Symbol)

    symbolic name of the property to get value for.

Returns:

  • (Object)

    value for property of a widget



63
64
65
66
67
68
# File 'lib/yui_rest_client/widgets/base.rb', line 63

def property(property)
  YuiRestClient.logger.info("Get #{property} for #{class_name} #{@filter}")
  result = find_widgets.first[property.to_sym]
  YuiRestClient.logger.info("Found '#{property}=#{result}' for #{class_name} #{@filter}")
  result
end