yui_rest_client 0.5.0

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/publish.yml +33 -0
  3. data/.github/workflows/test.yml +26 -0
  4. data/.gitignore +15 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +41 -0
  7. data/Gemfile +8 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +216 -0
  10. data/Rakefile +20 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/lib/yui_rest_client.rb +42 -0
  14. data/lib/yui_rest_client/actions.rb +12 -0
  15. data/lib/yui_rest_client/app.rb +230 -0
  16. data/lib/yui_rest_client/error.rb +13 -0
  17. data/lib/yui_rest_client/filter_extractor.rb +28 -0
  18. data/lib/yui_rest_client/http/http_client.rb +36 -0
  19. data/lib/yui_rest_client/http/response.rb +21 -0
  20. data/lib/yui_rest_client/http/version_controller.rb +26 -0
  21. data/lib/yui_rest_client/http/widget_controller.rb +54 -0
  22. data/lib/yui_rest_client/local_process.rb +73 -0
  23. data/lib/yui_rest_client/logger.rb +32 -0
  24. data/lib/yui_rest_client/timer.rb +20 -0
  25. data/lib/yui_rest_client/version.rb +6 -0
  26. data/lib/yui_rest_client/wait.rb +21 -0
  27. data/lib/yui_rest_client/waitable.rb +39 -0
  28. data/lib/yui_rest_client/widgets.rb +30 -0
  29. data/lib/yui_rest_client/widgets/bargraph.rb +62 -0
  30. data/lib/yui_rest_client/widgets/base.rb +114 -0
  31. data/lib/yui_rest_client/widgets/button.rb +33 -0
  32. data/lib/yui_rest_client/widgets/checkbox.rb +53 -0
  33. data/lib/yui_rest_client/widgets/combobox.rb +95 -0
  34. data/lib/yui_rest_client/widgets/datefield.rb +47 -0
  35. data/lib/yui_rest_client/widgets/label.rb +41 -0
  36. data/lib/yui_rest_client/widgets/menubutton.rb +48 -0
  37. data/lib/yui_rest_client/widgets/multilinebox.rb +84 -0
  38. data/lib/yui_rest_client/widgets/numberbox.rb +76 -0
  39. data/lib/yui_rest_client/widgets/progressbar.rb +45 -0
  40. data/lib/yui_rest_client/widgets/radiobutton.rb +35 -0
  41. data/lib/yui_rest_client/widgets/richtext.rb +36 -0
  42. data/lib/yui_rest_client/widgets/selectionbox.rb +87 -0
  43. data/lib/yui_rest_client/widgets/tab.rb +81 -0
  44. data/lib/yui_rest_client/widgets/table.rb +154 -0
  45. data/lib/yui_rest_client/widgets/textbox.rb +94 -0
  46. data/lib/yui_rest_client/widgets/timefield.rb +45 -0
  47. data/lib/yui_rest_client/widgets/tree.rb +149 -0
  48. data/yui_rest_client.gemspec +38 -0
  49. metadata +222 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ea981c5b7efbf645df05748af02a42230510892162b5279634794d527d82ddbc
4
+ data.tar.gz: e3291d947be7d5e0d1d1257766fb4de0ccaf91891c4f53e7b049a05a90596a5d
5
+ SHA512:
6
+ metadata.gz: 2aa47e95d61d4f9e4a6b7a02e81e55af1274c9d93c73bcc5f3856c6389083f482c7cd5fe125a65b0b2061704896f60777542b487a7d3ce24d5a59f69bb58f8ea
7
+ data.tar.gz: 2307d790e8d50ba3abf495d055f283b2ba778b3b9e1655712e0d59d00ddbe0793e41d08bcda5ba52076645e2f46207545f9c624f79e94f4f6521280e3676713c
@@ -0,0 +1,33 @@
1
+ name: Publish Gem
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ name: Publish Gem
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.5
16
+ - name: Install dependencies
17
+ run: bundle install
18
+ - name: Setup credentials
19
+ env:
20
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
21
+ run: |
22
+ cat << EOF > ~/.gem/credentials
23
+ ---
24
+ :rubygems_api_key: $RUBYGEMS_API_KEY
25
+ EOF
26
+ chmod 0600 ~/.gem/credentials
27
+ - name: Build gem
28
+ run: gem build yui_rest_client.gemspec
29
+ - name: Push gem
30
+ run: gem push yui_rest_client*.gem
31
+ - name: Cleanup credentials
32
+ if: always()
33
+ run: rm ~/.gem/credentials
@@ -0,0 +1,26 @@
1
+ name: Test
2
+
3
+ on: pull_request
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.5', '2.6' ]
11
+ name: Ruby ${{ matrix.ruby }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Check version file was changed
15
+ run: |
16
+ git fetch origin master
17
+ git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD master` | grep version.rb
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Run rubocop
24
+ run: bundle exec rubocop
25
+ - name: Run tests
26
+ run: bundle exec rspec
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *.rbc
3
+ .rakeTasks
4
+ .rspec_status
5
+ .vendor
6
+ /.bundle/
7
+ /.yardoc
8
+ /_yardoc/
9
+ /coverage/
10
+ /pkg/
11
+ /spec/reports/
12
+ /tmp/
13
+ doc/
14
+ Gemfile.lock
15
+ y2signal.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,41 @@
1
+ # Cops documentation: https://rubocop.readthedocs.io/en/stable/
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+
6
+ Layout/LineLength:
7
+ Max: 120
8
+
9
+ Layout/SpaceAroundMethodCallOperator:
10
+ Enabled: true
11
+
12
+ Lint/RaiseException:
13
+ Enabled: true
14
+
15
+ Lint/StructNewOverride:
16
+ Enabled: true
17
+
18
+ Lint/UriEscapeUnescape:
19
+ Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - "**/*_spec.rb"
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Style/ExponentialNotation:
29
+ Enabled: true
30
+
31
+ Style/HashEachMethods:
32
+ Enabled: true
33
+
34
+ Style/HashTransformKeys:
35
+ Enabled: true
36
+
37
+ Style/HashTransformValues:
38
+ Enabled: true
39
+
40
+ Metrics/ModuleLength:
41
+ Max: 500
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in yui_rest_client.gemspec
6
+ gemspec
7
+ gem 'rubocop'
8
+ gem 'webmock'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-2020 SUSE LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,216 @@
1
+ # YuiRestClient
2
+
3
+ Ruby gem to interact with YaST applications via libyui-rest-api.
4
+ See documentation of the [libyui-rest-api project](https://github.com/libyui/libyui-rest-api/)
5
+ for more details about server side implementation.
6
+
7
+ Usage example:
8
+
9
+ ```ruby
10
+ require 'yui_rest_client'
11
+
12
+ app = YuiRestClient::App.new(host: 'localhost', port: '9999')
13
+ button = app.button(id: 'settime')
14
+ button.click
15
+ ```
16
+
17
+ ## Installing yui_rest_client
18
+
19
+ As soon as the gem is in development, run the following command from command line:
20
+
21
+ ```
22
+ gem install yui_rest_client
23
+ ```
24
+
25
+ In order to build and install locally run:
26
+ ```
27
+ gem build yui_rest_client.gemspec
28
+ gem install yui_rest_client-*.gem
29
+ ```
30
+
31
+ Now need to require gem in order to use it.
32
+
33
+ ## Initialize the app under control
34
+
35
+ It is assumed the application is running on `localhost:9999`.
36
+ Then the code to initialize the application looks like:
37
+
38
+ ```ruby
39
+ require 'yui_rest_client'
40
+
41
+ app = YuiRestClient::App.new(host: 'localhost', port: '9999')
42
+ ```
43
+
44
+ ## Supported widgets
45
+
46
+ yui_rest_client supports different types of widgets.
47
+
48
+ Here are examples of usage:
49
+
50
+ ### Button
51
+ ```ruby
52
+ app.button(id: 'test_id').click # clicks the button with id 'test_id'
53
+ app.button(label: 'test_label').debug_label # get 'debug_label' value with label 'test_label'
54
+ ```
55
+
56
+ ### Bargraph
57
+ ```ruby
58
+ # Get list of labels in the segments:
59
+ app.bargraph(class: YBarGraph).labels
60
+ # Get array of hashes containing label->value pairs denoting each segment:
61
+ app.bargraph(class: YBarGraph).segments
62
+ # Get list of values in the segments:
63
+ app.bargraph(class: YBarGraph).values
64
+ ```
65
+
66
+ ### Checkbox
67
+ ```ruby
68
+ app.checkbox(id: 'test_id').check # checks the checkbox with id 'test_id'
69
+ app.checkbox(label: 'test_label', class: 'YCheckBox').checked? # gets the state of checkbox with label 'test_label'
70
+ app.checkbox(id: 'test_id').toggle # toggles the checkbox with id 'test_id'
71
+ app.checkbox(label: 'test_label', class: 'YCheckBoxFrame').uncheck # unchecks the checkbox with id 'test_id'
72
+ ```
73
+
74
+ ### Combobox
75
+ ```ruby
76
+ app.combobox(id: 'test_id').items # gets all available items for combobox with id 'test_id'
77
+ app.combobox(id: 'test_id').select # selects the checkbox with id 'test_id'
78
+ app.combobox(id: 'test_id').selected_item # gets the selected item in combobox with id 'test_id'
79
+ app.combobox(label: 'cmbx', class: 'YComboBox').set # Sets custom string to the editable checkbox
80
+ ```
81
+
82
+ ### Datefield
83
+ ```ruby
84
+ # Set date field to 2048-08-16
85
+ app.datefield(class: 'YDateField').set(Date.new(2048, 8, 16))
86
+ app.datefield(id: 'date').value # gets value from datefield with id 'date'
87
+ ```
88
+
89
+ ### Label
90
+ ```ruby
91
+ app.label(id: 'test_id').heading? # gets if label has bold font respresentation with id 'test_id'
92
+ app.label(id: 'test_id').text # gets text from label with id 'test_id'
93
+ ```
94
+
95
+ ### Menubutton
96
+ ```ruby
97
+ app.menubutton(id: 'test_id').click('button1') # clicks on 'button1' of menubutton with id 'test_id'
98
+ ```
99
+
100
+ ### Numberbox
101
+ ```ruby
102
+ app.numberbox(id: 'test_id').min_value # gets min value to be set in numberbox with id 'test_id'
103
+ app.numberbox(id: 'test_id').max_value # gets max value to be set in numberbox with id 'test_id'
104
+ app.numberbox(id: 'test_id').set(99) # sets 99 to numberbox with id 'test_id'
105
+ app.numberbox(id: 'test_id').value # gets value from numberbox with id 'test_id'
106
+ ```
107
+
108
+ ### Radiobutton
109
+ ```ruby
110
+ app.radiobutton(id: 'test_id').select # selects the radiobutton with id 'test_id'
111
+ app.radiobutton(id: 'test_id').selected? # gets the state of radiobutton with id 'test_id'
112
+ ```
113
+
114
+ ### Richtext
115
+ ```ruby
116
+ app.richtext(id: 'test_id').click_link('test_link') # clicks on link "test_link" with id 'test_id'
117
+ app.richtext(id: 'test_id').text # gets text from richtext
118
+ ```
119
+
120
+ ### Tab
121
+ ```ruby
122
+ app.tab(id: 'test_id').items # gets items from tab with id 'test_id'
123
+ app.tab(id: 'test_id').select(value: 'item') # selects specific tab with id 'test_id'
124
+ app.tab(id: 'test_id').selected_item # gets selected tab for tab with id 'test_id'
125
+ ```
126
+
127
+ ### Table
128
+ ```ruby
129
+ # checks if there is not rows in table with id 'test_id':
130
+ app.table(id: 'test_id').empty?
131
+ # gets rows in the table with id 'test_id':
132
+ app.table(id: 'test_id').items
133
+ # selects row in table with value test.item.1 and column test.header:
134
+ app.table(id: 'test_id').select( value: 'test.item.1', column: 'test.header' )
135
+ # selects row with number 3, numeration starts from 0 and corresponds to the order
136
+ # in the list returned by method `items`:
137
+ app.table(id: 'test_id').select(row: 3)
138
+ # gets items currently selected in table with id 'test_id':
139
+ app.table(id: 'test_id').seleted_items
140
+
141
+
142
+ ```
143
+ ### Textbox
144
+ ```ruby
145
+ app.textbox(id: 'test_id').max_length
146
+ app.textbox(id: 'test_id').set('Test Text') # sets "Test Text" to textbox with id 'test_id'
147
+ app.textbox(id: 'test_id').password? # checks password mode for textbox with id 'test_id'
148
+ app.textbox(id: 'test_id').valid_chars # checks valid chars for textbox with id 'test_id'
149
+ app.textbox(id: 'test_id').value # gets value from textbox with id 'test_id'
150
+ ```
151
+
152
+ ### TimeField
153
+ ```ruby
154
+ # Set TimeField to current time
155
+ app.timefield(label: 'time', class: 'YTimeField').set(Time.now)
156
+ app.timefield(id: 'time').value # gets value from timefield with id 'time'
157
+ ```
158
+
159
+ ### Tree
160
+ ```ruby
161
+ app.tree(id: 'test_id').items # gets items from tree with id 'test_id'
162
+ app.tree(id: 'test_id').select('node1|node1_2') # selects item in tree with id 'test_id'
163
+ app.tree(id: 'test_id').selected_item # gets currently highlighted item from tree with id 'test_id'
164
+ ```
165
+
166
+ ## Filters
167
+
168
+ yui_rest_client supports the same filters, as libyui-rest-api provides:
169
+
170
+ * id - widget ID serialized as string, might include special characters like backtick (\`)
171
+ * label - widget label as currently displayed (i.e. translated!)
172
+ * class - widget class
173
+
174
+ Also, regex for the filters is allowed.
175
+
176
+ Example:
177
+ ```ruby
178
+ app.button(id: /.*test/).debug_label
179
+ ```
180
+
181
+ ## Waits
182
+
183
+ ### Default timeout and interval
184
+
185
+ All the actions against widgets in yui_rest_client are made with default timeout and interval.
186
+ Default timeout is 5 sec, default interval is 0.5 sec.
187
+ That means yui_rest_client will repeat sending requests to YaST application every 0.5 seconds until 5 seconds
188
+ timeout will be reached. This default wait is needed because widgets may not be loaded immediately while trying to
189
+ interact with them (e.g. when navigating from one screen to another).
190
+
191
+ The default timeout and interval can be changed by the following:
192
+
193
+ ```ruby
194
+ YuiRestClient.timeout = 10
195
+ YuiRestClient.interval = 1
196
+ ```
197
+
198
+ ### Specific waits
199
+
200
+ All the widgets include Waitable module, which contains special methods to allow explicit waiting:
201
+ `wait_until` and `wait_while`.
202
+ These methods can be used when it is needed to wait until some property of the widget will be changed.
203
+
204
+ For example, wait until button will be enabled and click on it:
205
+
206
+ ```ruby
207
+ # with #to_proc syntax:
208
+ app.button(id: 'test_id').wait_until(&:enabled?).click
209
+
210
+ # without #to_proc syntax:
211
+ app.button(id: 'test_id').wait_until{ |button| button.enabled? }.click
212
+ ```
213
+
214
+ ## License
215
+
216
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
9
+
10
+ task :integration do
11
+ RSpec::Core::RakeTask.new(:integration) do |t|
12
+ t.pattern = 'spec/widgets/*_spec.rb'
13
+ end
14
+ end
15
+
16
+ task :unit do
17
+ RSpec::Core::RakeTask.new(:unit) do |t|
18
+ t.pattern = 'spec/unit/**/*_spec.rb'
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'yui_rest_client'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'uri'
7
+ require 'timeout'
8
+ require 'time'
9
+
10
+ require 'yui_rest_client/version'
11
+ require 'yui_rest_client/local_process'
12
+ require 'yui_rest_client/widgets'
13
+ require 'yui_rest_client/logger'
14
+ require 'yui_rest_client/timer'
15
+ require 'yui_rest_client/wait'
16
+ require 'yui_rest_client/app'
17
+ require 'yui_rest_client/http/http_client'
18
+ require 'yui_rest_client/http/response'
19
+ require 'yui_rest_client/http/version_controller'
20
+ require 'yui_rest_client/http/widget_controller'
21
+ require 'yui_rest_client/error'
22
+ require 'yui_rest_client/actions'
23
+ require 'yui_rest_client/filter_extractor'
24
+
25
+ # Client to interact with YAST UI rest api framework for integration testing
26
+ module YuiRestClient
27
+ class << self
28
+ attr_writer :timeout, :interval
29
+
30
+ def timeout
31
+ @timeout ||= 5
32
+ end
33
+
34
+ def interval
35
+ @interval ||= 0.5
36
+ end
37
+ end
38
+
39
+ def self.logger
40
+ @logger ||= YuiRestClient::Logger.new
41
+ end
42
+ end