Best Python code snippet using pyatom_python
mailtests.py
Source:mailtests.py
1#!/usr/bin/env python2#3# Linux Desktop Testing Project http://ldtp.freedesktop.org4#5# Author:6# Prashanth Mohan <prashmohan@gmail.com>7#8# Copyright 2004 Novell, Inc.9#10# This test script is free software; you can redistribute it and/or11# modify it under the terms of the GNU Library General Public12# License as published by the Free Software Foundation; either13# version 2 of the License, or (at your option) any later version.14#15# This library is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18# Library General Public License for more details.19#20# You should have received a copy of the GNU Library General Public21# License along with this library; if not, write to the22# Free Software Foundation, Inc., 59 Temple Place - Suite 330,23# Boston, MA 02111-1307, USA.24#25from contact import *26from evoutils import *27from evoutils.mail import *28from evoutils.mailpreferences import *29from evoutils.composemail import *30from ldtp import *31from ldtputils import *32import os, time33def htmlformatting():34 log ('Check if formatting elements get disabled when HTML setting is off','teststart')35 try:36 selectMailPane()37 window_id = get_window()38 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')39 waittillguiexist ('*ComposeMessage')40 time.sleep (1)41 menuuncheck ('*ComposeMessage','mnuHTML')42 if stateenabled ('*ComposeMessage','tbtnTypewriter')==1 or stateenabled ('*ComposeMessage','tbtnBold')==1 or stateenabled ('*ComposeMessage','tbtnItalic')==1 or stateenabled ('*ComposeMessage','tbtnStrikeout')==1:43 log ('text formatting is enabled','cause')44 raise LdtpExecutionError(0)45# elif stateenabled ('*ComposeMessage','btnImage') == 1 or stateenabled ('*ComposeMessage','btnRule') == 1 or stateenabled ('*ComposeMessage','btnLink') == 1 or stateenabled ('*ComposeMessage','btnTable') == 1:46# log ('Inserting Objects is enabled','cause')47# raise LdtpExecutionError(0)48 selectmenuitem ('*ComposeMessage','mnuFile;mnuClose')49 except:50 log ('Menus are enabled when HTML is not selected','error')51 log ('Check if formatting elements get disabled when HTML setting is off','fail')52 log ('Check if formatting elements get disabled when HTML setting is off','testend')53 raise LdtpExecutionError (0)54 log ('Check if formatting elements get disabled when HTML setting is off','pass')55 log ('Check if formatting elements get disabled when HTML setting is off','testend')56 57def savemail(savemethod,to, subject=[''], body=[], cc=[], bcc=[], attachment=[], draftfolder='Drafts'):58 log ('Test for saving a mail into Drafts folder','teststart')59 try:60 selectrowpartialmatch ('frmEvolution-*', 'ttblMailFolderTree', draftfolder)61 waittillguiexist ('frmEvolution-'+draftfolder+'*')62 time.sleep (2)63 draft_mail_count = getrowcount ('frmEvolution-*', 'ttblMessages')64 print "Draft count:",draft_mail_count65 compose (to, subject, body, cc,bcc, attachment)66 savethismail (savemethod, get_mail_name (subject[0]))67 testsavemail (draft_mail_count,savemethod)68 except:69 log ('Saving Mail failed','error')70 log ('Test for saving a mail into Drafts folder','testend')71 raise LdtpExecutionError (0)72 log ('Test for saving a mail into Drafts folder','testend')73def testsavemail(draft_count,savemethod):74 log ('Verification for save mail','teststart')75 try:76 if savemethod == 0:77 new_draft_count=getrowcount ('frmEvolution-*','ttblMessages')78 print "new count:",new_draft_count79 if new_draft_count>=draft_count+1:80 log ('Save Mail','pass')81 else:82 log ('Save Mail','fail')83 raise LdtpExecutionError (0)84 elif savemethod == 1:85 home=os.environ.get('HOME')86 if os.path.isfile(home+os.sep+'testfile')==True:87 log ('Save Mail','pass')88 else:89 log ('Save Mail','fail')90 raise LdtpExecutionError (0)91 except:92 log ('Save mail could not be verified','error')93 log ('Verification for save mail','fail')94 log ('Verification for save mail','testend')95 raise LdtpExecutionError (0)96 log ('Verification for save mail','pass')97 log ('Verification for save mail','testend')98def sendmailwhenoffline (to=[], subject=[], body=[], cc=[], bcc=[], attachment=[]):99 log ('Sending mail when evolution is offline','teststart')100 try:101 go_offline()102 except:103 log ('Unable to go offline','cause')104 log ('Sending mail when evolution is offline','testend')105 raise LdtpExecutionError (0)106 try:107 selectrowpartialmatch ('frmEvolution-*', 'ttblMailFolderTree', 'Outbox')108 time.sleep (2)109 waittillguiexist ('frmEvolution-Outbox*')110 outbox_mail_count = getrowcount ('frmEvolution-*', 'ttblMessages')111 selectrowpartialmatch ('frmEvolution-*', 'ttblMailFolderTree', 'Sent')112 time.sleep (2)113 waittillguiexist ('frmEvolution-Sent*')114 sent_mail_count = getrowcount ('frmEvolution-*', 'ttblMessages')115 compose (to, subject, body, cc,bcc, attachment)116 sendmail (subject)117 selectrowpartialmatch ('frmEvolution-*', 'ttblMailFolderTree', 'Outbox')118 waittillguiexist ('frmEvolution-Outbox*')119 time.sleep (10)120 new_outbox_mail_count = getrowcount ('frmEvolution-*', 'ttblMessages')121 print 'Old:',outbox_mail_count, 'New: ',new_outbox_mail_count122 if new_outbox_mail_count >= outbox_mail_count+1:123 log ('Message has been put in OutBox Folder','info')124 else:125 log ('Message has not been put in OutBox Folder','cause')126 raise LdtpExecutionError (0)127 128 go_online ()129 time.sleep (1)130 try:131 click ('frmEvolution-*', 'btnSend/Receive')132 waittillguiexist ('dlgSend&ReceiveMail')133 waittillguinotexist ('dlgSend&ReceiveMail')134 time.sleep (3)135 except:136 log ('could not send mail','cause')137 raise LdtpExecutionError (0)138 selectrowpartialmatch ('frmEvolution-*', 'ttblMailFolderTree', 'Sent')139 waittillguiexist ('frmEvolution-Sent*')140 time.sleep (2)141 new_sent_mail_count = getrowcount ('frmEvolution-*', 'ttblMessages')142 if new_sent_mail_count==sent_mail_count+new_outbox_mail_count:143 log ('Message sent','info')144 log ('Send Mail while offline Succeeded','info')145 else:146 log ('Message send Failed','error')147 raise LdtpExecutionError (0)148 149 except:150 log ('Send Mail while offline failed','error')151 log ('Sending mail when evolution is offline','fail')152 log ('Sending mail when evolution is offline','testend')153 raise LdtpExecutionError (0)154 log ('Sending mail when evolution is offline','pass')155 log ('Sending mail when evolution is offline','testend')156 157def closecomposewindow(state, window_id='frmComposeMessage'):158 """ state == 0 --> Discard Message159 state == 1 --> Cancel Dialog160 state == 2 --> Save Message"""161 log ('Close compose window','teststart')162 try:163 if guiexist (window_id) == 0:164 log ('Compose window not open','cause')165 raise LdtpExecutionError (0)166 except:167 log ('Close compose window','testend')168 raise LdtpExecutionError (0)169 170 try:171 selectmenuitem (window_id,'mnuFile;mnuClose')172 time.sleep (2)173 if guiexist ('dlgWarning*')==1:174 if state==0:175 click ('dlgWarning*','btnDiscardChanges')176 elif state==1:177 click ('dlgWarning*','btnCancel')178 elif state==2:179 click ('dlgWarning*','btnSaveMessage')180 else:181 log ('Invalid option to choose','cause')182 raise LdtpExecutionError (0)183 log ('Warning Window closed successfully','info')184 else:185 log ('Warning window did not arise','warning')186 except:187 log ('Warning Window did not close successfully','error')188 log ('Close compose window','fail')189 log ('Close compose window','testend')190 raise LdtpExecutionError (0)191 waittillguinotexist (window_id)192 time.sleep (2)193 log ('Close compose window','pass')194 log ('Close compose window','testend')195def checkheaders(ref_image):196 log ('Check Compose window header boxes','teststart')197 try:198 window_id=getcurwindow()199 selectmenuitem ('window_id','mnuFile;mnuNew;mnuMailMessage')200 waittillguiexist ('frmComposeMessage')201 except:202 log ('could not open Mail Editor','cause')203 log ('Check Compose window header boxes','testend')204 raise LdtpExecutionError (0)205 try:206 menucheck ('frmComposeMessage','mnuFromField')207 menucheck ('frmComposeMessage','mnuPost-ToField')208 menucheck ('frmComposeMessage','mnuReply-ToField')209 menucheck ('frmComposeMessage','mnuCcField')210 menucheck ('frmComposeMessage','mnuBccField')211 except:212 log ('error while selecting fields','cause')213 log ('Check Compose window header boxes','testend')214 raise LdtpExecutionError (0)215 try:216 imagecapture('Compose Message','IMAGES/cur_mail.png')217 except:218 log ('Error while capturing image of window','cause')219 log ('Check Compose window header boxes','testend')220 raise LdtpExecutionError (0)221 try:222 if imagecompare (ref_image,'IMAGES/cur_mail.png') < 1.0:223 log ('Header fields ','pass')224 menuuncheck ('frmComposeMessage','mnuFromField')225 menuuncheck ('frmComposeMessage','mnuPost-ToField')226 menuuncheck ('frmComposeMessage','mnuReply-ToField')227 menuuncheck ('frmComposeMessage','mnuCcField')228 menuuncheck ('frmComposeMessage','mnuBccField')229 selectmenuitem ('frmComposeMessage','mnuFile;mnuClose')230 else:231 log ('Header fields ','fail')232 selectmenuitem ('frmComposeMessage','mnuFile;mnuClose')233 raise LdtpExecutionError(0)234 except:235 log ('Header fields do not match','warning')236 log ('Check Compose window header boxes','testend')237 raise LdtpExecutionError (0)238 log ('Check Compose window header boxes','testend')239def add_to_replytofield(replyto,to):240 log ('Add to reply-to field','teststart')241 try:242 selectMailPane()243 window_id='frmEvolution-*'244 subject =['test for reply to']245 body=subject246 selectrowpartialmatch (window_id,'ttblMailFolderTree','Sent')247 waittillguiexist ('frmEvolution-Sent*')248 sent_mail_count = getrowcount (window_id,'ttblMessages')249 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')250 time.sleep (5)251 waittillguiexist ('frmComposeMessage')252 sub = populate_mail_header (to,subject,body)253 menucheck (sub,'mnuReply-ToField')254 settextvalue (sub,'txtReply-To',replyto)255 sendmail (subject)256 click (window_id, 'btnSend/Receive')257 waittillguiexist ('dlgSend&ReceiveMail')258 waittillguinotexist ('dlgSend&ReceiveMail')259 time.sleep (5)260 new_sent_mail_count = getrowcount (window_id,'ttblMessages')261 print 'NEW :: ',new_sent_mail_count, 'OLD :: ',sent_mail_count262 if new_sent_mail_count < sent_mail_count + 1:263 log ('Message not sent','cause')264 raise LdtpExecutionError (0)265 selectrowindex(window_id,'ttblMessages',sent_mail_count)266 selectmenuitem (window_id,'mnuMessage;mnuPostaReply')267 waittillguiexist ('frmRe:*')268 if gettextvalue ('frmRe:*','txtTo') != replyto:269 log ('To field does not have replyto address','cause')270 raise LdtpExecutionError (0)271 menuuncheck (sub,'mnuReply-ToField')272 selectmenuitem ('frmRe:*','mnuFile;mnuClose')273 log ('Reply to Field','pass')274 except:275 log ('Reply to Field','fail')276 log ('Add to reply-to field','testend')277 raise LdtpExecutionError (0)278 log ('Add to reply-to field','testend')279def background_image_test (to,bgimage,ref_image):280 log ('background image','teststart')281 try:282 subject=['background image test']283 body=['background image test']284 selectMailPane()285 window_id='frmEvolution-*'286 time.sleep (2)287 selectrowpartialmatch (window_id,'ttblMailFolderTree','Sent')288 waittillguiexist ('frmEvolution-Sent*')289 sent_mail_count = getrowcount (window_id,'ttblMessages')290 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')291 waittillguiexist ('frmComposeMessage')292 populate_mail_header ([to],subject,body)293 insert_bgimage (bgimage[0])294 sendmail (subject)295 click (window_id, 'btnSend/Receive')296 waittillguiexist ('dlgSend&ReceiveMail')297 waittillguinotexist ('dlgSend&ReceiveMail')298 new_sent_mail_count=getrowcount (window_id,'ttblMessages')299 if new_sent_mail_count < sent_mail_count+1:300 log ('Could not send mail','cause')301 raise LdtpExecutiontionError (0)302 except:303 log ('Mail was not sent','error')304 log ('background image','testend')305 raise LdtpExecutionError (0)306 try:307 if verifymailwithimage ('Sent',sent_mail_count,ref_image) ==1:308 log ('Backgroung Image ','pass')309 else:310 log ('Background Image ','fail')311 raise LdtpExecutionError(0)312 print "outside"313 except:314 log ('Background image test did not pass','error')315 log ('background image','testend')316 raise LdtpExecutionError (0)317 log ('background image','testend')318 319def template_test(to,template,ref_image):320 log ('applying templates','teststart')321 try:322 subject=['template test']323 body=['template test\ntemplate test\ntemplate test\ntemplate test\n']324 selectMailPane()325 window_id='frmEvolution-*'326 selectrowpartialmatch (window_id,'ttblMailFolderTree','Sent')327 waittillguiexist ('frmEvolution-Sent*')328 sent_mail_count = getrowcount (window_id,'ttblMessages')329 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')330 waittillguiexist ('frmComposeMessage')331 populate_mail_header ([to],subject,body)332 apply_template (template)333 sendmail (subject)334 click ('frmEvolution-*', 'btnSend/Receive')335 waittillguiexist ('dlgSend&ReceiveMail')336 waittillguinotexist ('dlgSend&ReceiveMail')337 new_sent_mail_count = getrowcount (window_id,'ttblMessages')338 if new_sent_mail_count < sent_mail_count+1:339 log ('Could not send mail','cause')340 raise LdtpExecutiontionError (0)341 except:342 log ('Mail was not sent','error')343 log ('applying templates','testend')344 raise LdtpExecutionError (0)345 try:346 if verifymailwithimage ('Sent',sent_mail_count,ref_image) ==1:347 log ('Template Test','pass')348 else:349 log ('Template Test','fail')350 raise LdtpExecutionError(0)351 except:352 log ('Template test did not pass','error')353 log ('applying templates','testend')354 raise LdtpExecutionError (0)355 log ('applying templates','testend')356 357def find_and_replace_test(replace,with):358 log ('Find and replace','teststart')359 try:360 text = getmailtext()361 grabfocus ('frmComposeMessage','txt6')362 #selectmenuitem ('frmComposeMessage','mnuEdit;mnuSelectAll')363 selectmenuitem ('frmComposeMessage','mnuEdit;mnuReplace')364 waittillguiexist ('dlgReplace')365 settextvalue ('dlgReplace','txtReplace',replace)366 settextvalue ('dlgReplace','txtWith',with)367 click ( 'dlgReplace','btnFindandReplace')368 waittillguinotexist ('dlgReplace')369 time.sleep (2)370 if guiexist('dlgReplaceconfirmation')==1:371 click ('dlgReplaceconfirmation','btnReplaceAll')372 waittillguinotexist ('dlgReplaceconfirmation')373 print 'TEXT:',text374 print 'NEWTEXT:',getmailtext()375 if getmailtext() == text.replace (replace,with):376 log ('Find and Replace','pass')377 else:378 log ('Find and Replace','fail')379 raise LdtpExecutionError (0)380 except:381 log ('Error in Find and Replace','error')382 log ('Find and replace','testend')383 raise LdtpExecutionError (0)384 log ('Find and replace','testend')385 386def undo_redo_test():387 log ('Undo and Redo','teststart')388 try:389 window_id = 'frmComposeMessage'390 numchild = getpanelchildcount(window_id,'pnlPanelcontainingHTML')391 present_text = getmailtext()392 393 appendtext (window_id,'txt'+str(6+numchild-1),'addedtext')394 added_text = getmailtext()395 396 try:397 selectmenuitem (window_id,'mnuEdit;mnuUndo')398 except:399 log ('Undo Button is not active','cause')400 raise LdtpExecutionError (0)401 undoed_text = getmailtext()402 if undoed_text == present_text:403 log ('Undo','pass')404 else:405 log ('Undo','fail')406 raise LdtpExecutionError (0)407 try:408 selectmenuitem (window_id,'mnuEdit;mnuRedo')409 except:410 log ('Redo Button is not active','cause')411 raise LdtpExecutionError (0)412 redoed_text = getmailtext()413 if redoed_text == added_text :414 log ('Redo','pass')415 else:416 log ('Redo','fail')417 raise LdtpExecutionError (0)418 selectmenuitem (window_id,'mnuEdit;mnuUndo')419 except:420 log ('Undo - Redo test failed','error')421 log ('Undo and Redo','testend')422 raise LdtpExecutionError (0)423 log ('Undo and Redo','testend')424 425def spell_check_test(method):426 """427 method == 0 --> Replace428 method == 1 --> Ignore429 method == 2 --> Skip430 method == 3 --> Add to Dict431 method == 4 --> Close Spell Checker432 method == 5 --> Back Button"""433 log ('Spell Check','teststart')434 try:435 window_id='dlgSpellchecker'436 selectmenuitem ('frmComposeMessage','mnuEdit;mnuCheckSpelling')437 time.sleep (2)438 addwords=[]439 if guiexist ('dlgInformation')==1:440 click ('dlgInformation','btnOK')441 log ('No Spelling mistakes','info')442 elif guiexist (window_id)==1 and method != 4 and method != 5:443 # do the actual replacement/skipping/ignoring here444 while guiexist (window_id)==1:445 remap ('evolution',window_id)446 obj=getobjectlist(window_id)447 for objects in obj:448 if objects.startswith ('tbl'):449 obj=objects450 break451 repl = getrowcount (window_id,obj)452 if method==0:453 if repl>0:454 click (window_id,'btnReplace')455 else:456 log ('No Sugesstion for this word','info')457 elif method==1:458 click (window_id,'btnIgnore')459 elif method==2:460 click (window_id,'btnSkip')461 elif method==3:462 obj=obj[obj.find('\'')+1:]463 obj=obj[:obj.find('\'')]464 addwords.append (obj)465 click (window_id,'btnAddword')466 else:467 log ('Unknown Method given','cause')468 raise LdtpExecutionError (0)469 time.sleep (1)470 #verification of the above code471 if method == 3:472 present_text=gettextvalue ('frmComposeMessage','txt6')473 text=''474 for value in addwords:475 text+=value476 text+=' '477 text=text[:-1]478 settextvalue ('frmComposeMessage','txt6',text)479 #verification for all 3 methods480 481 selectmenuitem ('frmComposeMessage','mnuEdit;mnuCheckSpelling')482 time.sleep (2)483 if guiexist ('dlgInformation')==1 and method in [0,1,3]:484 click ('dlgInformation','btnOK')485 log ('Spell Check','pass')486 elif guiexist (window_id) == 1 and method == 2:487 click (window_id,'btnClose')488 waittillguinotexist (window_id)489 log ('Spell Check','pass')490 else:491 log ('Verification of Spell check failed','cause')492 log ('Spell Check','fail')493 raise LdtpExecutionError (0)494 if method==3:495 settextvalue ('frmComposeMessage','txt6',present_text)496 497 elif guiexist (window_id) == 1 and method == 4:498 click (window_id,'btnClose')499 waittillguinotexist (window_id)500 time.sleep (1)501 if guiexist (window_id) == 0:502 log ('Close button Works','info')503 else:504 log ('Close button Failed','cause')505 raise LdtpExecutionError (0)506 507 elif guiexist (window_id) == 1 and method == 5:508 #enter code for back button here509 obj=getobjectlist(window_id)510 for objects in obj:511 if objects.startswith ('tbl'):512 obj=objects513 break514 obj=obj[obj.find('\'')+1:]515 obj=obj[:obj.find('\'')]516 last_word = obj517 click (window_id,'btnSkip')518 time.sleep (1)519 if guiexist (window_id) == 0:520 log ('Only 1 mistyped occurance','cause')521 raise LdtpExecutionError (0)522 try:523 click (window_id,'btnBack')524 except:525 log ('Could not click Back Button','cause')526 raise LdtpExecutionError (0)527 time.sleep (1)528 obj=getobjectlist(window_id)529 for objects in obj:530 if objects.startswith ('tbl'):531 obj=objects532 break533 obj=obj[obj.find('\'')+1:]534 obj=obj[:obj.find('\'')]535 new_word = obj536 click (window_id,'btnClose')537 waittillguinotexist (window_id)538 if new_word != last_word:539 log ('Back does not lead to last misspelt word','cause')540 except:541 log ('Spell Check','fail')542 log ('Spell Check','testend')543 raise LdtpExecutionError (0)544 log ('Spell Check','pass')545 log ('Spell Check','testend')546def text_formatting_test(to,ref_image):547 log ('text formatting','teststart')548 try:549 subject=['bold,italic,strikethrough test']550 selectMailPane()551 window_id='frmEvolution-*'552 selectrowpartialmatch (window_id,'ttblMailFolderTree','Sent')553 waittillguiexist ('frmEvolution-Sent*')554 sent_mail_count=getrowcount (window_id,'ttblMessages')555 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')556 waittillguiexist ('frmComposeMessage')557 menucheck ('frmComposeMessage','mnuHTML')558 time.sleep (1)559 selectmenuitem ('frmComposeMessage','mnuFormat;mnuStyle;mnuBold')560 settextvalue ('frmComposeMessage','txt6','Hello\n')561 selectmenuitem ('frmComposeMessage','mnuFormat;mnuStyle;mnuItalic')562 settextvalue ('frmComposeMessage','txt7','Hello\n')563 settextvalue ('frmComposeMessage','txt8','Hello\n')564 selectmenuitem ('frmComposeMessage','mnuFormat;mnuStyle;mnuStrikethrough')565 settextvalue ('frmComposeMessage','txt9','Hello\n')566 settextvalue ('frmComposeMessage','txt10','Hello')567 selectmenuitem ('frmComposeMessage','mnuFormat;mnuAlignment;mnuCenter')568 settextvalue ('frmComposeMessage','txt10','Hello\n')569 settextvalue ('frmComposeMessage','txt11','Hello')570 selectmenuitem ('frmComposeMessage','mnuFormat;mnuAlignment;mnuRight')571 settextvalue ('frmComposeMessage','txt11','Hello\n')572 populate_mail_header ([to],subject)573 sendmail (subject)574 click ('frmEvolution-*', 'btnSend/Receive')575 waittillguiexist ('dlgSend&ReceiveMail')576 waittillguinotexist ('dlgSend&ReceiveMail')577 time.sleep (5)578 new_sent_mail_count = getrowcount (window_id,'ttblMessages')579 if new_sent_mail_count < sent_mail_count+1:580 log ('Could not send mail','cause')581 raise LdtpExecutiontionError (0)582 except:583 log ('Mail was not sent','error')584 log ('text formatting','testend')585 raise LdtpExecutionError (0)586 try:587 if verifymailwithimage ('Sent',sent_mail_count,ref_image, subject) ==1:588 log ('Text Formatting ','pass')589 else:590 log ('Text Formatting ','fail')591 raise LdtpExecutionError(0)592 except:593 log ('Text formatting test did not pass','error')594 log ('text formatting','testend')595 raise LdtpExecutionError (0)596 log ('text formatting','testend')597 598def lists_test(to,ref_image):599 log ('numbered,alphabetic,bulleted lists','teststart')600 try:601 subject=['Compose editor List test']602 selectMailPane()603 window_id='frmEvolution-*'604 selectrowpartialmatch (window_id,'ttblMailFolderTree','Sent')605 waittillguiexist ('frmEvolution-Sent*')606 sent_mail_count=getrowcount (window_id,'ttblMessages')607 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')608 waittillguiexist ('frmComposeMessage')609 menucheck ('frmComposeMessage','mnuHTML')610 time.sleep (1)611 selectmenuitem ('frmComposeMessage','mnuFormat;mnuHeading;mnuBulletedList')612 settextvalue ('frmComposeMessage','txt6','Hello\nHello\nHello\n')613 selectmenuitem ('frmComposeMessage','mnuFormat;mnuHeading;mnuNumberedList')614 settextvalue ('frmComposeMessage','txt9','Hello\nHello\nHello\n')615 selectmenuitem ('frmComposeMessage','mnuFormat;mnuHeading;mnuAlphabeticalList')616 settextvalue ('frmComposeMessage','txt12','Hello\nHello\nHello\n')617 selectmenuitem ('frmComposeMessage','mnuFormat;mnuHeading;mnuRomanNumeralList')618 settextvalue ('frmComposeMessage','txt15','Hello\nHello\nHello\n')619 populate_mail_header ([to],subject)620 sendmail (subject)621 click ('frmEvolution-*', 'btnSend/Receive')622 waittillguiexist ('dlgSend&ReceiveMail') 623 waittillguinotexist ('dlgSend&ReceiveMail')624 time.sleep (5)625 new_sent_mail_count=getrowcount (window_id,'ttblMessages')626 if new_sent_mail_count < sent_mail_count+1:627 log ('Could not send mail','cause')628 raise LdtpExecutiontionError (0)629 except:630 log ('Mail was not sent','error')631 log ('numbered,alphabetic,bulleted lists','testend')632 raise LdtpExecutionError (0)633 try:634 if verifymailwithimage ('Sent',sent_mail_count,ref_image, subject) == 1:635 log ('Text Formatting ','pass')636 else:637 log ('Text Formatting ','fail')638 raise LdtpExecutionError(0)639 #undoremap ('evolution',window_id)640 except:641 log ('Text formatting test did not pass','error')642 log ('numbered,alphabetic,bulleted lists','testend')643 raise LdtpExecutionError (0)644 log ('numbered,alphabetic,bulleted lists','testend')645 646def fonts_test(to,ref_image):647 log ('Fonts Test','teststart')648 try:649 subject=['Compose editor Fonts test']650 selectMailPane()651 window_id='frmEvolution-*'652 selectrowpartialmatch (window_id,'ttblMailFolderTree','Sent')653 waittillguiexist ('frmEvolution-Sent*')654 sent_mail_count=getrowcount (window_id,'ttblMessages')655 selectmenuitem (window_id,'mnuFile;mnuNew;mnuMailMessage')656 waittillguiexist ('frmComposeMessage')657 menucheck ('frmComposeMessage','mnuHTML')658 time.sleep (1)659 settextvalue ('frmComposeMessage','txt6','Hello\n')660 selectmenuitem ('frmComposeMessage','mnuFormat;mnuFontSize;mnu+1')661 settextvalue ('frmComposeMessage','txt7','Hello\n')662 selectmenuitem ('frmComposeMessage','mnuFormat;mnuFontSize;mnu+2')663 settextvalue ('frmComposeMessage','txt8','Hello\n')664 selectmenuitem ('frmComposeMessage','mnuFormat;mnuFontSize;mnu+3')665 settextvalue ('frmComposeMessage','txt9','Hello\n')666 populate_mail_header ([to],subject)667 sendmail (subject)668 click ('frmEvolution-*', 'btnSend/Receive')669 waittillguiexist ('dlgSend&ReceiveMail')670 waittillguinotexist ('dlgSend&ReceiveMail')671 time.sleep (5)672 new_sent_mail_count=getrowcount (window_id,'ttblMessages')673 if new_sent_mail_count < sent_mail_count+1:674 log ('Could not send mail','cause')675 raise LdtpExecutiontionError (0)676 except:677 log ('Mail was not sent','error')678 log ('Fonts Test','testend')679 raise LdtpExecutionError (0)680 try:681 if verifymailwithimage ('Sent',sent_mail_count,ref_image, subject) ==1:682 log ('Fonts in compose editor ','pass')683 else:684 log ('Fonts in compose editor ','fail')685 raise LdtpExecutionError(0)686 except:687 log ('Fonts in compose editor did not pass','error')688 log ('Fonts Test','testend')689 raise LdtpExecutionError (0)...
task.py
Source:task.py
1from ldtp import *2from ldtputils import *3from contact import *4from evoutils import *5from evoutils.calendar import get_date_format6def gettaskdata(datafilename):7 data_object = LdtpDataFileParser (datafilename)8 Group = data_object.gettagvalue ('group')9 Summary = data_object.gettagvalue ('summary')10 Desc = data_object.gettagvalue ('desc')11 Start_date = data_object.gettagvalue ('start_date')12 Start_time = data_object.gettagvalue ('start_time')13 End_date = data_object.gettagvalue ('end_date')14 End_time = data_object.gettagvalue ('end_time')15 Time_zone = data_object.gettagvalue ('time_zone')16 Categories = data_object.gettagvalue ('Categories')17 return Group, Summary, Desc, Start_date, Start_time, End_date, End_time, Time_zone, Categories18def fill_task (Group, Summary, Desc, Start_date, Start_time, End_date, End_time, Time_zone, Categories, window_id = 'frmTask-*'):19 try:20# for obj in getobjectlist ('frmTask-*'):21# if obj.startswith ('cbo'):22# grp_obj = obj23# break24 grp_obj = 'cboPersonal'25 if Group:26 comboselect (window_id, grp_obj, Group[0])27 time.sleep(3)28 settextvalue (window_id, 'txtSummary', Summary[0])29 if Desc:30 settextvalue (window_id, 'txtDescription', Desc[0])31 if Start_date:32 settextvalue (window_id, 'txtDate1',Start_date[0])33 if End_date:34 settextvalue (window_id, 'txtDate',End_date[0])35 if Start_time:36 settextvalue (window_id, 'txt8',Start_time[0])37 if End_time:38 settextvalue (window_id, 'txt6',End_time[0])39 #if Time_zone:40 # menucheck (window_id,'mnuView;mnuTimeZone')41 # settextvalue (window_id, 'txt4',Time_zone[0])42 #else:43 menuuncheck (window_id,'mnuView;mnuTimeZone')44 if Categories:45 menucheck (window_id,'mnuView;mnuCategories')46 settextvalue (window_id, 'txt0',Categories[0])47 else:48 menuuncheck (window_id,'mnuView;mnuCategories')49 log('User Details entered','info')50 except:51 print 'Error in entering the values'52 log('Error in entering the values','error')53 raise LdtpExecutionError(0)54 55def verify_task (Group, Summary, Desc, Start_date, Start_time, End_date,56 End_time, Time_zone, Categories, windowname='frmTask-*'):57 try:58 selectmenuitem ('frmEvolution-Tasks','mnuFile;mnuOpenTask');59 if waittillguiexist (windowname) == 0:60 log ('Unable to open Task','cause')61 raise LdtpExecutionError (0)62 63 if Desc and verifysettext (windowname, 'txtDescription', Desc[0]) == 0:64 log ('Description not set','cause')65 raise LdtpExecutionError (0)66 67 # if Start_date and verifysettext (windowname, 'txtDate1',get_date_format(Start_date[0])) == 0:68 # log ('Start Date set incorrectly','cause')69 # raise LdtpExecutionError (0)70 # if End_date and verifysettext (windowname, 'txtDate',get_date_format(End_date[0])) == 0:71 # log ('End date set incorrectly','cause')72 # raise LdtpExecutionError (0)73 74 if Start_time and verifysettext (windowname, 'txt8',Start_time[0]) == 0:75 log ('Start time set incorrectly','cause')76 raise LdtpExecutionError (0)77 78 if End_time and verifysettext (windowname, 'txt6',End_time[0]) == 0:79 log ('End time set incorrectly','cause')80 raise LdtpExecutionError (0)81 82 # if Time_zone and verifysettext (windowname, 'txt4',Time_zone[0]) == 0:83 # log ('Time Zone set incorrecly','cause')84 # raise LdtpExecutionError (0)85 86 if Categories and verifysettext (windowname, 'txt0',Categories[0]) == 0:87 log ('Categories set incorrectly','cause')88 raise LdtpExecutionError (0)89 except:90 log ('Task Verification failed','error')91 raise LdtpExecutionError (0)92 93def read_assignedtask_data (datafilename):94 try:95 data_object = LdtpDataFileParser (datafilename)96 index = 197 attendee = []98 email = []99 while True:100 att = data_object.gettagvalue ('attendee'+str(index))101 em = data_object.gettagvalue ('email'+str(index))102 103 if att == [] or em == []:104 break105 attendee.append (att[0])106 email.append (em[0])107 index += 1108 addr_book = data_object.gettagvalue ('addr_book')109 Group = data_object.gettagvalue ('group')110 Summary = data_object.gettagvalue ('summary')111 Desc = data_object.gettagvalue ('Desc')112 Start_date = data_object.gettagvalue ('start_date')113 Start_time = data_object.gettagvalue ('start_time')114 End_date = data_object.gettagvalue ('due_date')115 End_time = data_object.gettagvalue ('due_time')116 Time_zone = data_object.gettagvalue ('time_zone')117 Categories = data_object.gettagvalue ('Categories')118 print Group, Summary, Desc, Start_date, Start_time, \119 End_date, End_time, Time_zone, Categories, attendee, email120 return Group, Summary, Desc, Start_date, Start_time, \121 End_date, End_time, Time_zone, Categories, addr_book, attendee, email122 except:123 log('Unable to read the user data or data file missing','error')...
checkmenuitem.py
Source:checkmenuitem.py
1#!/usr/bin/env python2#3# Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp4#5# Description:6# This set of test scripts will test the LDTP framework for correct7# functioning of its APIs. This is a Regression Suite.8#9# Author:10# Prashanth Mohan <prashmohan@gmail.com>11#12#13# This test script is free software; you can redistribute it and/or14# modify it under the terms of the GNU Library General Public15# License as published by the Free Software Foundation; either16# version 2 of the License, or (at your option) any later version.17#18# This library is distributed in the hope that it will be useful,19# but WITHOUT ANY WARRANTY; without even the implied warranty of20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU21# Library General Public License for more details.22#23# You should have received a copy of the GNU Library General Public24# License along with this library; if not, write to the25# Free Software Foundation, Inc., 59 Temple Place - Suite 330,26# Boston, MA 02111-1307, USA.27#28from regression import *29import random, os30try:31 check_open('gedit')32except:33 raise34log ('menucheck','teststart')35try:36 if menucheck ('*gedit','mnuView;mnuStatusbar') != 1:37 log ('Undefined return value','cause')38 raise LdtpExecutionError (str (traceback.format_exc ()))39 #time.sleep (2)40 if verifymenucheck ('*gedit','mnuView;mnuStatusbar') != 1:41 log ('verifymenucheck - Check Menu item not checked','cause')42 raise LdtpExecutionError (str (traceback.format_exc ()))43 if verifymenuuncheck ('*gedit','mnuView;mnuStatusbar') != 0:44 log ('verifymenuuncheck - Check Menu item not checked','cause')45 raise LdtpExecutionError (str (traceback.format_exc ()))46except:47 testfail ('menucheck')48 raise LdtpExecutionError (str (traceback.format_exc ()))49testpass ('menucheck')50log ('menuuncheck','teststart')51try:52 if menuuncheck ('*gedit','mnuView;mnuStatusbar') != 1:53 log ('Undefined return value','cause')54 raise LdtpExecutionError (str (traceback.format_exc ()))55 #time.sleep (2)56 if verifymenuuncheck ('*gedit','mnuView;mnuStatusbar') != 1:57 log ('verifymenuuncheck - Check Menu item not checked','cause')58 raise LdtpExecutionError (str (traceback.format_exc ()))59 if verifymenucheck ('*gedit','mnuView;mnuStatusbar') != 0:60 log ('verifymenucheck - Check Menu item not checked','cause')61 raise LdtpExecutionError (str (traceback.format_exc ()))62except:63 testfail ('menuuncheck')64 raise LdtpExecutionError (str (traceback.format_exc ()))65testpass ('menuuncheck')66log ('selectmenuitem on checkmenu','teststart')67try:68 curstate = verifymenucheck ('*gedit','mnuView;mnuStatusbar')69 if selectmenuitem ('*gedit','mnuView;mnuStatusbar') != 1:70 log ('Undefined return value','cause')71 raise LdtpExecutionError (str (traceback.format_exc ()))72 #time.sleep (2)73 if verifymenucheck ('*gedit','mnuView;mnuStatusbar') == curstate:74 log ('verifymenucheck - Check Menu item not inverted','cause')75 raise LdtpExecutionError (str (traceback.format_exc ()))76 curstate = verifymenucheck ('*gedit','mnuView;mnuStatusbar')77 if selectmenuitem ('*gedit','mnuView;mnuStatusbar') != 1:78 log ('Undefined return value','cause')79 raise LdtpExecutionError (str (traceback.format_exc ()))80 #time.sleep (2)81 if verifymenucheck ('*gedit','mnuView;mnuStatusbar') == curstate:82 log ('verifymenucheck - Check Menu item not inverted 2nd time','cause')83 raise LdtpExecutionError (str (traceback.format_exc ()))84except:85 testfail ('selectmenuitem on checkmenu')86 raise LdtpExecutionError (str (traceback.format_exc ()))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!