2
This is the "gnome" module.
4
The gnome module provides wrappers for LDTP to make the write of Gnome tests easier.
8
from .main import Application
10
class Seahorse(Application):
12
Seahorse manages the Seahorse application.
14
WINDOW = "frmPasswordsandEncryptionKeys"
17
NEWKEY_DLG = "Create New ..."
18
BTN_CONTINUE = "btnContinue"
20
NEWPGP_DLG = "dlgCreateaPGPKey"
21
DLG_NEWPGP_FULLNAME = "txtFullName"
22
DLG_NEWPGP_EMAIL = "txtEmailAddress"
23
DLG_NEWPGP_COMMENT = "txtComment"
24
BTN_NEWPGP_CREATE = "btnCreate"
25
DLG_NEWKEY_PASS = "dlgPassphrasefor*"
27
DLG_GENERATING_KEY = "dlgGeneratingkey"
28
DLG_CREATING_SSH = "dlgCreatingSecureShellKey"
29
TYPE_SSH = "Secure Shell Key"
30
NEWSSH_DLG = "New Secure Shell Key"
31
DLG_NEWSSH_DESC = "txtKeyDescription"
32
BTN_NEWSSH_CREATE_AND_SETUP = "Create and Set Up"
33
DLG_SET_UP = "Set Up Computer for SSH Connection"
34
TXT_SET_UP_COMPUTER = "txtThehostnameoraddressoftheserver."
35
TXT_SET_UP_LOGIN = "txtLoginName"
36
BTN_SET_UP = "btnSetUp"
37
BTN_NEWSSH_CREATE = "Just Create Key"
38
TAB_PERSONAL_KEYS = "My Personal Keys"
40
TBL_PERSONAL_KEYS = "tbl0"
41
LBL_DELETE_KEY_Q = "lblOneormoreofthedeletedkeysareprivatekeys.Areyousureyouwanttoproceed?"
44
Application.__init__(self)
45
self.generated_keys = []
47
def new_key(self, key_type):
49
It opens up the list of available new keys, and select the one to create.
51
@type key_type: string
52
@param key_type: The type of key to create.
55
seahorse = ooldtp.context(self.name)
58
mnu_new_key = seahorse.getchild(self.MNU_NEWKEY)
59
except ldtp.LdtpExecutionError:
60
raise ldtp.LdtpExecutionError, "The new key menu was not found."
63
mnu_new_key.selectmenuitem()
64
except ldtp.LdtpExecutionError:
65
raise ldtp.LdtpExecutionError, "There was a problem when selecting new key menu item."
68
ldtp.waittillguiexist(self.NEWKEY_DLG)
69
dlg_new_key = ooldtp.context(self.NEWKEY_DLG)
70
except ldtp.LdtpExecutionError:
71
raise ldtp.LdtpExecutionError, "The new key dialog was not found."
74
table = dlg_new_key.getchild(role = 'table')
75
types_table = table[0]
77
for i in range(0, types_table.getrowcount(), 1):
78
text = types_table.getcellvalue(i, 1)
79
candidate = text.split('\n')[0]
80
if candidate == key_type:
81
types_table.selectrowindex(i)
84
except ldtp.LdtpExecutionError:
85
raise ldtp.LdtpExecutionError, "Error getting the key types table."
88
btn_continue = dlg_new_key.getchild(self.BTN_CONTINUE)
89
except ldtp.LdtpExecutionError:
90
raise ldtp.LdtpExecutionError, "The continue button at the new key dialog was not found."
94
except ldtp.LdtpExecutionError:
95
raise ldtp.LdtpExecutionError, "There was a problem when clicking the continue button."
97
def new_pgp_key(self, full_name, email, comment, passphrase):
99
It creates a new PGP key with the default settings.
101
TODO: Allow advanced options
102
TODO: Check the list afterwards for the newly created key
104
@type full_name: string
105
@param full_name: Full name to type for the PGP key
108
@param email: Email to type for the PGP key
110
@type comment: string
111
@param comment: Comment to type for the PGP key
113
@type passphrase: string
114
@param passphrase: Passphrase to type for the PGP key
117
self.new_key(self.TYPE_PGP)
120
ldtp.waittillguiexist(self.NEWPGP_DLG)
121
dlg_new_pgp = ooldtp.context(self.NEWPGP_DLG)
122
except ldtp.LdtpExecutionError:
123
raise ldtp.LdtpExecutionError, "The new key dialog was not found."
126
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_FULLNAME)
127
except ldtp.LdtpExecutionError:
128
raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
130
txt_field.settextvalue(full_name)
131
except ldtp.LdtpExecutionError:
132
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
135
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_EMAIL)
136
except ldtp.LdtpExecutionError:
137
raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
139
txt_field.settextvalue(email)
140
except ldtp.LdtpExecutionError:
141
raise ldtp.LdtpExecutionError, "There was a problem when writing the text."
144
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_COMMENT)
145
except ldtp.LdtpExecutionError:
146
raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
148
txt_field.settextvalue(comment)
149
except ldtp.LdtpExecutionError:
150
raise ldtp.LdtpExecutionError, "There was a problem when writing the text."
153
btn_create = dlg_new_pgp.getchild(self.BTN_NEWPGP_CREATE)
154
except ldtp.LdtpExecutionError:
155
raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
159
except ldtp.LdtpExecutionError:
160
raise ldtp.LdtpExecutionError, "There was a problem when clicking the create button."
163
ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
164
dlg_new_pgp_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
165
except ldtp.LdtpExecutionError:
166
raise ldtp.LdtpExecutionError, "The new pgp key passphrase dialog was not found."
169
ldtp.enterstring(passphrase)
170
ldtp.enterstring("<tab>")
171
ldtp.enterstring(passphrase)
172
except ldtp.LdtpExecutionError:
173
raise ldtp.LdtpExecutionError, "Error entering passphrase."
176
btn_pass_ok = dlg_new_pgp_pass.getchild(self.BTN_PASS_OK)
177
except ldtp.LdtpExecutionError:
178
raise ldtp.LdtpExecutionError, "The OK button at the new PGP key passphrase dialog was not found."
182
except ldtp.LdtpExecutionError:
183
raise ldtp.LdtpExecutionError, "There was a problem when clicking the OK button."
186
ldtp.waittillguiexist(self.DLG_GENERATING_KEY)
187
while ldtp.guiexist(self.DLG_GENERATING_KEY) == 1:
189
except ldtp.LdtpExecutionError:
190
raise ldtp.LdtpExecutionError, "The new pgp generating key dialog was not found."
192
# Add key name to generated key list, so we know to delete it later.
193
self.generated_keys.append(' '.join([full_name, email, "'"+comment+"'"]))
195
def new_ssh_key(self, description, passphrase, set_up = False, computer = '', login = ''):
197
It creates a new SSH key with the default settings.
199
TODO: Setting up the key is not working yet
201
@type description: string
202
@param description: Description to type in the SSH key
204
@type passphrase: string
205
@param passphrase: Passphrase to type for the SSH key
207
@type set_up: boolean
208
@param passphrase: True, to set up the SSH key
210
@type computer: string
211
@param computer: URL or IP of the computer to set up the key
214
@param login: Login to use in the remote computer
217
self.new_key(self.TYPE_SSH)
220
ldtp.waittillguiexist(self.NEWSSH_DLG)
221
dlg_new_ssh = ooldtp.context(self.NEWSSH_DLG)
222
except ldtp.LdtpExecutionError:
223
raise ldtp.LdtpExecutionError, "The new key dialog was not found."
226
txt_field = dlg_new_ssh.getchild(self.DLG_NEWSSH_DESC)
227
except ldtp.LdtpExecutionError:
228
raise ldtp.LdtpExecutionError, "The " + self.DLG_NEWSSH_DESC + " text field was not found."
230
txt_field.settextvalue(description)
231
except ldtp.LdtpExecutionError:
232
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
236
btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE_AND_SETUP)
237
except ldtp.LdtpExecutionError:
238
raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
242
btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE)
243
except ldtp.LdtpExecutionError:
244
raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
248
except ldtp.LdtpExecutionError:
249
raise ldtp.LdtpExecutionError, "There was a problem when clicking the create button."
253
ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
254
dlg_new_key_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
255
except ldtp.LdtpExecutionError:
256
raise ldtp.LdtpExecutionError, "The new key passphrase dialog was not found."
259
ldtp.enterstring(passphrase)
260
ldtp.enterstring("<tab>")
261
ldtp.enterstring(passphrase)
262
except ldtp.LdtpExecutionError:
263
raise ldtp.LdtpExecutionError, "Error entering passphrase."
266
btn_pass_ok = dlg_new_key_pass.getchild(self.BTN_PASS_OK)
267
except ldtp.LdtpExecutionError:
268
raise ldtp.LdtpExecutionError, "The OK button at the new key passphrase dialog was not found."
272
except ldtp.LdtpExecutionError:
273
raise ldtp.LdtpExecutionError, "There was a problem when clicking the OK button."
275
if set_up == True and login is not None:
278
ldtp.waittillguiexist(self.DLG_SET_UP)
279
dlg_set_up_computer = ooldtp.context(self.DLG_SET_UP)
280
except ldtp.LdtpExecutionError:
281
raise ldtp.LdtpExecutionError, "The set up computer dialog was not found."
284
txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_LOGIN)
285
except ldtp.LdtpExecutionError:
286
raise ldtp.LdtpExecutionError, "The " + self.TXT_SET_UP_LOGIN + " text field was not found."
288
txt_field.settextvalue(login)
289
except ldtp.LdtpExecutionError:
290
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
294
txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_COMPUTER)
295
except ldtp.LdtpExecutionError:
296
raise ldtp.LdtpExecutionError, "The " + self.TXT_SET_UP_COMPUTER + " text field was not found."
298
txt_field.settextvalue(computer)
299
except ldtp.LdtpExecutionError:
300
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
303
btn_set_up = dlg_set_up_computer.getchild(self.BTN_SET_UP)
304
except ldtp.LdtpExecutionError:
305
raise ldtp.LdtpExecutionError, "The set up button was not found."
309
except ldtp.LdtpExecutionError:
310
raise ldtp.LdtpExecutionError, "There was a problem when clicking the set up button."
313
while ldtp.guiexist(self.DLG_CREATING_SSH) == 1:
316
except ldtp.LdtpExecutionError:
317
raise ldtp.LdtpExecutionError, "The creating key dialog was not found."
318
# Add key name to generated key list, so we know to delete it later.
319
self.generated_keys.append(description)
321
# It is too fast to grab the main window afterwards
324
def go_to_tab(self, tab_name):
326
Go to the specified tab.
328
seahorse = ooldtp.context(self.name)
329
page_list = seahorse.getchild(self.TAB_LIST)
330
page_list.selecttab(self.TAB_PERSONAL_KEYS)
333
def assert_exists_key(self, name, tab_name = None):
335
It checks that the KEY with description 'description' is
336
part of the keys of the current user
339
@param name: The name of the key to search
341
@type tab_name: string
342
@param tab_name: The tab name to search for the key.
345
tab_name = self.TAB_PERSONAL_KEYS
347
self.go_to_tab(tab_name)
348
seahorse = ooldtp.context(self.name)
349
return bool(seahorse.doesrowexist(self.TBL_PERSONAL_KEYS, name))
351
def remove_key(self, key):
352
seahorse = ooldtp.context(self.name)
354
tbl_personal_keys = seahorse.getchild(self.TBL_PERSONAL_KEYS)
355
mnu_delete = seahorse.getchild('mnuDelete')
356
dlg_question = ooldtp.context('dlgQuestion')
359
tbl_personal_keys.selectrow(key)
360
except ldtp.LdtpExecutionError:
361
# Doesn't exist, return False.
364
mnu_delete.selectmenuitem()
365
# General 'private key' verification.
366
dlg_question.waittillguiexist(self.LBL_DELETE_KEY_Q)
367
dlg_question.click('btnDelete')
368
dlg_question.waittillguinotexist(self.LBL_DELETE_KEY_Q)
370
# Specific key type verification.
371
dlg_question.waittillguiexist()
372
dlg_question.click('btnDelete')
373
dlg_question.waittillguinotexist()
377
def remove_keys(self, keys=None, tab_name=None):
378
self.go_to_tab(tab_name or self.TAB_PERSONAL_KEYS)
380
keys = keys or self.generated_keys
385
class GEdit(Application):
387
GEdit manages the Gedit application.
392
SAVE_DLG = "dlgSave*"
393
SAVE_DLG_TXT_NAME = "txtName"
394
SAVE_DLG_BTN_SAVE = "btnSave"
395
QUESTION_DLG = "dlgQuestion"
396
QUESTION_DLG_BTN_SAVE = "btnSave"
397
QUESTION_DLG_BTN_SAVE_AS = "btnSaveAs"
398
QUESTION_DLG_BTN_CLOSE = "btnClosewithoutSaving"
400
MNU_CLOSE = "mnuClose"
404
Application.__init__(self)
407
def write_text(self, text):
409
It writes text to the current buffer of the Gedit window.
412
@param text: The text string to be written to the current buffer.
414
Application.write_text(self, text, self.TXT_FIELD)
416
def save(self, filename):
418
It tries to save the current opened buffer to the filename passed as parameter.
420
TODO: It does not manage the overwrite dialog yet.
422
@type filename: string
423
@param filename: The name of the file to save the buffer to.
425
Application.save(self)
426
ooldtp.context(self.name)
429
ldtp.waittillguiexist(self.SAVE_DLG)
430
save_dialog = ooldtp.context(self.SAVE_DLG)
431
except ldtp.LdtpExecutionError:
432
raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
434
save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
435
except ldtp.LdtpExecutionError:
436
raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
439
save_dlg_txt_filename.settextvalue(filename)
440
except ldtp.LdtpExecutionError:
441
raise ldtp.LdtpExecutionError, "We couldn't write text."
444
save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
445
except ldtp.LdtpExecutionError:
446
raise ldtp.LdtpExecutionError, "The button Save in Gedit save dialog was not found."
449
save_dlg_btn_save.click()
450
except ldtp.LdtpExecutionError:
451
raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
453
ldtp.waittillguinotexist(self.SAVE_DLG)
456
def close(self, save=False, filename=''):
458
Given a gedit window, it tries to close the application.
459
By default, it closes without saving. This behaviour can be changed to save (or save as) on close.
462
@param save: If True, the edited file will be saved on close.
464
@type filename: string
465
@param filename: The file name to save the buffer to
468
# Exit using the Quit menu
470
gedit = ooldtp.context(self.name)
472
quit_menu = gedit.getchild(self.MNU_QUIT)
473
except ldtp.LdtpExecutionError:
474
raise ldtp.LdtpExecutionError, "The quit menu was not found."
475
quit_menu.selectmenuitem()
476
except ldtp.LdtpExecutionError:
477
raise ldtp.LdtpExecutionError, "Mmm, something went wrong when closing the application."
479
question_dialog = None
481
while not gedit.waittillguinotexist(guiTimeOut=1) and \
484
question_dialog = ooldtp.context(self.QUESTION_DLG)
490
# If the text has changed, the save dialog will appear
492
# Test if the file needs to be saved
495
question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE)
496
question_dlg_btn_save.click()
497
except ldtp.LdtpExecutionError:
498
# If the Save button was not found, we will try to find the Save As
500
question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE_AS)
501
question_dlg_btn_save.click()
502
except ldtp.LdtpExecutionError:
503
raise ldtp.LdtpExecutionError, "The save or save as buttons in Gedit question dialog were not found."
506
ldtp.waittillguiexist(self.SAVE_DLG)
507
save_dialog = ooldtp.context(self.SAVE_DLG)
508
except ldtp.LdtpExecutionError:
509
raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
511
save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
512
except ldtp.LdtpExecutionError:
513
raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
516
save_dlg_txt_filename.settextvalue(filename)
517
except ldtp.LdtpExecutionError:
518
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
521
save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
522
except ldtp.LdtpExecutionError:
523
raise ldtp.LdtpExecutionError, "The save button in Gedit save dialog was not found."
526
save_dlg_btn_save.click()
527
except ldtp.LdtpExecutionError:
528
raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
530
ldtp.waittillguinotexist(self.SAVE_DLG)
534
question_dlg_btn_close = question_dialog.getchild(self.QUESTION_DLG_BTN_CLOSE)
535
question_dlg_btn_close.click()
536
except ldtp.LdtpExecutionError:
537
raise ldtp.LdtpExecutionError, "It was not possible to click the close button."
539
gedit.waittillguinotexist(guiTimeOut=20)
541
class PolicyKit(Application):
543
PolicyKit class manages the GNOME pop up that ask for password for admin activities.
546
TXT_PASS = "txtPassword"
548
BTN_CANCEL = "btnCancel"
551
def __init__(self, password):
553
UpdateManager class main constructor
555
@type password: string
556
@param password: User's password for administrative tasks.
559
Application.__init__(self)
560
self.password = password
564
Wait for the pop up window asking for the password to appear.
566
@return 1, if the gksu window exists, 0 otherwise.
568
return ldtp.waittillguiexist(self.name)
570
def set_password(self):
572
It enters the password in the text field and clicks enter.
575
ooldtp.context(self.name)
578
ldtp.enterstring (self.password)
579
ldtp.enterstring ("<enter>")
581
except ldtp.LdtpExecutionError:
582
raise ldtp.LdtpExecutionError, "The PolicyKit txt field for the password was not found."
584
# TODO: Change this to use ooldtp
586
# btnOK = polKit.getchild(self.BTN_OK)
587
# except ldtp.LdtpExecutionError, msg:
588
# raise ldtp.LdtpExecutionError, "The GtkSudo OK button was not found."
592
#This also have problems because of the lack of accesibiliy information
593
#ldtp.waittillguinotexist (self.name)
596
polKit = ooldtp.context(self.name)
599
cancelButton = polKit.getchild(self.BTN_CANCEL)
600
except ldtp.LdtpExecutionError:
601
raise ldtp.LdtpExecutionError, "The PolicyKit cancel button was not found."
604
ldtp.waittillguinotexist (self.name)