2
3
This is the "gnome" module.
4
5
The gnome module provides wrappers for LDTP to make the write of Gnome tests easier.
8
9
from .main import Application
10
from ..gconfwrapper import GConf
13
class Calculator(Application):
15
The Calculator class contains methods for exercising the gcalctool application
17
LAUNCHER = "gcalctool"
18
WINDOW = "frmCalculator"
19
WINDOW_ADVANCED = "frmCalculator—Advanced"
20
WINDOW_FINANCIAL = "frmCalculator—Financial"
21
WINDOW_SCIENTIFIC = "frmCalculator—Scientific"
22
WINDOW_PROGRAMMING = "frmCalculator—Programming"
23
MNU_BASIC = "mnuBasic"
24
MNU_ADVANCED = "mnuAdvanced"
25
MNU_FINANCIAL = "mnuFinancial"
26
MNU_SCIENTIFIC = "mnuScientific"
27
MNU_PROGRAMMING = "mnuProgramming"
28
VIEWS = {"BASIC" : {"WINDOW" : WINDOW,
30
"ADVANCED" : {"WINDOW" : WINDOW_ADVANCED,
31
"MENU" : MNU_ADVANCED},
32
"FINANCIAL" : {"WINDOW" : WINDOW_FINANCIAL,
33
"MENU" : MNU_FINANCIAL},
34
"SCIENTIFIC" : {"WINDOW" : WINDOW_SCIENTIFIC,
35
"MENU" : MNU_SCIENTIFIC},
36
"PROGRAMMING" : {"WINDOW" : WINDOW_PROGRAMMING,
37
"MENU" : MNU_PROGRAMMING}}
56
EDITBAR_ROLE = "edit bar"
59
GCONF_MODE_KEY = "/apps/gcalctool/button_layout"
60
GCONF_MODE_VAL = "BASIC"
63
Application.__init__(self)
70
GConf.set_item(self.GCONF_MODE_KEY, self.GCONF_MODE_VAL)
71
except GConf.GConfError:
72
raise ldtp.LdtpExecutionError, "Could not set default view in gconf"
73
Application.open(self)
75
def showing(self, button):
77
Test whether the specified button is showing
79
@param button: Specify the button to test
81
@return: Value indicating whether the button is showing in the view
85
>>> c.open() # Calculator opens in BASIC view
86
>>> c.showing("Reciprocal")
88
>>> c.set_view("ADVANCED")
89
>>> c.showing("Reciprocal")
92
calculator = ooldtp.context(self.name)
94
children = calculator.getchild(button,'push button')
95
for child in children:
96
childName=child.getName()
97
if calculator.hasstate(childName, ldtp.state.SHOWING):
99
except ldtp.LdtpExecutionError:
100
raise ldtp.LdtpExecutionError, "Error locating button %s" % button
103
def push(self, buttons):
105
Push the specified buttons in the calculator window.
111
@param buttons: Specify the buttons to push.
112
@type buttons: string
114
calculator = ooldtp.context(self.name)
115
for button in buttons:
117
# The calculator has some buttons with the same names that are
118
# hidden depending on the view.
119
children = calculator.getchild(self.BUTTONS[button],'push button')
120
for child in children:
121
childName=child.getName()
122
if calculator.hasstate(childName, ldtp.state.SHOWING):
123
calculator.click(childName)
126
raise LookupError, "Could not find button %s in current view" % button
127
except ldtp.LdtpExecutionError:
128
raise ldtp.LdtpExecutionError, "Error clicking button %s" % button
132
Get the current view of the calculator.
139
@return: The current view: BASIC, ADVANCED, FINANCIAL, SCIENTIFIC,
143
windowname = self.name
144
for view in self.VIEWS:
145
if self.VIEWS[view]['WINDOW'] == windowname:
147
raise LookupError, "Could not identify the current calculator view"
149
def set_view(self, new_view):
151
Change to the specified view in the calculator
155
>>> c.set_view('ADVANCED')
157
@param new_view: Specify the new view. Valid values are:
158
BASIC, ADVANCED, FINANCIAL, SCIENTIFIC, PROGRAMMING
159
@type new_view: string
161
new_window_name = self.VIEWS[new_view]["WINDOW"]
162
new_view_menu_name = self.VIEWS[new_view]["MENU"]
163
calculator = ooldtp.context(self.name)
165
mnu_new_view = calculator.getchild(new_view_menu_name)
166
except ldtp.LdtpExecutionError:
167
raise ldtp.LdtpExecutionError, "The menu item for the requested view was not found."
170
mnu_new_view.selectmenuitem()
171
except ldtp.LdtpExecutionError:
172
raise ldtp.LdtpExecutionError, "There was a problem changing views."
173
self.set_name(new_window_name)
174
time.sleep(self.SLEEP_DELAY) # need to give mago some time to catch up to calc ui
178
Read the value from the calculator screen
186
@return: The contents of the calculator's screen
189
calculator = ooldtp.context(self.name)
191
editBar = calculator.getchild(role=self.EDITBAR_ROLE)
192
value = editBar[0].gettextvalue()
193
except ldtp.LdtpExecutionError:
194
raise ldtp.LdtpExecutionError, "There was a problem reading the value."
197
class GnomeScreenshot(Application):
199
GnomeScreenshot manages the gnome-screenshot application in interactive
202
LAUNCHER = 'gnome-screenshot'
203
LAUNCHER_ARGS = ['--interactive']
204
CLOSE_TYPE = 'button'
205
CLOSE_NAME = 'btnCancel'
207
WINDOW = 'dlgTakeScreenshot'
209
GRAB_AFTER_DELAY_FIELD = 'sbtnGrabafteradelayof'
210
GRAB_THE_WHOLE_DESKTOP_RADIO = 'rbtnGrabthewholedesktop'
211
GRAB_THE_CURRENT_WINDOW_RADIO = 'rbtnGrabthecurrentwindow'
212
GRAB_A_SELECTED_AREA = 'rbtnSelectareatograb'
214
TAKE_SCREENSHOT_BUTTON = 'btnTakeScreenshot'
216
SAVE_FILE_WINDOW = 'dlgSaveScreenshot'
217
SAVE_FILE_BUTTON = 'btnSave'
218
SAVE_FILE_NAME_TEXT = 'txtName'
219
SAVE_FILE_FOLDER_DROPDOWN = 'cbSaveFile'
222
Application.__init__(self)
224
def take_whole_desktop_screenshot(self, delay):
226
Complete the "Take Screenshot" dialog box by choosing whole desktop and
227
clicking Take Screenshot.
229
You must have started the application already.
232
@param delay: The number of seconds to delay before taking the
236
gnome_screenshot = ooldtp.context(self.name)
237
except ldtp.LdtpExecutionError:
238
raise ldtp.LdtpExecutionError, "Error finding " + name
241
radio_button = gnome_screenshot.getchild(self.GRAB_THE_WHOLE_DESKTOP_RADIO)
242
except ldtp.LdtpExecutionError:
243
raise ldtp.LdtpExecutionError, "Error finding " + self.GRAB_THE_WHOLE_DESKTOP_RADIO
247
except ldtp.LdtpExecutionError:
248
raise ldtp.LdtpExecutionError, "Error clicking on radio button."
251
delay_field = gnome_screenshot.getchild(self.GRAB_AFTER_DELAY_FIELD)
252
except ldtp.LdtpExecutionError:
253
raise ldtp.LdtpExecutionError, "Error finding " + self.GRAB_AFTER_DELAY_FIELD
256
delay_field.setvalue(delay)
257
except ldtp.LdtpExecutionError:
258
raise ldtp.LdtpExecutionError, "Error setting value to " + self.GRAB_AFTER_DELAY_FIELD
261
save_button = gnome_screenshot.getchild(self.TAKE_SCREENSHOT_BUTTON)
262
except ldtp.LdtpExecutionError:
263
raise ldtp.LdtpExecutionError, "Error finding " + self.TAKE_SCREENSHOT_BUTTON
266
ldtp.click(self.WINDOW, self.TAKE_SCREENSHOT_BUTTON)
267
except ldtp.LdtpExecutionError:
268
raise ldtp.LdtpExecutionError, "Error clicking on save button"
271
ldtp.waittillguinotexist(self.WINDOW)
272
except ldtp.LdtpExecutionError:
273
raise ldtp.LdtpExecutionError, "Window " + self.WINDOW + " did not go away."
276
def take_current_window_screenshot(self, delay):
278
Complete the "Take Screenshot" dialog box by choosing current window and
279
clicking Take Screenshot.
281
You must have started the application already.
284
@param delay: The number of seconds to delay before taking the
288
gnome_screenshot = ooldtp.context(self.name)
289
except ldtp.LdtpExecutionError:
290
raise ldtp.LdtpExecutionError, "Error finding " + name
293
radio_button = gnome_screenshot.getchild(self.GRAB_THE_CURRENT_WINDOW_RADIO)
294
except ldtp.LdtpExecutionError:
295
raise ldtp.LdtpExecutionError, "Error finding " + self.GRAB_THE_CURRENT_WINDOW_RADIO
299
except ldtp.LdtpExecutionError:
300
raise ldtp.LdtpExecutionError, "Error clicking on radio button"
303
delay_field = gnome_screenshot.getchild(self.GRAB_AFTER_DELAY_FIELD)
304
except ldtp.LdtpExecutionError:
305
raise ldtp.LdtpExecutionError, "Error finding " + self.GRAB_AFTER_DELAY_FIELD
308
delay_field.setvalue(delay)
309
except ldtp.LdtpExecutionError:
310
raise ldtp.LdtpExecutionError, "Error setting delay to " + delay
313
save_button = gnome_screenshot.getchild(self.TAKE_SCREENSHOT_BUTTON)
314
except ldtp.LdtpExecutionError:
315
raise ldtp.LdtpExecutionError, "Error finding " + self.TAKE_SCREENSHOT_BUTTON
319
except ldtp.LdtpExecutionError:
320
raise ldtp.LdtpExecutionError, "Error clicking on save button"
323
ldtp.waittillguinotexist(self.WINDOW)
324
except ldtp.LdtpExecutionError:
325
raise ldtp.LdtpExecutionError, "Window " + self.WINDOW + " did not go away"
327
def grab_selected_area(self, delay):
329
Complete the "Take Screenshot" dialog box by choosing selected area and
330
clicking Take Screenshot.
332
You must have started the application already.
335
@param delay: The number of seconds to delay before taking the
339
gnome_screenshot = ooldtp.context(self.name)
340
except ldtp.LdtpExecutionError:
341
raise ldtp.LdtpExecutionError, "Error finding " + name
344
radio_button = gnome_screenshot.getchild(self.GRAB_A_SELECTED_AREA)
345
except ldtp.LdtpExecutionError:
346
raise ldtp.LdtpExecutionError, "Error finding " + self.GRAB_A_SELECTED_AREA
350
except ldtp.LdtpExecutionError:
351
raise ldtp.LdtpExecutionError, "Error clicking on radio button"
354
delay_field = gnome_screenshot.getchild(self.GRAB_AFTER_DELAY_FIELD)
355
except ldtp.LdtpExecutionError:
356
raise ldtp.LdtpExecutionError, "Error finding " + self.GRAB_AFTER_DELAY_FIELD
359
delay_field.setvalue(delay)
360
except ldtp.LdtpExecutionError:
361
raise ldtp.LdtpExecutionError, "Error setting delay to " + delay
364
save_button = gnome_screenshot.getchild(self.TAKE_SCREENSHOT_BUTTON)
365
except ldtp.LdtpExecutionError:
366
raise ldtp.LdtpExecutionError, "Error finding " + self.TAKE_SCREENSHOT_BUTTON
370
except ldtp.LdtpExecutionError:
371
raise ldtp.LdtpExecutionError, "Error clicking on save button"
374
ldtp.waittillguinotexist(self.WINDOW)
375
except ldtp.LdtpExecutionError:
376
raise ldtp.LdtpExecutionError, "Window " + self.WINDOW + " did not go away"
378
# Select the area of the screen for the screenshot. As long as your screen is
379
# larger than 200x200px this should work fine.
381
ldtp.generatemouseevent(100,100,'b1p') # button 1 press
382
ldtp.generatemouseevent(200,200,'abs') # move mouse to 200,200
383
ldtp.generatemouseevent(200,200,'b1r') # button 1 release
384
except ldtp.LdtpExecutionError:
385
raise ldtp.LdtpExecutionError, "Error selecting screen area"
387
def save_to_file(self, filename):
389
Complete the save to file dialog. You must have completed a grab_* already
391
@type filename: string
392
@param filename: The name of the file to save. This file will be saved
393
into the current users home folder. You cannot
397
ldtp.waittillguiexist(self.SAVE_FILE_WINDOW)
398
except ldtp.LdtpExecutionError:
399
raise ldtp.LdtpExecutionError, "Window " + self.SAVE_FILE_WINDOW + " did not appear"
402
save_file_window = ooldtp.context(self.SAVE_FILE_WINDOW)
403
except ldtp.LdtpExecutionError:
404
raise ldtp.LdtpExecutionError, "Error finding window " + self.SAVE_FILE_WINDOW
407
filename_field = save_file_window.getchild(self.SAVE_FILE_NAME_TEXT)
408
except ldtp.LdtpExecutionError:
409
raise ldtp.LdtpExecutionError, "Error finding " + self.SAVE_FILE_NAME_TEXT
412
filename_field.settextvalue(filename)
413
except ldtp.LdtpExecutionError:
414
raise ldtp.LdtpExecutionError, "Error setting filename to " + delay
416
# There is a bug in gnome-screenshot that prevents the combobox
417
# name from being used. There is only one combo box so its easy to
418
# select it by index.
420
# Also for some reason ooldtp didn't seem to be able select the combo
423
ldtp.comboselectindex(self.SAVE_FILE_WINDOW, "cbo#0", 0)
424
except ldtp.LdtpExecutionError:
425
raise ldtp.LdtpExecutionError, "Error setting folder to home folder"
428
save_file_button = save_file_window.getchild(self.SAVE_FILE_BUTTON)
429
except ldtp.LdtpExecutionError:
430
raise ldtp.LdtpExecutionError, "Error finding " + self.SAVE_FILE_BUTTON
433
save_file_button.click()
434
except ldtp.LdtpExecutionError:
435
raise ldtp.LdtpExecutionError, "Error clicking on save button"
438
ldtp.waittillguinotexist(self.SAVE_FILE_WINDOW)
439
except ldtp.LdtpExecutionError:
440
raise ldtp.LdtpExecutionError, "Window " + self.SAVE_FILE_WINDOW + " did not go away"
10
442
class Seahorse(Application):