Class: TE3270::Emulators::Virtel

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeVirtel

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

Parameters:

  • value

    the value to set the attribute max_wait_time to.



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

Parameters:

  • value

    the value to set the attribute url to.



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)

Examples:

Example calling screen object constructor with a block

screen_object = MyScreenObject.new(:virtel)
screen_object.connect do |emulator|
  emulator.url = 'http://mainframe:41001/w2h/WEB2AJAX.htm+Sessmgr'
end

Yields:

  • (_self)

Yield Parameters:



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

#disconnectObject

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.

Parameters:

  • row (Fixnum)

    the x coordinate of location on the screen.

  • column (Fixnum)

    the y coordinate of location on the screen.

  • length (Fixnum)

    the length of string to extract

Returns:

  • (String)


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.

Parameters:

  • row (Fixnum)

    the x coordinate of the location on the screen.

  • column (Fixnum)

    the y coordinate of the location on the screen.



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.

Parameters:

  • str (String)

    the string to set

  • row (Fixnum)

    the x coordinate of the location on the screen.

  • column (Fixnum)

    the y coordinate of the location on the screen.



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.

Parameters:

  • filename (String)

    the path and name of the screenshot file to be saved



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.

Parameters:

  • keys (String)

    keystokes up to 255 in length



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_browserObject



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

#textString

Returns the text of the active screen

Returns:

  • (String)


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

Parameters:

  • seconds (Fixnum)

    the maximum number of seconds to wait



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

Parameters:

  • str (String)

    the string to wait for

  • row (Fixnum)

    the x coordinate of location

  • column (Fixnum)

    the y coordinate of 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.

Parameters:

  • row (Fixnum)

    the x coordinate of the location

  • column (Fixnum)

    the y coordinate of the 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