Class: RokuController
- Defined in:
- lib/platform_libs/roku/roku_controller.rb
Constant Summary collapse
- @@keyport =
8060
- @@keyDelayInMs =
0.600
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#clear_string(count) ⇒ Object
Public: intended to clear the login screen.
- #get_boolean?(element_name, timeout) ⇒ Boolean
-
#get_text(element_name) ⇒ Object
Deprecated: fetch the json associated with the element_name - does not provide error processing.
-
#get_text_t(element_name, timeout) ⇒ Object
Public: fetches the json text associated with the element_name - only waits until timeout.
-
#get_visit_id ⇒ Object
Public: retrieves the visit id used to fetch analytics records from Venona.
- #initComm(host, port) ⇒ Object
-
#initialize(args = {}) ⇒ RokuController
constructor
A new instance of RokuController.
-
#is_true(element_name) ⇒ Object
Public: checks to see if an element exists and if the value is true - returns immediately.
-
#is_visible(element_name) ⇒ Object
Public: checks to see if an element exists - returns immediately.
-
#launch_app(app_keyword, app_version, app_Id) ⇒ Object
Public: launch application - Id, version and appkeyword details needed for app launch.
-
#send_key(key) ⇒ Object
Public: send a key directly to the OS - different from send_native_key because the entire keyboard is not supported.
-
#send_native_key(value) ⇒ Object
Public: send a key directly to the OS - this can be used instead of navigating the on screen keyboard.
-
#type_string(word) ⇒ Object
Public: intended to type characters on the on screen keyboard.
-
#wait_for_element_visible(element_name, timeout) ⇒ Object
Public: waits for an element to be displayed - a valid http transaction occurs with no data, here we wait for data requested.
Constructor Details
#initialize(args = {}) ⇒ RokuController
Returns a new instance of RokuController.
10 11 12 13 14 15 16 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 10 def initialize(args={}) # PLEASE DO NOT MODIFY BELOW LINE. @host = args.fetch(:host, nil) @port = args.fetch(:port, 8888) @basepath = '/twctvweb/status/activewindow/' @dut = args[:dut] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 5 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 5 def port @port end |
Instance Method Details
#clear_string(count) ⇒ Object
Public: intended to clear the login screen
count - number of times to hit the backspace key
43 44 45 46 47 48 49 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 43 def clear_string(count) i = 0 while (i < count) send_native_key("Backspace") i = i + 1 end end |
#get_boolean?(element_name, timeout) ⇒ Boolean
144 145 146 147 148 149 150 151 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 144 def get_boolean?(element_name, timeout) s = get_text_t(element_name, timeout) @r = false if (s == "true") @r = true end return @r end |
#get_text(element_name) ⇒ Object
Deprecated: fetch the json associated with the element_name
- does not provide error processing
element_name - the name of the element to be retrieved
104 105 106 107 108 109 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 104 def get_text(element_name) puts "\ngetText " + element_name uri = URI(element_name) s = Net::HTTP.get(uri) return s end |
#get_text_t(element_name, timeout) ⇒ Object
Public: fetches the json text associated with the element_name
- only waits until timeout
element_name - the name of the element to be retrieved timeout - the amount of time to wait in secs
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 117 def get_text_t(element_name, timeout) path = @basepath + element_name puts "\nget_text_t" + path + ", timeout = " + timeout.to_s http = Net::HTTP.new( @host, @port) http.open_timeout = 2 http.read_timeout = timeout s = nil begin http.start begin http.request_get( path) do |res| s = res.read_body end rescue Timeout::ERROR puts "Timeout reading " end rescue Timeout::Error puts "Timeout connecting " rescue puts "Other network error" end return s end |
#get_visit_id ⇒ Object
Public: retrieves the visit id used to fetch analytics records from Venona
241 242 243 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 241 def get_visit_id return get_text_t("venona/visitid", 5) end |
#initComm(host, port) ⇒ Object
18 19 20 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 18 def initComm(host, port) initialize(:host => host, :port => port) end |
#is_true(element_name) ⇒ Object
Public: checks to see if an element exists and if the value is true
- returns immediately
element_name - the name of the element to be retrieved
224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 224 def is_true(element_name) s = get_text_t(element_name,0.3) if (s == nil or s == "{}") return false else puts "evaluating " + s if s == "true" return true else return false end end end |
#is_visible(element_name) ⇒ Object
Public: checks to see if an element exists
- returns immediately
element_name - the name of the element to be retrieved
185 186 187 188 189 190 191 192 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 185 def is_visible(element_name) s = get_text_t(element_name,0.3) if (s == nil || s == "{}") return false else return true end end |
#launch_app(app_keyword, app_version, app_Id) ⇒ Object
Public: launch application
- Id, version and appkeyword details needed for app launch
version - application version to launch Id - target application Id it from ./query/apps appkeyword - application search keyword Example : app_version=‘4.2.1’, app_Id=‘dev’, app_keyword=‘Spectrum’
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 201 def launch_app(app_keyword, app_version, app_Id) http = Net::HTTP.new(@host, @@keyport) http.open_timeout = 2 begin unless app_version == "" and app_Id == "" and app_keyword =="" launch_tag = "/launch/" + app_Id + "?"+ "version=" + app_version + "&keyword=" + app_keyword puts "Launching " + launch_tag http.request_post(launch_tag, "") sleep(1.0) else puts "Invalid App launch request... " end sleep(@@keyDelayInMs) rescue Timeout::Error puts "Timeout launching app " + app_keyword end end |
#send_key(key) ⇒ Object
Public: send a key directly to the OS
- different from send_native_key because the entire keyboard is not supported
key - the remote control key to be sent
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 75 def send_key(key) http = Net::HTTP.new(@host, @@keyport) http.open_timeout = 2 begin case key when "Back", "Select", "Up", "Down", "Left", "Right" pkey = "/keypress/" + key puts "Sending " + pkey http.request_post(pkey, "") else pkey = "/keydown/" + key puts "Sending " + pkey http.request_post(pkey, "") sleep(0.1) pkey = "/keyup/" + key http.request_post(pkey, "") end sleep(@@keyDelayInMs) rescue Timeout::Error puts "Timeout sending " + key end end |
#send_native_key(value) ⇒ Object
Public: send a key directly to the OS
-
this can be used instead of navigating the on screen keyboard.
-
different from send_key because the entire keyboard is supported
-
value - the number or letter to be sent
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 57 def send_native_key(value) http = Net::HTTP.new(@host, @@keyport) http.open_timeout = 2 p_key = "/keypress/" + value begin puts "sending " + p_key http.request_post(p_key, "") sleep(@@keyDelayInMs) rescue Timeout::Error puts "Timeout sending " + p_key end end |
#type_string(word) ⇒ Object
Public: intended to type characters on the on screen keyboard
word - the string to be typed (username or password)
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 27 def type_string(word) word.each_char do |c| value = "Lit_" + c send_native_key(value) end i = 0 while (i < 4) send_key("Down") i = i + 1 end send_key("Select") end |
#wait_for_element_visible(element_name, timeout) ⇒ Object
Public: waits for an element to be displayed
- a valid http transaction occurs with no data, here we wait for data requested
element_name - the name of the element to be retrieved timeout - the amount of time to wait in secs
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/platform_libs/roku/roku_controller.rb', line 160 def wait_for_element_visible(element_name, timeout) untilTime = Time.now.to_i + timeout while (true) do json = get_text_t(element_name, 1) puts json if json == nil return nil end if json != "{}" return json end now = Time.now.to_i if now > untilTime return nil end sleep(1) end end |