osaka 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +32 -8
- data/lib/osaka/calculator.rb +10 -9
- data/lib/osaka/keynote.rb +4 -4
- data/lib/osaka/location.rb +4 -0
- data/lib/osaka/numbers.rb +1 -1
- data/lib/osaka/osakaexpectations.rb +132 -0
- data/lib/osaka/pages.rb +13 -13
- data/lib/osaka/{applicationwrapper.rb → remotecontrol.rb} +68 -31
- data/lib/osaka/scriptrunner.rb +9 -1
- data/lib/osaka/textedit.rb +4 -4
- data/lib/osaka/typicalapplication.rb +49 -107
- data/lib/osaka/typicalprintdialog.rb +32 -0
- data/lib/osaka/typicalsavedialog.rb +33 -0
- data/lib/osaka/version.rb +1 -1
- data/lib/osaka.rb +4 -2
- data/spec/assets/mail_merge_data.numbers +0 -0
- data/spec/assets/mail_merge_template.pages +0 -0
- data/spec/calculator_spec.rb +10 -12
- data/spec/integration_keynote_spec.rb +1 -0
- data/spec/integration_pages_numbers_mail_merge_spec.rb +1 -1
- data/spec/keynote_flows_spec.rb +4 -4
- data/spec/keynote_spec.rb +4 -4
- data/spec/location_spec.rb +6 -0
- data/spec/mailmergeflow_spec.rb +2 -2
- data/spec/numbers_spec.rb +2 -3
- data/spec/osakaexpectations_spec.rb +26 -0
- data/spec/pages_spec.rb +8 -8
- data/spec/remotecontrol_spec.rb +411 -0
- data/spec/scriptrunner_spec.rb +12 -0
- data/spec/textedit_spec.rb +2 -2
- data/spec/typicalapplication_spec.rb +195 -221
- data/spec/typicalprintdialog_spec.rb +33 -0
- data/spec/typicalsavedialog_spec.rb +51 -0
- metadata +10 -5
- data/lib/osaka/applicationwrapperexpectations.rb +0 -91
- data/spec/applicationwrapper_spec.rb +0 -296
@@ -1,91 +0,0 @@
|
|
1
|
-
|
2
|
-
module Osaka
|
3
|
-
module ApplicationWrapperExpectations
|
4
|
-
|
5
|
-
def expect_clone
|
6
|
-
wrapper.should_receive(:clone)
|
7
|
-
end
|
8
|
-
|
9
|
-
def expect_activate
|
10
|
-
wrapper.should_receive(:activate)
|
11
|
-
end
|
12
|
-
|
13
|
-
def expect_focus
|
14
|
-
wrapper.should_receive(:focus)
|
15
|
-
end
|
16
|
-
|
17
|
-
def expect_set_current_window(name)
|
18
|
-
wrapper.should_receive(:set_current_window).with(name)
|
19
|
-
end
|
20
|
-
|
21
|
-
def expect_running?
|
22
|
-
wrapper.should_receive(:running?)
|
23
|
-
end
|
24
|
-
|
25
|
-
def expect_quit
|
26
|
-
wrapper.should_receive(:quit)
|
27
|
-
end
|
28
|
-
|
29
|
-
def expect_window_list
|
30
|
-
wrapper.should_receive(:window_list)
|
31
|
-
end
|
32
|
-
|
33
|
-
def expect_set(element, location, value)
|
34
|
-
wrapper.should_receive(:set).with(element, location, value)
|
35
|
-
end
|
36
|
-
|
37
|
-
def expect_keystroke(key, modifier = [])
|
38
|
-
wrapper.should_receive(:keystroke).with(key, modifier).and_return(wrapper) unless modifier.empty?
|
39
|
-
wrapper.should_receive(:keystroke).with(key).and_return(wrapper) if modifier.empty?
|
40
|
-
end
|
41
|
-
|
42
|
-
def expect_keystroke!(key, modifier = [])
|
43
|
-
wrapper.should_receive(:keystroke!).with(key, modifier).and_return(wrapper) unless modifier.empty?
|
44
|
-
wrapper.should_receive(:keystroke!).with(key).and_return(wrapper) if modifier.empty?
|
45
|
-
end
|
46
|
-
|
47
|
-
def expect_click!(location)
|
48
|
-
wrapper.should_receive(:click!).with(location).and_return(wrapper)
|
49
|
-
end
|
50
|
-
|
51
|
-
def expect_click(location)
|
52
|
-
wrapper.should_receive(:click).with(location).and_return(wrapper)
|
53
|
-
end
|
54
|
-
|
55
|
-
def expect_click_menu_bar(menu_item, menu_name)
|
56
|
-
wrapper.should_receive(:click_menu_bar).with(menu_item, menu_name).and_return(wrapper)
|
57
|
-
end
|
58
|
-
|
59
|
-
def expect_get!(element, location)
|
60
|
-
wrapper.should_receive(:get!).with(element, location)
|
61
|
-
end
|
62
|
-
|
63
|
-
def expect_tell(do_this)
|
64
|
-
wrapper.should_receive(:tell).with(do_this)
|
65
|
-
end
|
66
|
-
|
67
|
-
def expect_system_event(event)
|
68
|
-
wrapper.should_receive(:system_event).with(event)
|
69
|
-
end
|
70
|
-
|
71
|
-
def expect_exists(location)
|
72
|
-
wrapper.should_receive(:exists).with(location)
|
73
|
-
end
|
74
|
-
|
75
|
-
def expect_wait_until_exists(location)
|
76
|
-
wrapper.should_receive(:wait_until_exists).with(location)
|
77
|
-
end
|
78
|
-
|
79
|
-
def expect_wait_until_exists!(*location)
|
80
|
-
wrapper.should_receive(:wait_until_exists!).with(*location)
|
81
|
-
end
|
82
|
-
|
83
|
-
def expect_wait_until_not_exists(location)
|
84
|
-
wrapper.should_receive(:wait_until_not_exists).with(location)
|
85
|
-
end
|
86
|
-
|
87
|
-
def expect_until_not_exists!(element)
|
88
|
-
wrapper.should_receive(:until_not_exists!).with(element).and_yield
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,296 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'osaka'
|
3
|
-
|
4
|
-
describe "Osaka::ApplicationWrapper" do
|
5
|
-
|
6
|
-
name = "ApplicationName"
|
7
|
-
quoted_name = "\"#{name}\""
|
8
|
-
subject { Osaka::ApplicationWrapper.new(name) }
|
9
|
-
|
10
|
-
before (:each) do
|
11
|
-
Osaka::ScriptRunner.enable_debug_prints
|
12
|
-
end
|
13
|
-
|
14
|
-
after (:each) do
|
15
|
-
Osaka::ScriptRunner.disable_debug_prints
|
16
|
-
end
|
17
|
-
|
18
|
-
it "Should be able to clone wrappers" do
|
19
|
-
subject.set_current_window "Window"
|
20
|
-
new_wrapper = subject.clone
|
21
|
-
new_wrapper.should == subject
|
22
|
-
new_wrapper.should_not equal(subject)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "Should be able to compare objects using names" do
|
26
|
-
subject.should == Osaka::ApplicationWrapper.new(name)
|
27
|
-
subject.should_not == Osaka::ApplicationWrapper.new("otherName")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "Should be able to compare objects using window" do
|
31
|
-
equal_object = Osaka::ApplicationWrapper.new(name)
|
32
|
-
unequal_object = Osaka::ApplicationWrapper.new(name)
|
33
|
-
equal_object.set_current_window("Window")
|
34
|
-
subject.set_current_window("Window")
|
35
|
-
unequal_object.set_current_window "Another Window"
|
36
|
-
|
37
|
-
subject.should == equal_object
|
38
|
-
subject.should_not == unequal_object
|
39
|
-
end
|
40
|
-
|
41
|
-
def check_for_warning(action)
|
42
|
-
Osaka::ScriptRunner.should_receive(:execute).and_return("Blah")
|
43
|
-
subject.should_receive(:print_warning).with(action, "Blah")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "Should be able to tell applications to do something" do
|
47
|
-
Osaka::ScriptRunner.should_receive(:execute).with("tell application #{quoted_name}; command; end tell")
|
48
|
-
subject.tell("command")
|
49
|
-
end
|
50
|
-
|
51
|
-
it "Can also pass multi-line commands to telling an application what to do" do
|
52
|
-
Osaka::ScriptRunner.should_receive(:execute).with("tell application #{quoted_name}; activate; quit; end tell")
|
53
|
-
subject.tell("activate; quit")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "Should be able to print warning messages" do
|
57
|
-
subject.should_receive(:puts).with("Osaka WARNING while doing action: Message")
|
58
|
-
subject.print_warning("action", "Message")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "Should print an Warning message with the ScriptRunner returns text when doing activate" do
|
62
|
-
check_for_warning("activate")
|
63
|
-
subject.activate
|
64
|
-
end
|
65
|
-
|
66
|
-
it "Has a short-cut method for quitting" do
|
67
|
-
subject.should_receive(:keystroke).with("q", :command)
|
68
|
-
subject.quit
|
69
|
-
end
|
70
|
-
|
71
|
-
it "Should be able to generate events via the Systems Events" do
|
72
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/tell application "System Events"; tell process #{quoted_name}; quit; end tell; end tell/)
|
73
|
-
subject.system_event!("quit")
|
74
|
-
end
|
75
|
-
|
76
|
-
it "Should be possible to check whether an application is still running" do
|
77
|
-
Osaka::ScriptRunner.should_receive(:execute).with("tell application \"System Events\"; (name of processes) contains \"#{name}\"; end tell").and_return("false")
|
78
|
-
subject.running?.should == false
|
79
|
-
end
|
80
|
-
|
81
|
-
it "Should be able to generate events via the Systems Events and activate the application first" do
|
82
|
-
subject.should_receive(:activate)
|
83
|
-
subject.should_receive(:system_event!).with("quit")
|
84
|
-
subject.system_event("quit")
|
85
|
-
end
|
86
|
-
|
87
|
-
it "Should be able to check whether a location exists" do
|
88
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/exists button 1/).and_return("true\n")
|
89
|
-
subject.exists(at.button(1)).should == true
|
90
|
-
end
|
91
|
-
|
92
|
-
it "Should be able to check whether a location does not exists" do
|
93
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/not exists window 1/).and_return("true\n")
|
94
|
-
subject.not_exists(at.window(1)).should == true
|
95
|
-
end
|
96
|
-
|
97
|
-
it "Should be able to wait until multiple locations exists and return the one that happened" do
|
98
|
-
subject.should_receive(:exists).with(at.button(1)).and_return(false, false, false)
|
99
|
-
subject.should_receive(:exists).with(at.sheet(5)).and_return(false, false, true)
|
100
|
-
subject.wait_until_exists!(at.button(1), at.sheet(5)).should == at.sheet(5)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "Should be able to wait until exists and activate the application first" do
|
104
|
-
subject.should_receive(:activate)
|
105
|
-
subject.should_receive(:wait_until_exists!).with([at.window(1)])
|
106
|
-
subject.wait_until_exists(at.window(1))
|
107
|
-
end
|
108
|
-
|
109
|
-
it "Should be able to wait for a specific element and activate" do
|
110
|
-
subject.should_receive(:activate)
|
111
|
-
subject.should_receive(:wait_until_not_exists!).with(at.window(1), nil)
|
112
|
-
subject.wait_until_not_exists(at.window(1))
|
113
|
-
end
|
114
|
-
|
115
|
-
it "Should be able to wait for a specific element to not exist anymore" do
|
116
|
-
subject.should_receive(:not_exists).with(at.window(1)).and_return(false, false, true)
|
117
|
-
subject.wait_until_not_exists!(at.window(1))
|
118
|
-
end
|
119
|
-
|
120
|
-
it "Should be able to generate keystroke events" do
|
121
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
|
122
|
-
subject.keystroke!("p")
|
123
|
-
end
|
124
|
-
|
125
|
-
it "Should be able to generate return keystroke event" do
|
126
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/keystroke return/).and_return("")
|
127
|
-
subject.keystroke!(:return)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "Prints a warning when keystroke results in some outputShould be able to generate keystroke events" do
|
131
|
-
check_for_warning("keystroke")
|
132
|
-
subject.keystroke!("p")
|
133
|
-
end
|
134
|
-
|
135
|
-
it "Should be able to keystroke and activate" do
|
136
|
-
subject.should_receive(:activate)
|
137
|
-
subject.should_receive(:focus)
|
138
|
-
subject.should_receive(:keystroke!).with("a", [])
|
139
|
-
subject.keystroke("a", [])
|
140
|
-
end
|
141
|
-
|
142
|
-
it "Should be able to do keystrokes with command down" do
|
143
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p" using {command down}/).and_return("")
|
144
|
-
subject.keystroke!("p", :command)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "Should be able to do keystrokes with option and command down" do
|
148
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p" using {option down, command down}/).and_return("")
|
149
|
-
subject.keystroke!("p", [ :option, :command ])
|
150
|
-
end
|
151
|
-
|
152
|
-
it "Should be able to do a keystroke and wait until something happen in one easy line" do
|
153
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
|
154
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
|
155
|
-
subject.keystroke!("p", []).wait_until_exists!(at.window(1))
|
156
|
-
end
|
157
|
-
|
158
|
-
it "Should be able to keystroke_and_wait_until_exists and activate" do
|
159
|
-
subject.should_receive(:activate)
|
160
|
-
subject.should_receive(:focus)
|
161
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
|
162
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
|
163
|
-
subject.keystroke("p", []).wait_until_exists!(at.window(1))
|
164
|
-
end
|
165
|
-
|
166
|
-
it "Should be able to do clicks" do
|
167
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/click menu button "PDF"/).and_return("")
|
168
|
-
subject.click!(at.menu_button("PDF"))
|
169
|
-
end
|
170
|
-
|
171
|
-
it "Should be able to do click and activate" do
|
172
|
-
subject.should_receive(:activate)
|
173
|
-
subject.should_receive(:click!).with("button")
|
174
|
-
subject.click("button")
|
175
|
-
end
|
176
|
-
|
177
|
-
it "Should be able to do clicks and wait until something happened in one easy line" do
|
178
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/click/).and_return("")
|
179
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
|
180
|
-
subject.click!("button").wait_until_exists!(at.window(1))
|
181
|
-
end
|
182
|
-
|
183
|
-
it "Should be able to click_and_wait_until_exists and activate" do
|
184
|
-
subject.should_receive(:activate)
|
185
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/click/).and_return("")
|
186
|
-
Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
|
187
|
-
subject.click("button").wait_until_exists!(at.window(1))
|
188
|
-
end
|
189
|
-
|
190
|
-
it "Should be able to click on menu bar items" do
|
191
|
-
subject.should_receive("activate")
|
192
|
-
subject.should_receive("click!").with(at.menu_item("Hey").menu(1).menu_bar_item("File").menu_bar(1))
|
193
|
-
subject.click_menu_bar(at.menu_item("Hey"), "File")
|
194
|
-
end
|
195
|
-
|
196
|
-
it "Should be able to set a value to an element" do
|
197
|
-
subject.should_receive(:system_event!).with(/set value of window 1 to "newvalue"/).and_return("")
|
198
|
-
subject.set!("value", at.window(1), "newvalue")
|
199
|
-
end
|
200
|
-
|
201
|
-
it "Prints a warning when setting and element and output is received" do
|
202
|
-
check_for_warning("set")
|
203
|
-
subject.set!("value", at.window(1), "newvalue")
|
204
|
-
end
|
205
|
-
|
206
|
-
it "Should be able to set to boolean values" do
|
207
|
-
subject.should_receive(:system_event!).with(/set value of window 1 to true/).and_return("")
|
208
|
-
subject.set!("value", at.window(1), true)
|
209
|
-
end
|
210
|
-
|
211
|
-
it "Should be able to get a value from an element" do
|
212
|
-
subject.should_receive(:system_event!).with(/get value of window 1/).and_return("1\n")
|
213
|
-
subject.get!("value", at.window(1)).should == "1"
|
214
|
-
end
|
215
|
-
|
216
|
-
it "Should use the locally stored window when that one is set." do
|
217
|
-
subject.set_current_window("1")
|
218
|
-
subject.should_receive(:system_event!).with(/get value of window \"1\"/).and_return("1\n")
|
219
|
-
subject.get!("value").should == "1"
|
220
|
-
end
|
221
|
-
|
222
|
-
it "Should combine the location and the window" do
|
223
|
-
subject.set_current_window("1")
|
224
|
-
subject.should_receive(:system_event!).with(/get value of dialog 2 of window "1"/).and_return("1\n")
|
225
|
-
subject.get!("value", at.dialog(2)).should == "1"
|
226
|
-
end
|
227
|
-
|
228
|
-
it "Should be able to get values from the application itself" do
|
229
|
-
subject.should_receive(:system_event!).with("get value").and_return("1\n")
|
230
|
-
subject.get_app!("value").should == "1"
|
231
|
-
end
|
232
|
-
|
233
|
-
it "Should be able to set a value and activate" do
|
234
|
-
subject.should_receive(:activate)
|
235
|
-
subject.should_receive(:set!).with("value", at.window(1), "newvalue")
|
236
|
-
subject.set("value", at.window(1), "newvalue")
|
237
|
-
end
|
238
|
-
|
239
|
-
it "Should be able to loop over some script until something happens" do
|
240
|
-
Osaka::ScriptRunner.should_receive(:execute).and_return("false", "false", "true")
|
241
|
-
subject.should_receive(:activate).twice
|
242
|
-
subject.until_exists!(at.window(1)) {
|
243
|
-
subject.activate
|
244
|
-
}
|
245
|
-
end
|
246
|
-
|
247
|
-
it "Should be able to get an empty array when requesting for the window list and there are none" do
|
248
|
-
subject.should_receive(:get_app!).with("windows").and_return("\n")
|
249
|
-
subject.window_list.should == []
|
250
|
-
end
|
251
|
-
|
252
|
-
it "Should be able get an array with one window name when there is exactly one window" do
|
253
|
-
subject.should_receive(:get_app!).with("windows").and_return("window one of application process process\n")
|
254
|
-
subject.window_list.should == ["one"]
|
255
|
-
end
|
256
|
-
|
257
|
-
it "Should be able to get an array of multiple window names" do
|
258
|
-
subject.should_receive(:get_app!).with("windows").and_return("window one of application process process, window two of application process process\n")
|
259
|
-
subject.window_list.should == ["one", "two"]
|
260
|
-
end
|
261
|
-
|
262
|
-
it "Should initialize the current window when it is not focused yet" do
|
263
|
-
subject.should_receive(:window_list).and_return(["1"])
|
264
|
-
subject.focus
|
265
|
-
subject.current_window_name.should == "1"
|
266
|
-
end
|
267
|
-
|
268
|
-
it "Shouldn't initialize current window when it is already set" do
|
269
|
-
subject.should_receive(:window_list).and_return(["1"])
|
270
|
-
subject.focus
|
271
|
-
|
272
|
-
subject.should_receive(:window_list).and_return(["2", "1"])
|
273
|
-
subject.should_receive(:set!)
|
274
|
-
subject.focus
|
275
|
-
subject.current_window_name.should == "1"
|
276
|
-
end
|
277
|
-
|
278
|
-
it "Should re-initialize the current window when it doesn't exist anymore" do
|
279
|
-
subject.should_receive(:window_list).and_return(["1"])
|
280
|
-
subject.focus
|
281
|
-
|
282
|
-
subject.should_receive(:window_list).and_return(["2"])
|
283
|
-
subject.focus
|
284
|
-
subject.current_window_name.should == "2"
|
285
|
-
end
|
286
|
-
|
287
|
-
it "Should focus the current window when it doesn't have focus" do
|
288
|
-
subject.should_receive(:window_list).and_return(["1"])
|
289
|
-
subject.focus
|
290
|
-
|
291
|
-
subject.should_receive(:window_list).and_return(["2", "1"])
|
292
|
-
subject.should_receive(:set!).with("value", "attribute \"AXMain\"", true )
|
293
|
-
subject.focus
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|