Wednesday, September 26, 2012

Multiple field is checking When restarting an application with exception and logging in sikuli


Description:
This script is checking multiple field When user changing an Field after reopen an application. Here, I have choose Pathway Configuration Tool and It code contain Exception handling when field failed then popup message box will invoke an error line. Those error line is inserted in log file in temp directory.

Example code:

# Exception handling
import sys, re, traceback, os
setThrowException(True)
try:
    openPH()
    PHAction()
    openPH_two()
    click("TestI.png"), click("PrDDerties.png"), wait("PaeSize.png")
  
    Page_Size = find("HalfIetter.png").highlight(2)
    Justified = find("JustifiedYes.png").inside().find("Yes-1.png").highlight(2)
    Fixed_Line_Height = find("IUIFixedLine.png").inside().find("1348489050687.png").highlight(2)
    Running_Header = find("EveryPage-1.png").highlight(2)
    Page_Number = find("PaueNumbers.png").inside().find("ButtumLeftMa.png").highlight(2)

except:
    err = str(sys.exc_info()[1])
    errs = err.split()[4]
    pth = sys.argv[0]
    ful_err = traceback.format_exc()
    vrie = ful_err.split()[11]
    PTR = 'This ' + str(vrie) + ' field is failed. So, Please find a picture in ' + str(pth) + str(errs) + ' path.'
    print PTR
    logger.error(PTR) 
    popup(PTR)

 # Creating Log file

def logdirs():
    global dirname
    dirname = "C:\\WINDOWS\\TEMP\\Sikuli_logs\\"
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    else:
#      os.remove(dirname)
        print "Directory is already created..."
import logging, os
logdirs()
logger = logging.getLogger('myapp')
hdlr = logging.FileHandler('C:\\WINDOWS\\TEMP\\Sikuli_logs\\Pathway.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.WARNING)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)

Demo view in video:

Youtube links : https://www.youtube.com/watch?v=e-wwPrDcoR8



No comments:

Post a Comment