xautobrowse 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f041542a7d5cdda69ec2726ce75c83a6fc4f3b2c
4
- data.tar.gz: 0adcae5ccff6385fd401cac25f253e4e4adb3ffb
3
+ metadata.gz: 6bd962c21e206a637724b51740ca2621b573398a
4
+ data.tar.gz: fa0c8af387436e9ce83e23622acc971ae1eff9ad
5
5
  SHA512:
6
- metadata.gz: 53af8d4f275024df3babe3cfbdb5e7efc1244e3acfbc66a1342312ada412a1c2692410d842b8d7f09ce279e6292a6d6c1ec927d99fd84b2c7fb83ce7e4a4c5f4
7
- data.tar.gz: f38fce05205f41ebe04840fc22241c777a9c1a5714a0632fb6cee1e9a637afbd9dde35c4ee4a240681ea5a57104552df36fb49ca4a7486efdbed01444403f63b
6
+ metadata.gz: dfceccbff97cefc1b71dbcc6cf29d26e80452c4540a096544f32b577f8ebb7e6b9851d80112e87895daa0621f69078d577fa9cccb62d91ca5e7cd90923e18161
7
+ data.tar.gz: f245d6273bea4465e09a20d407cf6142a51ac02cf7b3e5eb55d9ac9816b22869f30a46d37ed45c601e33a0c2f50a962c802d6327a626d234d088480d7c5109cb
checksums.yaml.gz.sig CHANGED
@@ -1 +1,3 @@
1
- U(V���u�7,�y�����2��DJ]?b��;0��W8[qE��.w_ 5��j�RUP���
1
+ G��t�_٧IV_] D
2
+
3
+ ���R��������?E�2^R�[��'�+��ߚ�ZN���?G��~��#���H�BrYNћJ�fB��@�]���u�t4Q��ŮG���e3�i�E"K���4�z�ص]�m�� ��3W�D5���ס��9�<rQ���cNt��D>�� �H����v�0�μ,�փ�^��������:��ׯ�ʯ�+�)rdF��� x�c`��NY������WԤp��Z��-[y��
data/lib/xautobrowse.rb CHANGED
@@ -5,6 +5,12 @@
5
5
  # description: Runs on an X Windows system (e.g. Debian running LXDE)
6
6
  # Primarily tested using Firefox (52.6.0 (64-bit)) on Debian.
7
7
 
8
+
9
+ # modifications
10
+
11
+ # 28 Jan 2018: feature: Chromium is now supported
12
+
13
+
8
14
  require 'wmctrl'
9
15
  require 'nokorexi'
10
16
  require 'clipboard'
@@ -16,14 +22,15 @@ require "xdo/xwindow"
16
22
 
17
23
  class XAutoBrowse
18
24
 
19
- def initialize(browser_name, debug: false)
25
+ def initialize(browser= :firefox, debug: false)
20
26
 
21
- @debug = debug
27
+ @browser, @debug = browser, debug
22
28
 
23
29
  @wm = WMCtrl.instance
24
- spawn(browser_name)
25
- sleep 4
26
- id = XDo::XWindow.wait_for_window(browser_name)
30
+ spawn(browser.to_s)
31
+ sleep 5
32
+
33
+ id = XDo::XWindow.wait_for_window(browser)
27
34
  xwin = XDo::XWindow.new(id)
28
35
  title = xwin.title
29
36
  puts 'title: ' + title.inspect if @debug
@@ -32,7 +39,7 @@ class XAutoBrowse
32
39
 
33
40
  a = @wm.list_windows true
34
41
  puts 'a: ' + a.inspect if @debug
35
- r = a.find {|x| x[:title] =~ /#{browser_name}$/i}
42
+ r = a.reverse.find {|x| x[:title] =~ /#{browser}$/i}
36
43
  @id = r[:id]
37
44
 
38
45
  @x, @y, @width, @height = *r[:geometry]
@@ -57,6 +64,7 @@ class XAutoBrowse
57
64
 
58
65
  activate()
59
66
  sleep 2
67
+
60
68
  if block_given? then
61
69
  yield(self)
62
70
  end
@@ -71,9 +79,8 @@ class XAutoBrowse
71
79
  sleep 0.5
72
80
  XDo::Keyboard.ctrl_l
73
81
  sleep 0.5
74
- XDo::Keyboard.type(url)
75
- XDo::Keyboard.return
76
- sleep 5
82
+ enter(url)
83
+ sleep 4
77
84
 
78
85
  end
79
86
 
@@ -89,25 +96,19 @@ class XAutoBrowse
89
96
 
90
97
  def text_field(klass: nil, id: nil, name: nil, value: '')
91
98
 
92
- XDo::Keyboard.ctrl_shift_k # web console
93
- sleep 5
99
+ console = @browser == :firefox ? :ctrl_shift_k : :ctrl_shift_i
100
+ XDo::Keyboard.send console # web console
94
101
 
95
- if klass then
96
- XDo::Keyboard.type("r = document.querySelector('#{klass}')")
102
+ sleep 3
103
+
104
+ cmd = if klass then
105
+ "r = document.querySelector('#{klass}')"
97
106
  elsif id then
98
- XDo::Keyboard.type("r = document.getElementById(\"#{id}\")")
107
+ "r = document.getElementById(\"#{id}\")"
99
108
  end
100
- sleep 3
101
- XDo::Keyboard.return
102
- sleep 2
103
- XDo::Keyboard.type("r.value = \"\"")
104
- sleep 2
105
- XDo::Keyboard.return
106
- sleep 1
107
- XDo::Keyboard.type("r.focus()")
108
- sleep 2
109
- XDo::Keyboard.return
110
- sleep 2
109
+
110
+ [cmd, "r.value = \"\"", "r.focus()"].each {|x| enter x}
111
+
111
112
  XDo::Keyboard.ctrl_shift_i # toggle tools
112
113
  sleep 2
113
114
  XDo::Keyboard.type(value)
@@ -131,6 +132,14 @@ class XAutoBrowse
131
132
  sleep 0.5
132
133
  XDo::Keyboard.ctrl_u # View source code
133
134
  end
135
+
136
+ private
137
+
138
+ def enter(s)
139
+ XDo::Keyboard.type(s)
140
+ sleep 0.8
141
+ XDo::Keyboard.return
142
+ sleep 1
143
+ end
134
144
 
135
145
  end
136
-
data.tar.gz.sig CHANGED
Binary file
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -142,6 +142,5 @@ rubyforge_project:
142
142
  rubygems_version: 2.6.13
143
143
  signing_key:
144
144
  specification_version: 4
145
- summary: A poor man's web automation tool primarily for ' + 'Firefox in an X
146
- windows system.
145
+ summary: A poor man's web automation tool primarily for Firefox in an X windows system.
147
146
  test_files: []
metadata.gz.sig CHANGED
Binary file