Class: TE3270::Emulators::Virtel
- Inherits:
-
Object
- Object
- TE3270::Emulators::Virtel
- Defined in:
- lib/te3270/emulators/virtel.rb
Overview
This class has the code necessary to communicate with the terminal emulator called Virtel. It is a browser based terminal emulator. Watir webdriver (chrome only) is used to drive a browser with VWS (Virtel Web Access) You can use this emulator by providing the :virtel
parameter to the constructor of your screen object or by passing the same value to the emulator_for
method on the TE3270
module.
Constant Summary collapse
- WAIT_SLEEP_INTERVAL =
How long should we sleep during the wait loop.
0.2
Instance Attribute Summary collapse
-
#max_wait_time ⇒ Object
writeonly
Sets the attribute max_wait_time.
-
#url ⇒ Object
writeonly
Sets the attribute url.
Instance Method Summary collapse
-
#connect {|_self| ... } ⇒ Object
Creates a method to connect to Virtel System.
-
#disconnect ⇒ Object
Disconnects the Virtel System connection.
-
#get_string(row, column, length) ⇒ String
Extracts text of specified length from a start point.
-
#initialize ⇒ Virtel
constructor
A new instance of Virtel.
-
#move_to(row, column) ⇒ Object
Moves string at the coordinates specified.
-
#put_string(str, row, column) ⇒ Object
Puts string at the coordinates specified.
-
#screenshot(filename) ⇒ Object
Creates a method to take screenshot of the active screen.
-
#send_keys(keys) ⇒ Object
Sends keystrokes to the host, including function keys.
- #start_virtel_browser ⇒ Object
-
#text ⇒ String
Returns the text of the active screen.
-
#wait_for_host(seconds) ⇒ Object
Waits for the host to not send data for a specified number of seconds.
-
#wait_for_string(str, row, column) ⇒ Object
Wait for the string to appear at the specified location.
-
#wait_until_cursor_at(row, column) ⇒ Object
Waits until the cursor is at the specified location.
Constructor Details
#initialize ⇒ Virtel
Returns a new instance of Virtel.
14 15 16 |
# File 'lib/te3270/emulators/virtel.rb', line 14 def initialize require 'watir-webdriver' end |
Instance Attribute Details
#max_wait_time=(value) ⇒ Object
Sets the attribute max_wait_time
11 12 13 |
# File 'lib/te3270/emulators/virtel.rb', line 11 def max_wait_time=(value) @max_wait_time = value end |
#url=(value) ⇒ Object (writeonly)
Sets the attribute url
11 12 13 |
# File 'lib/te3270/emulators/virtel.rb', line 11 def url=(value) @url = value end |
Instance Method Details
#connect {|_self| ... } ⇒ Object
Creates a method to connect to Virtel System. This method expects a block in which certain platform specific values can be set. Extra can take the following parameters.
-
url - this value is required and should be the url of the session.
-
max_wait_time - max time to wait in wait_for_string (defaults to 10 if not specified)
31 32 33 34 35 36 37 |
# File 'lib/te3270/emulators/virtel.rb', line 31 def connect @max_wait_time = 10 yield self if block_given? start_virtel_browser raise 'The url must be set in a block when calling connect with the Virtel emulator.' if @url.nil? end |
#disconnect ⇒ Object
Disconnects the Virtel System connection
42 43 44 |
# File 'lib/te3270/emulators/virtel.rb', line 42 def disconnect @browser.close end |
#get_string(row, column, length) ⇒ String
Extracts text of specified length from a start point.
54 55 56 57 58 |
# File 'lib/te3270/emulators/virtel.rb', line 54 def get_string(row, column, length) @browser.execute_script <<-JS return VIR3270.collectText("#{row}", "#{column}", 1, "#{length}"); JS end |
#move_to(row, column) ⇒ Object
Moves string at the coordinates specified.
81 82 83 84 85 86 87 88 |
# File 'lib/te3270/emulators/virtel.rb', line 81 def move_to(row, column) @browser.execute_script <<-JS var row = parseInt("#{row}", 10); var col = parseInt("#{column}", 10); VIR3270.moveCursorToPos(VIR3270.posFromRowCol(row, col)); JS end |
#put_string(str, row, column) ⇒ Object
Puts string at the coordinates specified.
67 68 69 70 71 72 73 |
# File 'lib/te3270/emulators/virtel.rb', line 67 def put_string(str, row, column) move_to(row, column) @browser.execute_script <<-JS VIR3270.pasteByTyping("#{str}"); JS quiet_period end |
#screenshot(filename) ⇒ Object
Creates a method to take screenshot of the active screen.
184 185 186 187 188 |
# File 'lib/te3270/emulators/virtel.rb', line 184 def screenshot(filename) File.delete(filename) if File.exists?(filename) @browser.screenshot.save(filename) end |
#send_keys(keys) ⇒ Object
Sends keystrokes to the host, including function keys.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/te3270/emulators/virtel.rb', line 95 def send_keys(keys) char_input_keys = ['ErEof','Reset'] if char_input_keys.include?(keys) @browser.execute_script <<-JS VIR3270.charInput("#{keys}"); JS else @browser.execute_script <<-JS sendWithSpecialKey("#{keys}"); JS end quiet_period end |
#start_virtel_browser ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/te3270/emulators/virtel.rb', line 190 def start_virtel_browser begin @browser = Watir::Browser.new :chrome @browser.goto(@url) rescue Exception => e $stderr.puts e end end |
#text ⇒ String
Returns the text of the active screen
173 174 175 176 177 |
# File 'lib/te3270/emulators/virtel.rb', line 173 def text @browser.execute_script <<-JS VIR3270.collectText(1,1,VIR3270.rows,VIR3270.cols) JS end |
#wait_for_host(seconds) ⇒ Object
Waits for the host to not send data for a specified number of seconds
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/te3270/emulators/virtel.rb', line 131 def wait_for_host(seconds) milliseconds = seconds * 1000 sleep(WAIT_SLEEP_INTERVAL) @browser.execute_script <<-JS function virtelWaiting(){ if (VIR3270.waitlocked === false) {return true;} else {return false;} }; function waitOnVirtel(){ for (var count = 1; ; count++) { if (setInterval(virtelWaiting(), 200)) { return true; } } } setTimeout(waitOnVirtel(), "#{milliseconds}"); JS end |
#wait_for_string(str, row, column) ⇒ Object
Wait for the string to appear at the specified location
116 117 118 119 120 121 122 123 124 |
# File 'lib/te3270/emulators/virtel.rb', line 116 def wait_for_string(str, row, column) total_time = 0.0 sleep_time = 0.5 while get_string(row, column, str.length) != str do sleep sleep_time total_time = total_time + sleep_time break if total_time >= @max_wait_time end end |
#wait_until_cursor_at(row, column) ⇒ Object
Waits until the cursor is at the specified location.
160 161 162 163 164 165 166 |
# File 'lib/te3270/emulators/virtel.rb', line 160 def wait_until_cursor_at(row, column) wait_until do @browser.execute_script <<-JS return (VIR3270.rowFromPos(VIR3270.cursorPosn) === parseInt("#{row}", 10)) && (VIR3270.colFromPos(VIR3270.cursorPosn) === parseInt("#{column}", 10)) JS end end |