xautobrowse 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a98ad02b9ca15c528bd77d851d96d1405a782f3
4
- data.tar.gz: 40feedea4769332549a574708afb3198343f8130
3
+ metadata.gz: dd96b9501e28095dc7b9f4e2c7e24c9a9ebdbd2f
4
+ data.tar.gz: 63143f4863cd56c5076d4142fa434287001bcb15
5
5
  SHA512:
6
- metadata.gz: 6d654981f154feeb36bbe40448f583024e6c9038033307be1a3bd71f9a191dbdd5b6c347ce7db9fc40375e054b4fdcdf9ab33322fe0ec15ea43be56c51e1664d
7
- data.tar.gz: d6cb140ebacd73bb129d003e7672b3e981439745890fe37425a0b60bf1b7dae804e68042bfd5d49471f6b5258a23588cb2ba9915d96bc4732d62705fa0896bdf
6
+ metadata.gz: 15235e79acf072fad0b58a7c68b561ea1d66d5748278f150781f3e9e66d8ed6b6759a08ceb6d49ee9ed1637faae72a8db2f26a13e49b5cc31c48796148f92ef7
7
+ data.tar.gz: 9bc862a4b3ca340f7a1dedd2742400c348879460a7e1376087e7e934247f6eba2a67827d3f7eccf565e2cc6fb885669992d749c87c66dbc4e70618454977dec3
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,4 @@
1
- ��w\
2
- /�)ܧ%��e��FԹoV�Y/ uC�?}S8��_�%�F߯_Ż~��~� �G�'+�i��7LBn'O���J`>agt�~HTDZ(m����#>FN�|`[6p�+�#�ҷ�GhZٻ�Ju� �����AYh*}>���k��“���ދ�[��#��g�t�
1
+ ���`a<_|�@���8<�� r��B_�+�oW�v]�H
2
+ M�+���x2h2U��"K
3
+ WZE�R���)+U��]�38��!ay�b�0p8wk���򒻋
4
+ urјⲮ��6����6�Z+���[�4ʂ��O[�����6t�!�����UXƆ��&���� נ�!+�� j��[_�<8*]�9�b�!_l�+��9C�|�eCN��SsǴ.i��:����R!�;����d2���H�O��4�K:���,��
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- � }(EEweV7�����.z�l���c���eJO{ྕ�u4p��H��u��EZJ[�;vٔ��YMWi���V&-����l�K��AW��>H�-y��~��Jy���Yul�)9j<����� ���3�J��RЂ����Ӑ����3��ZA�q82�!"��#�;(��et&�S�-p������nX�����VB�Ε�m-����{�J5~C��n1 V�
2
- �"+��_�-5E|�\/�‚�9H[�t|W�Ѷz#}
1
+ ͂_Tl'���~���`5C��=�ܣ�Q<z^ἑ��Я���oBF(�1k��%$H5���&�( � {�mI��qRER��-W��
2
+ /�hJv)S��6��q)T���"�p�i�t]����&ܾ$��� @'5|��Sϴ��'�f��~�
3
+ 7��P*[��7!o���Ր�Q��C���O�I��K�� ��_��#�&̡����v��yV�AN�9�Q֨d��yE���ر��^��8�
data/lib/xautobrowse.rb CHANGED
@@ -11,6 +11,8 @@
11
11
  # 30 Jan 2018: feature: Now uses the gem universal_dom_remote to
12
12
  # connect to the browser via websockets.
13
13
  # A window can now be closed remotely.
14
+ # SPS is now optional given there is no secure
15
+ # websockets support
14
16
  # 28 Jan 2018: feature: Chromium is now supported.
15
17
  # A custom accesskey can now be used to jump to an element.
16
18
 
@@ -29,36 +31,78 @@ class XAutoBrowse
29
31
 
30
32
  at_exit() do
31
33
 
32
- puts 'shutting down ...'
33
- EventMachine.stop
34
- SPSPub.notice('shutdown', host: '127.0.0.1', port: '55000'); sleep 0.5
34
+ if @sps then
35
+ puts 'shutting down ...'
36
+ EventMachine.stop
37
+ SPSPub.notice('shutdown', host: '127.0.0.1', port: '55000'); sleep 0.5
38
+ end
35
39
 
36
40
  end
37
41
 
42
+ class Window
43
+
44
+ def initialize(browser)
45
+
46
+ @wm = WMCtrl.instance
47
+ spawn(browser.to_s); sleep 3
48
+
49
+ id = XDo::XWindow.wait_for_window(browser)
50
+ xwin = XDo::XWindow.new(id)
51
+ title = xwin.title
52
+ puts 'title: ' + title.inspect if @debug
38
53
 
39
- def initialize(browser= :firefox, debug: false)
54
+ # WMCtrl is used because XDo is problematic at trying to activate a window
55
+
56
+ a = @wm.list_windows true
57
+ puts 'a: ' + a.inspect if @debug
58
+ r = a.reverse.find {|x| x[:title] =~ /#{browser}$/i}
59
+ @id = r[:id]
40
60
 
41
- @browser, @debug = browser, debug
61
+ @x, @y, @width, @height = *r[:geometry]
62
+ sleep 4
63
+
64
+ end
42
65
 
43
- @wm = WMCtrl.instance
44
- spawn(browser.to_s); sleep 3
66
+ def activate()
67
+ @wm.action_window(@id, :activate)
68
+ end
45
69
 
46
- id = XDo::XWindow.wait_for_window(browser)
47
- @xwin = XDo::XWindow.new(id)
48
- title = @xwin.title
49
- puts 'title: ' + title.inspect if @debug
50
-
51
- # WMCtrl is used because XDo is problematic at trying to activate a window
70
+ def height=(val)
71
+ @height = val
72
+ @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
73
+ end
52
74
 
53
- a = @wm.list_windows true
54
- puts 'a: ' + a.inspect if @debug
55
- r = a.reverse.find {|x| x[:title] =~ /#{browser}$/i}
56
- @id = r[:id]
75
+ def move(x,y)
76
+ @x, @y = x, y
77
+ @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
78
+ end
79
+
80
+ def resize_to(width, height)
81
+ @width, @height = width, height
82
+ @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
83
+ end
84
+
85
+ alias resize resize_to
86
+
87
+ def width=(val)
88
+ @width = val
89
+ @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
90
+ end
91
+ end
92
+
93
+ attr_reader :window
94
+
95
+
96
+ def initialize(browser= :firefox, debug: false, sps: false)
57
97
 
58
- @x, @y, @width, @height = *r[:geometry]
98
+ @browser, @debug = browser, debug
99
+
100
+ @window = Window.new browser
101
+ sleep 4
59
102
  Thread.new { open_web_console(); sleep 1; close_web_console() }
60
103
 
61
- connect()
104
+ @sps = sps
105
+ connect() if sps
62
106
 
63
107
  end
64
108
 
@@ -68,18 +112,13 @@ class XAutoBrowse
68
112
  def accesskey(key) send_keys(key.to_sym) end
69
113
 
70
114
  alias access_key accesskey
71
-
72
- def activate()
73
- @wm.action_window(@id, :activate)
74
- end
75
-
76
115
 
77
116
  # Attaches the SPS client to the web browser. The SPS broker must be
78
117
  # started before the code can be attached. see start_broker()
79
118
  #
80
119
  def attach_console(autohide: true)
81
120
 
82
- activate()
121
+ @window.activate()
83
122
  open_web_console(); sleep 1
84
123
 
85
124
  clipboard = Clipboard.paste
@@ -97,7 +136,7 @@ class XAutoBrowse
97
136
  end
98
137
 
99
138
  def close_web_console()
100
- activate()
139
+ @window.activate()
101
140
  ctrl_shift_i()
102
141
  end
103
142
 
@@ -118,18 +157,38 @@ class XAutoBrowse
118
157
 
119
158
  end
120
159
 
160
+ def copy_screen()
161
+ select_all(); sleep 2; ctrl_c(); sleep 2
162
+ unselect_all()
163
+ Clipboard.paste
164
+ end
165
+
166
+ alias scrape_screen copy_screen
167
+
121
168
  def copy_source()
122
169
 
123
170
  view_source(); sleep 3
124
- ctrl_a() # select all
171
+ select all()
125
172
  sleep 1
126
173
  ctrl_c() # copy the source code to the clipboard
174
+ sleep 1
175
+ ctrl_w() # close the viewsource window
127
176
 
128
177
  end
129
178
 
130
179
  # select all
131
180
  #
132
181
  def ctrl_a() send_keys(:ctrl_a) end
182
+
183
+ # unselect all
184
+ #
185
+ def ctrl_shift_a()
186
+
187
+ XDo::Keyboard.key_down('shift')
188
+ send_keys(:ctrl_a)
189
+ XDo::Keyboard.key_up('shift')
190
+
191
+ end
133
192
 
134
193
  # copy
135
194
  #
@@ -154,19 +213,14 @@ class XAutoBrowse
154
213
  # developer tools
155
214
  #
156
215
  def ctrl_shift_i() send_keys(:ctrl_shift_i) end
157
-
158
- def height=(val)
159
- @height = val
160
- @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
161
- end
162
-
216
+
163
217
  # submit a form by pressing return
164
218
  #
165
219
  def go()
166
220
 
167
221
  if block_given? then
168
222
 
169
- activate(); sleep 2
223
+ @window.activate(); sleep 2
170
224
  yield(self)
171
225
  carriage_return()
172
226
 
@@ -174,26 +228,17 @@ class XAutoBrowse
174
228
 
175
229
  end
176
230
 
177
- def goto(url)
231
+ def goto(url, attachconsole: true)
178
232
 
179
- activate(); sleep 0.5
180
- ctrl_l(); sleep 0.5
181
- enter(url); sleep 4
182
- attach_console()
233
+ @window.activate(); sleep 2
234
+ ctrl_l(); sleep 1
235
+ enter(url); sleep 7
236
+ attach_console() if @sps and attachconsole
183
237
 
184
238
  end
185
-
186
- def move(x,y)
187
- @x, @y = x, y
188
- @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
189
- end
190
-
191
- def resize(width, height)
192
- @width, @height = width, height
193
- @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
194
- end
195
239
 
196
240
  def carriage_return()
241
+ @window.activate(); sleep 1
197
242
  XDo::Keyboard.return
198
243
  end
199
244
 
@@ -204,13 +249,32 @@ class XAutoBrowse
204
249
  console = @browser == :firefox ? :ctrl_shift_k : :ctrl_shift_i
205
250
  method(console).call # web console
206
251
 
207
- sleep 2
252
+ sleep 2
253
+
254
+ if block_given? then
255
+ yield(self)
256
+ close_web_console()
257
+ end
208
258
 
209
259
  end
210
260
 
211
261
  def send(s)
212
262
  @udr.send s
213
263
  end
264
+
265
+ def select_all()
266
+ ctrl_a()
267
+ end
268
+
269
+ def unselect_all()
270
+
271
+ if @browser == :firefox then
272
+ tab(); shift_tab()
273
+ else
274
+ ctrl_shift_a()
275
+ end
276
+
277
+ end
214
278
 
215
279
  # Starts the simplepubsub broker
216
280
 
@@ -226,8 +290,17 @@ class XAutoBrowse
226
290
  SPSPub.notice 'shutdown', host: '127.0.0.1', port: '55000'
227
291
  end
228
292
 
293
+ def shift_tab(n=1)
294
+
295
+ @window.activate()
296
+ XDo::Keyboard.key_down('shift')
297
+ XDo::Keyboard.simulate("{TAB}" * n)
298
+ XDo::Keyboard.key_up('shift')
299
+
300
+ end
301
+
229
302
  def tab(n=1)
230
- activate()
303
+ @window.activate()
231
304
  XDo::Keyboard.simulate("{TAB}" * n)
232
305
  end
233
306
 
@@ -256,11 +329,11 @@ class XAutoBrowse
256
329
 
257
330
  # type some text
258
331
  #
259
- def type(s) activate(); XDo::Keyboard.type(s) end
332
+ def type(s) @window.activate(); XDo::Keyboard.type(s) end
260
333
 
261
334
  def view_source()
262
335
 
263
- activate(); sleep 0.5
336
+ @window.activate(); sleep 0.5
264
337
  ctrl_l() # jump to the location bar
265
338
  sleep 0.6
266
339
  tab(2); sleep 0.5
@@ -268,10 +341,6 @@ class XAutoBrowse
268
341
 
269
342
  end
270
343
 
271
- def width=(val)
272
- @width = val
273
- @wm.action_window(@id, :move_resize, 0, @x, @y, @width, @height)
274
- end
275
344
 
276
345
  # input some text
277
346
  #
@@ -315,7 +384,7 @@ ws.onmessage = function(event) {
315
384
 
316
385
  def send_keys(keys)
317
386
 
318
- activate(); XDo::Keyboard.send keys.to_sym
387
+ @window.activate(); XDo::Keyboard.send keys.to_sym
319
388
 
320
389
  end
321
390
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xautobrowse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file