-
Notifications
You must be signed in to change notification settings - Fork 33
/
spec_helper.rb
128 lines (119 loc) · 5.96 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rautomation'
require 'rspec'
require 'timeout'
module SpecHelper
# @private
def adapter
adapter = ENV["RAUTOMATION_ADAPTER"] && ENV["RAUTOMATION_ADAPTER"].to_sym || RAutomation::Adapter::Helper.default_adapter
if RAutomation::Adapter::Helper.supported_for_current_platform?(adapter)
adapter
else
:unsupported_platform
end
end
def navigate_to_simple_elements
main_window = RAutomation::Window.new(title: "MainFormWindow")
main_window.button(value: "Simple Elements").click { RAutomation::Window.new(title: "SimpleElementsForm").present? }
end
module_function :adapter, :navigate_to_simple_elements
# Since adapters are different then the windows to be tested
# might be different also.
#
# This constant allows to create input data for specs which could differ between the adapters.
#
# There has to be 2 windows:
# 1) Some random window, which is maximizable, minimizable, close'able and etc.
# 2) Browser window, which opens up a test.html where JavaScript prompt with a Button and a TextField objects will be shown.
DATA = {
# This adapter needs Windows OS with Internet Explorer installed into 'c:\program files\internet explorer'.
autoit: {
# Path to some binary, which opens up a window, what can be
# minimized, maximized, activated, closed and etc.
window1: "ext\\WindowsForms\\Release\\WindowsForms.exe",
window2: "notepad",
window2_title: /notepad/i,
# Window 1 title, has to be a Regexp.
window1_title: /FormWindow/i,
window1_full_title: 'MainFormWindow',
# Window 1 should have this text on it.
window1_text: "This is a sample text",
# When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
# "A" key
window1_send_keys: "A",
proc_after_send_keys: lambda do
about_box = RAutomation::Window.new(title: /About/i)
RAutomation::WaitHelper.wait_until {about_box.present?}
end,
# Window 1 should have a button with the following text.
window1_button_text: "&About",
# Window 1 should have a text field with the specified class name.
window1_text_field_class: "Edit",
# Adapter internal method invocation for getting title of window2
title_proc: lambda {|win| win.WinGetTitle("[TITLE:MainFormWindow]")}
},
win_32: {
# Path to some binary, which opens up a window, what can be
# minimized, maximized, activated, closed and etc.
window1: "ext\\WindowsForms\\Release\\WindowsForms.exe",
window2: "notepad",
window2_title: /notepad/i,
# Window 1 title, has to be a Regexp.
window1_title: /FormWindow/i,
window1_full_title: 'MainFormWindow',
# Window 1 should have this text on it.
window1_text: "This is a sample text",
# When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
# "A" key
window1_send_keys: "A",
proc_after_send_keys: lambda do
about_box = RAutomation::Window.new(title: /About/i)
RAutomation::WaitHelper.wait_until {about_box.present?}
end,
# Window 1 should have a button with the following text.
window1_button_text: "&About",
# Window 1 should have a text field with the specified class name.
window1_text_field_class: "Edit",
# Adapter internal method invocation for getting title of window2
title_proc: lambda {|win| win.window_title(win.hwnd)}
},
#Just copying :win_ffi data for now
ms_uia: {
# Path to some binary, which opens up a window, what can be
# minimized, maximized, activated, closed and etc.
window1: "ext\\WindowsForms\\Release\\WindowsForms.exe",
window2: "notepad",
window2_title: /notepad/i,
# Window 1 title, has to be a Regexp.
window1_title: /FormWindow/i,
window1_full_title: 'MainFormWindow',
# Window 1 should have this text on it.
window1_text: "This is a sample text",
# When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
# "A" key
window1_send_keys: "A",
proc_after_send_keys: lambda do
about_box = RAutomation::Window.new(title: /About/i)
RAutomation::WaitHelper.wait_until {about_box.present?}
end,
# Window 1 should have a button with the following text.
window1_button_text: "&About",
# Window 1 should have a text field with the specified class name.
window1_text_field_class: "Edit",
# Adapter internal method invocation for getting title of window2
title_proc: lambda {|win| win.window_title(win.hwnd)}
}
}[adapter]
end
RSpec.configure do |config|
config.before(:each) do |example|
RAutomation::Window.wait_timeout = 15
unless example.metadata[:pure_unit]
@pid1 = IO.popen(SpecHelper::DATA[:window1]).pid
RAutomation::WaitHelper.wait_until { RAutomation::Window.new(pid: @pid1).present? }
end
end
config.after(:each) do
Process.kill(9, @pid1) rescue nil
end
end