Class: WindowsTestApp

Inherits:
Object
  • Object
show all
Includes:
Waiter
Defined in:
lib/rutl/appium/windows_test_app_wrapper.rb

Overview

wrapper for simple test apps

Constant Summary

Constants included from Waiter

Waiter::DEFAULT_TIMEOUT, Waiter::POLL_SLEEP_TIME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Waiter

#await

Constructor Details

#initialize(name:, title:) ⇒ WindowsTestApp

Returns a new instance of WindowsTestApp.



10
11
12
13
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 10

def initialize(name:, title:)
  @name = name
  @title = title
end

Instance Attribute Details

#window_handle_stringObject (readonly)

Returns the value of attribute window_handle_string.



8
9
10
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 8

def window_handle_string
  @window_handle_string
end

Instance Method Details

#find_window_by_titleObject



15
16
17
18
19
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 15

def find_window_by_title
  result = Win32::Window.find(title: @title)
  raise 'found more than one instance of app' if result.size > 1
  result.empty? ? false : result.first
end

#quiet_cmd(in_string) ⇒ Object



37
38
39
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 37

def quiet_cmd(in_string)
  system in_string + ' 1>nul 2>&1'
end

#startObject



27
28
29
30
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 27

def start
  quiet_cmd "start \"NO TITLE\" #{@name}"
  wait_for_started
end

#stopObject Also known as: kill



32
33
34
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 32

def stop
  quiet_cmd "taskkill /f /pid #{@pid} /t"
end

#wait_for_startedObject



21
22
23
24
25
# File 'lib/rutl/appium/windows_test_app_wrapper.rb', line 21

def wait_for_started
  app_window = await -> { find_window_by_title }
  @pid = app_window.pid
  @window_handle_string = format('0x%08x', app_window.handle)
end