te3270-jruby 0.1-x86-mingw32
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/ChangeLog +2 -0
- data/Gemfile +11 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +88 -0
- data/Rakefile +6 -0
- data/ext/mkrf_conf.rb +19 -0
- data/lib/te3270/accessors.rb +30 -0
- data/lib/te3270/emulator_factory.rb +21 -0
- data/lib/te3270/emulators/extra.rb +224 -0
- data/lib/te3270/emulators/quick3270.rb +206 -0
- data/lib/te3270/function_keys.rb +78 -0
- data/lib/te3270/screen_factory.rb +51 -0
- data/lib/te3270/version.rb +4 -0
- data/lib/te3270.rb +166 -0
- data/spec/lib/te3270/accessors_spec.rb +50 -0
- data/spec/lib/te3270/emulators/extra_spec.rb +182 -0
- data/spec/lib/te3270/emulators/quick3270_spec.rb +146 -0
- data/spec/lib/te3270/screen_factory_spec.rb +48 -0
- data/spec/lib/te3270_spec.rb +98 -0
- data/spec/spec_helper.rb +67 -0
- data/te3270.gemspec +29 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0f0098ace54a7e8096d10bf8bd299049547189c
|
4
|
+
data.tar.gz: 8ba9e549544c8f1d87e3290ce5534708584470a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74fdd9bf36403bbbc924ab75d7deebd3157ce74589ce6952992a7a5bcd53341ec98e33d58c95814bd749774c9a9a967f794055bb764b161c7f2dbf2bbb80ad2d
|
7
|
+
data.tar.gz: 580038c7636473ee0f29a9a64990b932ae9b774f500d034a55a7ff4350b2ea11461053fe187931c4827d620440ba8c021a4a3c9de5f7c5f5cb29c383a6a28e32
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/ChangeLog
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pradeep K. Macharla
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# TE3270 for jruby
|
2
|
+
|
3
|
+
This gem can be used to drive a 3270 terminal emulator in a ruby environment (jruby and non-jruby). The code has been tested on jruby 1.7.10 and mruby 2.0.x
|
4
|
+
You have to have a supported emulator installed on the
|
5
|
+
machines on which you use the gem. Currently the only supported emulators are
|
6
|
+
[EXTRA! X-treme](http://www.attachmate.com/Products/Terminal+Emulation/Extra/xtreme/extra-x-treme.htm) by
|
7
|
+
Attachmate and [Quick3270](http://www.dn-computing.com/Quick3270.htm) by DN-Computing. These are commercial
|
8
|
+
products and you will need to purchase one of them in order to use this gem. We do plan to support other
|
9
|
+
emulators as time permits.
|
10
|
+
|
11
|
+
## Documentation
|
12
|
+
|
13
|
+
You can view the RDocs for this project [here](http://rubydoc.info/gems/te3270-jruby/0.1/frames).
|
14
|
+
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'te3270-jruby'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install te3270-jruby
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
You can create classes that are similar to page-object classes. In these classes you can define
|
33
|
+
the various fields that you wish to interact with on the screen.
|
34
|
+
|
35
|
+
class MainframeScreen
|
36
|
+
include TE3270
|
37
|
+
|
38
|
+
text_field(:userid, 10, 30, 20)
|
39
|
+
text_field(:password, 12, 30, 20)
|
40
|
+
|
41
|
+
def login(username, password)
|
42
|
+
self.userid = username
|
43
|
+
self.password = password
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
emulator = TE3270.emulator_for :extra do |platform|
|
48
|
+
platform.session_file = 'sessionfile.edp'
|
49
|
+
end
|
50
|
+
my_screen = MainframeScreen.new(emulator)
|
51
|
+
my_screen.userid = 'the_id'
|
52
|
+
my_screen.password = 'the_password'
|
53
|
+
|
54
|
+
If you are using this gem with cucumber then you can register the ScreenFactory module with the
|
55
|
+
cucumber World like this:
|
56
|
+
|
57
|
+
World(TE3270::ScreenFactory)
|
58
|
+
|
59
|
+
You also need to setup some hooks to start and stop the emulator:
|
60
|
+
|
61
|
+
Begin do
|
62
|
+
@emulator = TE3270.emulator_for :extra do |platform|
|
63
|
+
platform.session_file = 'sessionfile.edp'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
After do
|
68
|
+
TE3270.disconnect(@emulator)
|
69
|
+
end
|
70
|
+
|
71
|
+
This allows you to use the `on` method in your step definitions like this:
|
72
|
+
|
73
|
+
on(MainframeScreen).login('the_user', 'the_password')
|
74
|
+
|
75
|
+
or you can use the version of `on` that takes a block like this:
|
76
|
+
|
77
|
+
on(MainframeScreen) do |screen|
|
78
|
+
screen.userid = 'the_id'
|
79
|
+
screen.password = 'the_password'
|
80
|
+
end
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
1. Fork it
|
85
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
86
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
87
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
88
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ext/mkrf_conf.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Borrowed from http://www.programmersparadox.com/2012/05/21/gemspec-loading-dependent-gems-based-on-the-users-system/
|
2
|
+
# The author mentions that this is not the right way to do when installing on different rubies like mruby, jruby, but
|
3
|
+
# seems there is no other solution at this time, if a single gem has to work on both mruby and jruby
|
4
|
+
|
5
|
+
begin
|
6
|
+
if RUBY_VERSION > "1.7" and RUBY_PLATFORM == "java"
|
7
|
+
installer.install "jruby-win32ole", ">=0"
|
8
|
+
else
|
9
|
+
installer.install "win32screenshot", ">=0"
|
10
|
+
end
|
11
|
+
|
12
|
+
rescue
|
13
|
+
#Exit with a non-zero value to let rubygems know something went wrong
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w")
|
18
|
+
f.write("task :default\n")
|
19
|
+
f.close
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module TE3270
|
3
|
+
module Accessors
|
4
|
+
|
5
|
+
#
|
6
|
+
# adds two methods to the screen object - one to set text in a text field,
|
7
|
+
# another to retrieve text from a text field.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# text_field(:first_name, 23,45,20)
|
11
|
+
# # will generate 'first_name', 'first_name=' method
|
12
|
+
#
|
13
|
+
# @param [String] the name used for the generated methods
|
14
|
+
# @param [FixedNum] row number of the location
|
15
|
+
# @param [FixedNum] column number of the location
|
16
|
+
# @param [FixedNum] length of the text field
|
17
|
+
# @param [true|false] editable is by default true
|
18
|
+
#
|
19
|
+
def text_field(name, row, column, length, editable=true)
|
20
|
+
define_method(name) do
|
21
|
+
platform.get_string(row, column, length)
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method("#{name}=") do |value|
|
25
|
+
platform.put_string(value, row, column)
|
26
|
+
end if editable
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'te3270/emulators/extra'
|
2
|
+
require 'te3270/emulators/quick3270'
|
3
|
+
|
4
|
+
module TE3270
|
5
|
+
#
|
6
|
+
# Provides a mapping between a key used in the +emulator_for+ method
|
7
|
+
# and the class that implements the access to the emulator.
|
8
|
+
#
|
9
|
+
module EmulatorFactory
|
10
|
+
|
11
|
+
EMULATORS = {
|
12
|
+
extra: TE3270::Emulators::Extra,
|
13
|
+
quick3270: TE3270::Emulators::Quick3270
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.emulator_for(platform)
|
17
|
+
EMULATORS[platform]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
module TE3270
|
2
|
+
module Emulators
|
3
|
+
#
|
4
|
+
# This class has the code necessary to communicate with the terminal emulator called EXTRA! X-treme.
|
5
|
+
# You can use this emulator by providing the +:extra+ parameter to the constructor of your screen
|
6
|
+
# object or by passing the same value to the +emulator_for+ method on the +TE3270+ module.
|
7
|
+
#
|
8
|
+
class Extra
|
9
|
+
|
10
|
+
attr_writer :session_file, :visible, :window_state, :max_wait_time
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
if RUBY_PLATFORM == "java"
|
14
|
+
require 'jruby-win32ole'
|
15
|
+
require 'java'
|
16
|
+
include_class 'java.awt.Dimension'
|
17
|
+
include_class 'java.awt.Rectangle'
|
18
|
+
include_class 'java.awt.Robot'
|
19
|
+
include_class 'java.awt.Toolkit'
|
20
|
+
include_class 'java.awt.event.InputEvent'
|
21
|
+
include_class 'java.awt.image.BufferedImage'
|
22
|
+
include_class 'javax.imageio.ImageIO'
|
23
|
+
else
|
24
|
+
require 'win32ole'
|
25
|
+
require 'win32/screenshot'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
#
|
32
|
+
# Creates a method to connect to Extra System. This method expects a block in which certain
|
33
|
+
# platform specific values can be set. Extra can take the following parameters.
|
34
|
+
#
|
35
|
+
# * session_file - this value is required and should be the filename of the session.
|
36
|
+
# * visible - determines if the emulator is visible or not. If not set it will default to +true+.
|
37
|
+
# * window_state - determines the state of the session window. Valid values are +:minimized+,
|
38
|
+
# +:normal+, and +:maximized+. If not set it will default to +:normal+.
|
39
|
+
#
|
40
|
+
# @example Example calling screen object constructor with a block
|
41
|
+
# screen_object = MyScreenObject.new(:extra)
|
42
|
+
# screen_object.connect do |emulator|
|
43
|
+
# emulator.session_file = 'path_to_session_file'
|
44
|
+
# emulator.visible = true
|
45
|
+
# emulator.window_state = :maximized
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
def connect
|
49
|
+
start_extra_system
|
50
|
+
|
51
|
+
yield self if block_given?
|
52
|
+
raise 'The session file must be set in a block when calling connect with the Extra emulator.' if @session_file.nil?
|
53
|
+
open_session
|
54
|
+
@screen = session.Screen
|
55
|
+
@area = screen.SelectAll
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Disconnects the Extra System connection
|
60
|
+
#
|
61
|
+
def disconnect
|
62
|
+
system.Quit
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Extracts text of specified length from a start point.
|
67
|
+
#
|
68
|
+
# @param [Fixnum] row the x coordinate of location on the screen.
|
69
|
+
# @param [Fixnum] column the y coordinate of location on the screen.
|
70
|
+
# @param [Fixnum] length the length of string to extract
|
71
|
+
# @return [String]
|
72
|
+
#
|
73
|
+
def get_string(row, column, length)
|
74
|
+
screen.GetString(row, column, length)
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Puts string at the coordinates specified.
|
79
|
+
#
|
80
|
+
# @param [String] str the string to set
|
81
|
+
# @param [Fixnum] row the x coordinate of the location on the screen.
|
82
|
+
# @param [Fixnum] column the y coordinate of the location on the screen.
|
83
|
+
#
|
84
|
+
def put_string(str, row, column)
|
85
|
+
screen.PutString(str, row, column)
|
86
|
+
quiet_period
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Sends keystrokes to the host, including function keys.
|
91
|
+
#
|
92
|
+
# @param [String] keys keystokes up to 255 in length
|
93
|
+
#
|
94
|
+
def send_keys(keys)
|
95
|
+
screen.SendKeys(keys)
|
96
|
+
quiet_period
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Wait for the string to appear at the specified location
|
101
|
+
#
|
102
|
+
# @param [String] str the string to wait for
|
103
|
+
# @param [Fixnum] row the x coordinate of location
|
104
|
+
# @param [Fixnum] column the y coordinate of location
|
105
|
+
#
|
106
|
+
def wait_for_string(str, row, column)
|
107
|
+
wait_for do
|
108
|
+
screen.WaitForString(str, row, column)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Waits for the host to not send data for a specified number of seconds
|
114
|
+
#
|
115
|
+
# @param [Fixnum] seconds the maximum number of seconds to wait
|
116
|
+
#
|
117
|
+
def wait_for_host(seconds)
|
118
|
+
wait_for(seconds) do
|
119
|
+
screen.WaitHostQuiet
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Waits until the cursor is at the specified location.
|
125
|
+
#
|
126
|
+
# @param [Fixnum] row the x coordinate of the location
|
127
|
+
# @param [Fixnum] column the y coordinate of the location
|
128
|
+
#
|
129
|
+
def wait_until_cursor_at(row, column)
|
130
|
+
wait_for do
|
131
|
+
screen.WaitForCursor(row, column)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Creates a method to take screenshot of the active screen. If you have set the +:visible+
|
137
|
+
# property to false it will be made visible prior to taking the screenshot and then changed
|
138
|
+
# to invisible after.
|
139
|
+
#
|
140
|
+
# @param [String] filename the path and name of the screenshot file to be saved
|
141
|
+
#
|
142
|
+
def screenshot(filename)
|
143
|
+
File.delete(filename) if File.exists?(filename)
|
144
|
+
session.Visible = true unless visible
|
145
|
+
|
146
|
+
if RUBY_PLATFORM == "java"
|
147
|
+
toolkit = Toolkit::getDefaultToolkit()
|
148
|
+
screen_size = toolkit.getScreenSize()
|
149
|
+
rect = Rectangle.new(screen_size)
|
150
|
+
robot = Robot.new
|
151
|
+
image = robot.createScreenCapture(rect)
|
152
|
+
f = java::io::File.new(filename)
|
153
|
+
ImageIO::write(image, "png", f)
|
154
|
+
else
|
155
|
+
hwnd = session.WindowHandle
|
156
|
+
Win32::Screenshot::Take.of(:window, hwnd: hwnd).write(filename)
|
157
|
+
end
|
158
|
+
|
159
|
+
session.Visible = false unless visible
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# Returns the text of the active screen
|
164
|
+
#
|
165
|
+
# @return [String]
|
166
|
+
#
|
167
|
+
def text
|
168
|
+
area.Value
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
attr_reader :system, :sessions, :session, :screen, :area
|
174
|
+
|
175
|
+
WINDOW_STATES = {
|
176
|
+
minimized: 0,
|
177
|
+
normal: 1,
|
178
|
+
maximized: 2
|
179
|
+
}
|
180
|
+
|
181
|
+
def wait_for(seconds = system.TimeoutValue / 1000)
|
182
|
+
wait_collection = yield
|
183
|
+
wait_collection.Wait(seconds * 1000)
|
184
|
+
end
|
185
|
+
|
186
|
+
def quiet_period
|
187
|
+
wait_for_host(max_wait_time)
|
188
|
+
end
|
189
|
+
|
190
|
+
def max_wait_time
|
191
|
+
@max_wait_time ||= 1
|
192
|
+
end
|
193
|
+
|
194
|
+
def window_state
|
195
|
+
@window_state.nil? ? 1 : WINDOW_STATES[@window_state]
|
196
|
+
end
|
197
|
+
|
198
|
+
def visible
|
199
|
+
@visible.nil? ? true : @visible
|
200
|
+
end
|
201
|
+
|
202
|
+
def hide_splash_screen
|
203
|
+
version = system.Version
|
204
|
+
sessions.VisibleOnStartup = true if version.to_i >= 9
|
205
|
+
end
|
206
|
+
|
207
|
+
def open_session
|
208
|
+
@sessions = system.Sessions
|
209
|
+
hide_splash_screen
|
210
|
+
@session = sessions.Open @session_file
|
211
|
+
@session.WindowState = window_state
|
212
|
+
@session.Visible = visible
|
213
|
+
end
|
214
|
+
|
215
|
+
def start_extra_system
|
216
|
+
begin
|
217
|
+
@system = WIN32OLE.new('EXTRA.System')
|
218
|
+
rescue Exception => e
|
219
|
+
$stderr.puts e
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
module TE3270
|
2
|
+
module Emulators
|
3
|
+
|
4
|
+
#
|
5
|
+
# This class has the code necessary to communicate with the terminal emulator called Quick3270.
|
6
|
+
# You can use this emulator by providing the +:quick+ parameter to the constructor of your screen
|
7
|
+
# object or by passing the same value to the +emulator_for+ method on the +TE3270+ module.
|
8
|
+
#
|
9
|
+
|
10
|
+
class Quick3270
|
11
|
+
|
12
|
+
attr_writer :session_file, :visible, :max_wait_time
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
if RUBY_PLATFORM == "java"
|
16
|
+
require 'jruby-win32ole'
|
17
|
+
require 'java'
|
18
|
+
|
19
|
+
include_class 'java.awt.Dimension'
|
20
|
+
include_class 'java.awt.Rectangle'
|
21
|
+
include_class 'java.awt.Robot'
|
22
|
+
include_class 'java.awt.Toolkit'
|
23
|
+
include_class 'java.awt.event.InputEvent'
|
24
|
+
include_class 'java.awt.image.BufferedImage'
|
25
|
+
include_class 'javax.imageio.ImageIO'
|
26
|
+
else
|
27
|
+
require 'win32ole'
|
28
|
+
require 'win32/screenshot'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates a method to connect to Quick System. This method expects a block in which certain
|
36
|
+
# platform specific values can be set. Quick can take the following parameters.
|
37
|
+
#
|
38
|
+
# * session_file - this value is required and should be the filename of the session.
|
39
|
+
# * visible - determines if the emulator is visible or not. If not set it will default to +true+.
|
40
|
+
#
|
41
|
+
# @example Example calling screen object constructor with a block
|
42
|
+
# screen_object = MyScreenObject.new(:quick3270)
|
43
|
+
# screen_object.connect do |emulator|
|
44
|
+
# emulator.session_file = 'path_to_session_file'
|
45
|
+
# emulator.visible = true
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
def connect
|
49
|
+
start_quick_system
|
50
|
+
yield self if block_given?
|
51
|
+
raise "The session file must be set in a block when calling connect with the Quick3270 emulator." if @session_file.nil?
|
52
|
+
establish_session
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Disconnects the Quick System connection
|
57
|
+
#
|
58
|
+
def disconnect
|
59
|
+
session.Disconnect
|
60
|
+
system.Application.Quit
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Extracts text of specified length from a start point.
|
65
|
+
#
|
66
|
+
# @param [Fixnum] row the x coordinate of location on the screen.
|
67
|
+
# @param [Fixnum] column the y coordinate of location on the screen.
|
68
|
+
# @param [Fixnum] length the length of string to extract
|
69
|
+
# @return [String]
|
70
|
+
#
|
71
|
+
def get_string(row, column, length)
|
72
|
+
screen.GetString(row, column, length)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Puts string at the coordinates specified.
|
77
|
+
#
|
78
|
+
# @param [String] str the string to set
|
79
|
+
# @param [Fixnum] row the x coordinate of the location on the screen.
|
80
|
+
# @param [Fixnum] column the y coordinate of the location on the screen.
|
81
|
+
#
|
82
|
+
def put_string(str, row, column)
|
83
|
+
screen.MoveTo(row, column)
|
84
|
+
screen.PutString(str)
|
85
|
+
quiet_period
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Sends keystrokes to the host, including function keys.
|
90
|
+
#
|
91
|
+
# @param [String] keys keystokes up to 255 in length
|
92
|
+
#
|
93
|
+
def send_keys(keys)
|
94
|
+
screen.SendKeys(keys)
|
95
|
+
quiet_period
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Wait for the string to appear at the specified location
|
100
|
+
#
|
101
|
+
# @param [String] str the string to wait for
|
102
|
+
# @param [Fixnum] row the x coordinate of location
|
103
|
+
# @param [Fixnum] column the y coordinate of location
|
104
|
+
#
|
105
|
+
def wait_for_string(str, row, column)
|
106
|
+
screen.WaitForString(str, row, column)
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Waits for the host to not send data for a specified number of seconds
|
111
|
+
#
|
112
|
+
# @param [Fixnum] seconds the maximum number of seconds to wait
|
113
|
+
#
|
114
|
+
def wait_for_host(seconds)
|
115
|
+
screen.WaitHostQuiet(seconds * 1000)
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Waits until the cursor is at the specified location.
|
120
|
+
#
|
121
|
+
# @param [Fixnum] row the x coordinate of the location
|
122
|
+
# @param [Fixnum] column the y coordinate of the location
|
123
|
+
#
|
124
|
+
def wait_until_cursor_at(row, column)
|
125
|
+
screen.WaitForCursor(row, column)
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Creates a method to take screenshot of the active screen. If you have set the +:visible+
|
130
|
+
# property to false it will be made visible prior to taking the screenshot and then changed
|
131
|
+
# to invisible after.
|
132
|
+
#
|
133
|
+
# @param [String] filename the path and name of the screenshot file to be saved
|
134
|
+
#
|
135
|
+
def screenshot(filename)
|
136
|
+
File.delete(filename) if File.exists?(filename)
|
137
|
+
system.Visible = true unless visible
|
138
|
+
|
139
|
+
if RUBY_PLATFORM == "java"
|
140
|
+
toolkit = Toolkit::getDefaultToolkit()
|
141
|
+
screen_size = toolkit.getScreenSize()
|
142
|
+
rect = Rectangle.new(screen_size)
|
143
|
+
robot = Robot.new
|
144
|
+
image = robot.createScreenCapture(rect)
|
145
|
+
f = java::io::File.new(filename)
|
146
|
+
ImageIO::write(image, "png", f)
|
147
|
+
system.Visible = false unless visible
|
148
|
+
else
|
149
|
+
hwnd = session.WindowHandle
|
150
|
+
Win32::Screenshot::Take.of(:window, hwnd: hwnd).write(filename)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# Returns the text of the active screen
|
156
|
+
#
|
157
|
+
# @return [String]
|
158
|
+
#
|
159
|
+
def text
|
160
|
+
rows = screen.Rows
|
161
|
+
columns = screen.Cols
|
162
|
+
result = ''
|
163
|
+
rows.times { |row| result += "#{screen.GetString(row+1, 1, columns)}\\n" }
|
164
|
+
result
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
attr_reader :system, :session, :screen
|
170
|
+
|
171
|
+
def quiet_period
|
172
|
+
screen.WaitHostQuiet(max_wait_time)
|
173
|
+
end
|
174
|
+
|
175
|
+
def max_wait_time
|
176
|
+
@max_wait_time ||= 3000
|
177
|
+
end
|
178
|
+
|
179
|
+
def visible
|
180
|
+
@visible.nil? ? true : @visible
|
181
|
+
end
|
182
|
+
|
183
|
+
def start_quick_system
|
184
|
+
begin
|
185
|
+
@system = WIN32OLE.new('Quick3270.Application')
|
186
|
+
rescue Exception => e
|
187
|
+
$stderr.puts e
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def establish_session
|
192
|
+
system.Visible = visible
|
193
|
+
@session = system.ActiveSession
|
194
|
+
session.Open @session_file
|
195
|
+
@screen = session.Screen
|
196
|
+
session.Connect
|
197
|
+
connected = session.Connected
|
198
|
+
while not connected
|
199
|
+
screen.WaitHostQuiet(1000)
|
200
|
+
connected = session.Connected
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|