3
This is the "gnome" module.
5
The gnome module provides wrappers for LDTP to make the write of Gnome tests easier.
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('txtResultRegion') # txtResultRegion
192
value = editBar.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"
442
class Seahorse(Application):
444
Seahorse manages the Seahorse application.
446
WINDOW = "frmPasswordsandEncryptionKeys"
447
LAUNCHER = "seahorse"
448
MNU_NEWKEY = "mnuNew"
449
NEWKEY_DLG = "Create New ..."
450
BTN_CONTINUE = "btnContinue"
452
NEWPGP_DLG = "dlgCreateaPGPKey"
453
DLG_NEWPGP_FULLNAME = "txtFullName"
454
DLG_NEWPGP_EMAIL = "txtEmailAddress"
455
DLG_NEWPGP_COMMENT = "txtComment"
456
BTN_NEWPGP_CREATE = "btnCreate"
457
DLG_NEWKEY_PASS = "dlgPassphrasefor*"
458
BTN_PASS_OK = "btnOK"
459
DLG_GENERATING_KEY = "dlgGeneratingkey"
460
DLG_CREATING_SSH = "dlgCreatingSecureShellKey"
461
TYPE_SSH = "Secure Shell Key"
462
NEWSSH_DLG = "New Secure Shell Key"
463
DLG_NEWSSH_DESC = "txtKeyDescription"
464
BTN_NEWSSH_CREATE_AND_SETUP = "Create and Set Up"
465
DLG_SET_UP = "Set Up Computer for SSH Connection"
466
TXT_SET_UP_COMPUTER = "txtThehostnameoraddressoftheserver."
467
TXT_SET_UP_LOGIN = "txtLoginName"
468
BTN_SET_UP = "btnSetUp"
469
BTN_NEWSSH_CREATE = "Just Create Key"
470
TAB_PERSONAL_KEYS = "My Personal Keys"
472
TBL_PERSONAL_KEYS = "tbl0"
473
LBL_DELETE_KEY_Q = "lblOneormoreofthedeletedkeysareprivatekeys.Areyousureyouwanttoproceed?"
476
Application.__init__(self)
477
self.generated_keys = []
479
def new_key(self, key_type):
481
It opens up the list of available new keys, and select the one to create.
483
@type key_type: string
484
@param key_type: The type of key to create.
487
seahorse = ooldtp.context(self.name)
490
mnu_new_key = seahorse.getchild(self.MNU_NEWKEY)
491
except ldtp.LdtpExecutionError:
492
raise ldtp.LdtpExecutionError, "The new key menu was not found."
495
mnu_new_key.selectmenuitem()
496
except ldtp.LdtpExecutionError:
497
raise ldtp.LdtpExecutionError, "There was a problem when selecting new key menu item."
500
ldtp.waittillguiexist(self.NEWKEY_DLG)
501
dlg_new_key = ooldtp.context(self.NEWKEY_DLG)
502
except ldtp.LdtpExecutionError:
503
raise ldtp.LdtpExecutionError, "The new key dialog was not found."
506
table = dlg_new_key.getchild(role = 'table')
507
types_table = table[0]
509
for i in range(0, types_table.getrowcount(), 1):
510
text = types_table.getcellvalue(i, 1)
511
candidate = text.split('\n')[0]
512
if candidate == key_type:
513
types_table.selectrowindex(i)
516
except ldtp.LdtpExecutionError:
517
raise ldtp.LdtpExecutionError, "Error getting the key types table."
520
btn_continue = dlg_new_key.getchild(self.BTN_CONTINUE)
521
except ldtp.LdtpExecutionError:
522
raise ldtp.LdtpExecutionError, "The continue button at the new key dialog was not found."
526
except ldtp.LdtpExecutionError:
527
raise ldtp.LdtpExecutionError, "There was a problem when clicking the continue button."
529
def new_pgp_key(self, full_name, email, comment, passphrase):
531
It creates a new PGP key with the default settings.
533
TODO: Allow advanced options
534
TODO: Check the list afterwards for the newly created key
536
@type full_name: string
537
@param full_name: Full name to type for the PGP key
540
@param email: Email to type for the PGP key
542
@type comment: string
543
@param comment: Comment to type for the PGP key
545
@type passphrase: string
546
@param passphrase: Passphrase to type for the PGP key
549
self.new_key(self.TYPE_PGP)
552
ldtp.waittillguiexist(self.NEWPGP_DLG)
553
dlg_new_pgp = ooldtp.context(self.NEWPGP_DLG)
554
except ldtp.LdtpExecutionError:
555
raise ldtp.LdtpExecutionError, "The new key dialog was not found."
558
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_FULLNAME)
559
except ldtp.LdtpExecutionError:
560
raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
562
txt_field.settextvalue(full_name)
563
except ldtp.LdtpExecutionError:
564
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
567
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_EMAIL)
568
except ldtp.LdtpExecutionError:
569
raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
571
txt_field.settextvalue(email)
572
except ldtp.LdtpExecutionError:
573
raise ldtp.LdtpExecutionError, "There was a problem when writing the text."
576
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_COMMENT)
577
except ldtp.LdtpExecutionError:
578
raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
580
txt_field.settextvalue(comment)
581
except ldtp.LdtpExecutionError:
582
raise ldtp.LdtpExecutionError, "There was a problem when writing the text."
585
btn_create = dlg_new_pgp.getchild(self.BTN_NEWPGP_CREATE)
586
except ldtp.LdtpExecutionError:
587
raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
591
except ldtp.LdtpExecutionError:
592
raise ldtp.LdtpExecutionError, "There was a problem when clicking the create button."
595
ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
596
dlg_new_pgp_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
597
except ldtp.LdtpExecutionError:
598
raise ldtp.LdtpExecutionError, "The new pgp key passphrase dialog was not found."
601
ldtp.enterstring(passphrase)
602
ldtp.enterstring("<tab>")
603
ldtp.enterstring(passphrase)
604
except ldtp.LdtpExecutionError:
605
raise ldtp.LdtpExecutionError, "Error entering passphrase."
608
btn_pass_ok = dlg_new_pgp_pass.getchild(self.BTN_PASS_OK)
609
except ldtp.LdtpExecutionError:
610
raise ldtp.LdtpExecutionError, "The OK button at the new PGP key passphrase dialog was not found."
614
except ldtp.LdtpExecutionError:
615
raise ldtp.LdtpExecutionError, "There was a problem when clicking the OK button."
618
ldtp.waittillguiexist(self.DLG_GENERATING_KEY)
619
while ldtp.guiexist(self.DLG_GENERATING_KEY) == 1:
621
except ldtp.LdtpExecutionError:
622
raise ldtp.LdtpExecutionError, "The new pgp generating key dialog was not found."
624
# Add key name to generated key list, so we know to delete it later.
625
self.generated_keys.append(' '.join([full_name, email, "'"+comment+"'"]))
627
def new_ssh_key(self, description, passphrase, set_up = False, computer = '', login = ''):
629
It creates a new SSH key with the default settings.
631
TODO: Setting up the key is not working yet
633
@type description: string
634
@param description: Description to type in the SSH key
636
@type passphrase: string
637
@param passphrase: Passphrase to type for the SSH key
639
@type set_up: boolean
640
@param passphrase: True, to set up the SSH key
642
@type computer: string
643
@param computer: URL or IP of the computer to set up the key
646
@param login: Login to use in the remote computer
649
self.new_key(self.TYPE_SSH)
652
ldtp.waittillguiexist(self.NEWSSH_DLG)
653
dlg_new_ssh = ooldtp.context(self.NEWSSH_DLG)
654
except ldtp.LdtpExecutionError:
655
raise ldtp.LdtpExecutionError, "The new key dialog was not found."
658
txt_field = dlg_new_ssh.getchild(self.DLG_NEWSSH_DESC)
659
except ldtp.LdtpExecutionError:
660
raise ldtp.LdtpExecutionError, "The " + self.DLG_NEWSSH_DESC + " text field was not found."
662
txt_field.settextvalue(description)
663
except ldtp.LdtpExecutionError:
664
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
668
btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE_AND_SETUP)
669
except ldtp.LdtpExecutionError:
670
raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
674
btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE)
675
except ldtp.LdtpExecutionError:
676
raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
680
except ldtp.LdtpExecutionError:
681
raise ldtp.LdtpExecutionError, "There was a problem when clicking the create button."
685
ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
686
dlg_new_key_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
687
except ldtp.LdtpExecutionError:
688
raise ldtp.LdtpExecutionError, "The new key passphrase dialog was not found."
691
ldtp.enterstring(passphrase)
692
ldtp.enterstring("<tab>")
693
ldtp.enterstring(passphrase)
694
except ldtp.LdtpExecutionError:
695
raise ldtp.LdtpExecutionError, "Error entering passphrase."
698
btn_pass_ok = dlg_new_key_pass.getchild(self.BTN_PASS_OK)
699
except ldtp.LdtpExecutionError:
700
raise ldtp.LdtpExecutionError, "The OK button at the new key passphrase dialog was not found."
704
except ldtp.LdtpExecutionError:
705
raise ldtp.LdtpExecutionError, "There was a problem when clicking the OK button."
707
if set_up == True and login is not None:
710
ldtp.waittillguiexist(self.DLG_SET_UP)
711
dlg_set_up_computer = ooldtp.context(self.DLG_SET_UP)
712
except ldtp.LdtpExecutionError:
713
raise ldtp.LdtpExecutionError, "The set up computer dialog was not found."
716
txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_LOGIN)
717
except ldtp.LdtpExecutionError:
718
raise ldtp.LdtpExecutionError, "The " + self.TXT_SET_UP_LOGIN + " text field was not found."
720
txt_field.settextvalue(login)
721
except ldtp.LdtpExecutionError:
722
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
726
txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_COMPUTER)
727
except ldtp.LdtpExecutionError:
728
raise ldtp.LdtpExecutionError, "The " + self.TXT_SET_UP_COMPUTER + " text field was not found."
730
txt_field.settextvalue(computer)
731
except ldtp.LdtpExecutionError:
732
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
735
btn_set_up = dlg_set_up_computer.getchild(self.BTN_SET_UP)
736
except ldtp.LdtpExecutionError:
737
raise ldtp.LdtpExecutionError, "The set up button was not found."
741
except ldtp.LdtpExecutionError:
742
raise ldtp.LdtpExecutionError, "There was a problem when clicking the set up button."
745
while ldtp.guiexist(self.DLG_CREATING_SSH) == 1:
748
except ldtp.LdtpExecutionError:
749
raise ldtp.LdtpExecutionError, "The creating key dialog was not found."
750
# Add key name to generated key list, so we know to delete it later.
751
self.generated_keys.append(description)
753
# It is too fast to grab the main window afterwards
756
def go_to_tab(self, tab_name):
758
Go to the specified tab.
760
seahorse = ooldtp.context(self.name)
761
page_list = seahorse.getchild(self.TAB_LIST)
762
page_list.selecttab(self.TAB_PERSONAL_KEYS)
765
def assert_exists_key(self, name, tab_name = None):
767
It checks that the KEY with description 'description' is
768
part of the keys of the current user
771
@param name: The name of the key to search
773
@type tab_name: string
774
@param tab_name: The tab name to search for the key.
777
tab_name = self.TAB_PERSONAL_KEYS
779
self.go_to_tab(tab_name)
780
seahorse = ooldtp.context(self.name)
781
return bool(seahorse.doesrowexist(self.TBL_PERSONAL_KEYS, name))
783
def remove_key(self, key):
784
seahorse = ooldtp.context(self.name)
786
tbl_personal_keys = seahorse.getchild(self.TBL_PERSONAL_KEYS)
787
mnu_delete = seahorse.getchild('mnuDelete')
788
dlg_question = ooldtp.context('dlgQuestion')
791
tbl_personal_keys.selectrow(key)
792
except ldtp.LdtpExecutionError:
793
# Doesn't exist, return False.
796
mnu_delete.selectmenuitem()
797
# General 'private key' verification.
798
dlg_question.waittillguiexist(self.LBL_DELETE_KEY_Q)
799
dlg_question.click('btnDelete')
800
dlg_question.waittillguinotexist(self.LBL_DELETE_KEY_Q)
802
# Specific key type verification.
803
dlg_question.waittillguiexist()
804
dlg_question.click('btnDelete')
805
dlg_question.waittillguinotexist()
809
def remove_keys(self, keys=None, tab_name=None):
810
self.go_to_tab(tab_name or self.TAB_PERSONAL_KEYS)
812
keys = keys or self.generated_keys
817
class GEdit(Application):
819
GEdit manages the Gedit application.
824
SAVE_DLG = "dlgSave*"
825
SAVE_DLG_TXT_NAME = "txtName"
826
SAVE_DLG_BTN_SAVE = "btnSave"
827
QUESTION_DLG = "dlgQuestion"
828
QUESTION_DLG_BTN_SAVE = "btnSave"
829
QUESTION_DLG_BTN_SAVE_AS = "btnSaveAs"
830
QUESTION_DLG_BTN_CLOSE = "btnClosewithoutSaving"
832
MNU_CLOSE = "mnuClose"
836
Application.__init__(self)
839
def write_text(self, text):
841
It writes text to the current buffer of the Gedit window.
844
@param text: The text string to be written to the current buffer.
846
Application.write_text(self, text, self.TXT_FIELD)
848
def save(self, filename):
850
It tries to save the current opened buffer to the filename passed as parameter.
852
TODO: It does not manage the overwrite dialog yet.
854
@type filename: string
855
@param filename: The name of the file to save the buffer to.
857
Application.save(self)
858
ooldtp.context(self.name)
861
ldtp.waittillguiexist(self.SAVE_DLG)
862
save_dialog = ooldtp.context(self.SAVE_DLG)
863
except ldtp.LdtpExecutionError:
864
raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
866
save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
867
except ldtp.LdtpExecutionError:
868
raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
871
save_dlg_txt_filename.settextvalue(filename)
872
except ldtp.LdtpExecutionError:
873
raise ldtp.LdtpExecutionError, "We couldn't write text."
876
save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
877
except ldtp.LdtpExecutionError:
878
raise ldtp.LdtpExecutionError, "The button Save in Gedit save dialog was not found."
881
save_dlg_btn_save.click()
882
except ldtp.LdtpExecutionError:
883
raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
885
ldtp.waittillguinotexist(self.SAVE_DLG)
888
def close(self, save=False, filename=''):
890
Given a gedit window, it tries to close the application.
891
By default, it closes without saving. This behaviour can be changed to save (or save as) on close.
894
@param save: If True, the edited file will be saved on close.
896
@type filename: string
897
@param filename: The file name to save the buffer to
900
# Exit using the Quit menu
902
gedit = ooldtp.context(self.name)
904
quit_menu = gedit.getchild(self.MNU_QUIT)
905
except ldtp.LdtpExecutionError:
906
raise ldtp.LdtpExecutionError, "The quit menu was not found."
907
quit_menu.selectmenuitem()
908
except ldtp.LdtpExecutionError:
909
raise ldtp.LdtpExecutionError, "Mmm, something went wrong when closing the application."
911
question_dialog = None
913
while not gedit.waittillguinotexist(guiTimeOut=1) and \
916
question_dialog = ooldtp.context(self.QUESTION_DLG)
922
# If the text has changed, the save dialog will appear
924
# Test if the file needs to be saved
927
question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE)
928
question_dlg_btn_save.click()
929
except ldtp.LdtpExecutionError:
930
# If the Save button was not found, we will try to find the Save As
932
question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE_AS)
933
question_dlg_btn_save.click()
934
except ldtp.LdtpExecutionError:
935
raise ldtp.LdtpExecutionError, "The save or save as buttons in Gedit question dialog were not found."
938
ldtp.waittillguiexist(self.SAVE_DLG)
939
save_dialog = ooldtp.context(self.SAVE_DLG)
940
except ldtp.LdtpExecutionError:
941
raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
943
save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
944
except ldtp.LdtpExecutionError:
945
raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
948
save_dlg_txt_filename.settextvalue(filename)
949
except ldtp.LdtpExecutionError:
950
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
953
save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
954
except ldtp.LdtpExecutionError:
955
raise ldtp.LdtpExecutionError, "The save button in Gedit save dialog was not found."
958
save_dlg_btn_save.click()
959
except ldtp.LdtpExecutionError:
960
raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
962
ldtp.waittillguinotexist(self.SAVE_DLG)
966
question_dlg_btn_close = question_dialog.getchild(self.QUESTION_DLG_BTN_CLOSE)
967
question_dlg_btn_close.click()
968
except ldtp.LdtpExecutionError:
969
raise ldtp.LdtpExecutionError, "It was not possible to click the close button."
971
gedit.waittillguinotexist(guiTimeOut=20)
973
class PolicyKit(Application):
975
PolicyKit class manages the GNOME pop up that ask for password for admin activities.
978
TXT_PASS = "txtPassword"
980
BTN_CANCEL = "btnCancel"
983
def __init__(self, password):
985
UpdateManager class main constructor
987
@type password: string
988
@param password: User's password for administrative tasks.
991
Application.__init__(self)
992
self.password = password
996
Wait for the pop up window asking for the password to appear.
998
@return 1, if the gksu window exists, 0 otherwise.
1000
return ldtp.waittillguiexist(self.name)
1002
def set_password(self):
1004
It enters the password in the text field and clicks enter.
1007
ooldtp.context(self.name)
1010
ldtp.enterstring (self.password)
1011
ldtp.enterstring ("<enter>")
1013
except ldtp.LdtpExecutionError:
1014
raise ldtp.LdtpExecutionError, "The PolicyKit txt field for the password was not found."
1016
# TODO: Change this to use ooldtp
1018
# btnOK = polKit.getchild(self.BTN_OK)
1019
# except ldtp.LdtpExecutionError, msg:
1020
# raise ldtp.LdtpExecutionError, "The GtkSudo OK button was not found."
1024
#This also have problems because of the lack of accesibiliy information
1025
#ldtp.waittillguinotexist (self.name)
1028
polKit = ooldtp.context(self.name)
1031
cancelButton = polKit.getchild(self.BTN_CANCEL)
1032
except ldtp.LdtpExecutionError:
1033
raise ldtp.LdtpExecutionError, "The PolicyKit cancel button was not found."
1035
cancelButton.click()
1036
ldtp.waittillguinotexist (self.name)