Module: RFormSpec::Driver
Instance Method Summary
collapse
-
#close_window(title) ⇒ Object
-
#driver ⇒ Object
-
#focus_window(title, text = nil) ⇒ Object
-
#key_press(keys) ⇒ Object
(also: #press_key)
wrapper of keyboard operations.
-
#mouse_click(x, y) ⇒ Object
-
#mouse_move(x, y) ⇒ Object
Wrapper of mouse operation.
-
#open_file_dialog(title, filepath, text = "") ⇒ Object
standard open file dialog.
-
#try_for(timeout = 30, polling_interval = 1, &block) ⇒ Object
helper Try the operation up to specified timeout (in seconds), and sleep given interval (in seconds).
-
#wait_and_focus_window(title, text = "", timeout = 5) ⇒ Object
-
#wait_for_window(win, timeout = 30) ⇒ Object
-
#window_exists?(title) ⇒ Boolean
#connect_to_testwise, #debug, #dump_caller_stack, #notify_screenshot_location, #operation_delay
Instance Method Details
#close_window(title) ⇒ Object
46
47
48
|
# File 'lib/rformspec/driver.rb', line 46
def close_window(title)
driver.WinClose(title)
end
|
#driver ⇒ Object
10
11
12
13
14
|
# File 'lib/rformspec/driver.rb', line 10
def driver
dump_caller_stack
return $a3 if $a3
return RFormSpec::AutoIt.init
end
|
#focus_window(title, text = nil) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/rformspec/driver.rb', line 38
def focus_window(title, text = nil)
if text
driver.WinActivate(title, text)
else
driver.WinActivate(title)
end
end
|
#key_press(keys) ⇒ Object
Also known as:
press_key
wrapper of keyboard operations
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/rformspec/driver.rb', line 51
def key_press(keys)
dump_caller_stack
if keys =~ /^Ctrl\+([A-Z])$/
filtered_keys = "^+#{$1}"
elsif keys =~ /^Ctrl\+Shift\+([A-Z])$/
filtered_keys = "^+#{$1.downcase}"
elsif keys =~ /^Alt+([A-Z])$/
filtered_keys = "!+#{$1}"
elsif keys =~ /^Alt\+Shift\+([a-z])$/
filtered_keys = "!+#{$1.downcase}"
else
filtered_keys = keys
end
filtered_keys = keys.gsub("Alt+", "!+").gsub("Ctrl+", "^+")
RFormSpec::Keyboard.press(filtered_keys)
sleep 0.5
end
|
#mouse_click(x, y) ⇒ Object
76
77
78
|
# File 'lib/rformspec/driver.rb', line 76
def mouse_click(x, y)
RFormSpec::Mouse.click(x, y)
end
|
#mouse_move(x, y) ⇒ Object
Wrapper of mouse operation
72
73
74
|
# File 'lib/rformspec/driver.rb', line 72
def mouse_move(x, y)
RFormSpec::Mouse.move_to(x, y)
end
|
#open_file_dialog(title, filepath, text = "") ⇒ Object
standard open file dialog
81
82
83
84
85
86
87
|
# File 'lib/rformspec/driver.rb', line 81
def open_file_dialog(title, filepath, text="")
wait_and_focus_window(title)
dialog = RFormSpec::OpenFileDialog.new(title, text)
dialog.enter_filepath(filepath)
sleep 1
dialog.click_open
end
|
#try_for(timeout = 30, polling_interval = 1, &block) ⇒ Object
helper Try the operation up to specified timeout (in seconds), and sleep given interval (in seconds). Error will be ignored until timeout Example
try_for { click_link('waiting')}
try_for (10, 2) { click_button('Search' } # try to click the 'Search' button upto 10 seconds, try every 2 seconds
try_for { click_button('Search' }
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/rformspec/driver.rb', line 100
def try_for(timeout = 30, polling_interval = 1, &block)
start_time = Time.now
last_error = nil
until (duration = Time.now - start_time) > timeout
begin
yield
last_error = nil
return true
rescue => e
last_error = e
end
sleep polling_interval
end
raise "Timeout after #{duration.to_i} seconds with error: #{last_error}." if last_error
raise "Timeout after #{duration.to_i} seconds."
end
|
#wait_and_focus_window(title, text = "", timeout = 5) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rformspec/driver.rb', line 20
def wait_and_focus_window(title, text="", timeout=5)
try_for(timeout) {
found_window = driver.WinExists(title, text)
raise "Window '#{title}' not found" unless found_window.to_i == 1
}
driver.WinActivate(title, text)
sleep 0.5
if driver.WinActive(title, text).to_i != 1
raise "Failed to make window '#{title}' active"
end
end
|
#wait_for_window(win, timeout = 30) ⇒ Object
16
17
18
|
# File 'lib/rformspec/driver.rb', line 16
def wait_for_window(win, timeout=30)
driver.WinWait(win.title, win.text, timeout * 1000)
end
|
#window_exists?(title) ⇒ Boolean
34
35
36
|
# File 'lib/rformspec/driver.rb', line 34
def window_exists?(title)
driver.WinExists(title) > 0
end
|