LibyuiClient
Ruby gem to interact with YaST applications via libyui-rest-api.
See documentation of the libyui-rest-api project
for more details about server side implementation.
Usage example:
require 'libyui_client'
app = LibyuiClient::App.new(host: 'localhost', port: '9999')
button = app.button(id: 'settime')
button.click
Installing libyui_client
As soon as the gem is in development, run the following command from command line:
gem "libyui_client", :git => "git@github.com:jknphy/libyui_client.git"
Now need to require gem in order to use it.
Initialize the app under control
It is assumed the application is running on localhost:9999
.
Then the code to initialize the application looks like:
require 'libyui_client'
app = LibyuiClient::App.new(host: 'localhost', port: '9999')
Supported widgets
libyui_client supports different types of widgets.
Here are examples of usage:
Button
app.button(id: 'test_id').click
app.button(label: 'test_label').debug_label
Bargraph
app.bargraph(class: YBarGraph).labels
app.bargraph(class: YBarGraph).segments
app.bargraph(class: YBarGraph).values
Checkbox
app.checkbox(id: 'test_id').check
app.checkbox(label: 'test_label', class: 'YCheckBox').checked?
app.checkbox(id: 'test_id').toggle
app.checkbox(label: 'test_label', class: 'YCheckBoxFrame').uncheck
Combobox
app.combobox(id: 'test_id').items
app.combobox(id: 'test_id').select
app.combobox(id: 'test_id').selected_item
app.combobox(label: 'cmbx', class: 'YComboBox').set
Datefield
app.datefield(class: 'YDateField').set(Date.new(2048, 8, 16))
app.datefield(id: 'date').value
Label
app.label(id: 'test_id').heading?
app.label(id: 'test_id').text
app.menubutton(id: 'test_id').click('button1')
Numberbox
app.numberbox(id: 'test_id').min_value
app.numberbox(id: 'test_id').max_value
app.numberbox(id: 'test_id').set(99)
app.numberbox(id: 'test_id').value
Radiobutton
app.radiobutton(id: 'test_id').select
app.radiobutton(id: 'test_id').selected?
Richtext
app.richtext(id: 'test_id').click_link('test_link')
app.richtext(id: 'test_id').text
Tab
app.tab(id: 'test_id').items
app.tab(id: 'test_id').select(value: 'item')
app.tab(id: 'test_id').selected_item
Table
app.table(id: 'test_id').empty?
app.table(id: 'test_id').items
app.table(id: 'test_id').select( value: 'test.item.1', column: 'test.header' )
app.table(id: 'test_id').select(row: 3)
app.table(id: 'test_id').seleted_items
Textbox
app.textbox(id: 'test_id').max_length
app.textbox(id: 'test_id').set('Test Text')
app.textbox(id: 'test_id').password?
app.textbox(id: 'test_id').valid_chars
app.textbox(id: 'test_id').value
TimeField
app.timefield(label: 'time', class: 'YTimeField').set(Time.now)
app.timefield(id: 'time').value
Tree
app.tree(id: 'test_id').items
app.tree(id: 'test_id').select('node1|node1_2')
app.tree(id: 'test_id').selected_item
Filters
libyui_client supports the same filters, as libyui-rest-api provides:
- id - widget ID serialized as string, might include special characters like backtick (`)
- label - widget label as currently displayed (i.e. translated!)
- class - widget class
Also, regex for the filters is allowed.
Example:
app.button(id: /.*test/).debug_label
Waits
Default timeout and interval
All the actions against widgets in libyui_client are made with default timeout and interval.
Default timeout is 5 sec, default interval is 0.5 sec.
That means libyui_client will repeat sending requests to YaST application every 0.5 seconds until 5 seconds
timeout will be reached. This default wait is needed because widgets may not be loaded immediately while trying to
interact with them (e.g. when navigating from one screen to another).
The default timeout and interval can be changed by the following:
LibyuiClient.timeout = 10
LibyuiClient.interval = 1
Specific waits
All the widgets include Waitable module, which contains special methods to allow explicit waiting:
wait_until
and wait_while
.
These methods can be used when it is needed to wait until some property of the widget will be changed.
For example, wait until button will be enabled and click on it:
app.button(id: 'test_id').wait_until(&:enabled?).click
app.button(id: 'test_id').wait_until{ |button| button.enabled? }.click
License
The gem is available as open source under the terms of the MIT License.