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



Sunday, September 16, 2012

Train availability status automated by sikuli tool



Scenario :
View train availability between two station in live website.


Feature in script:

                      This script is used for password encryption when you enter in input box and tool tip used to highlight some area for user attraction then inside find region used to click particular area.

Example :
Below, code line is give to understand for above feature.

# Password encription
import javax.swing.JOptionPane as JOP
import javax.swing.JPasswordField as JPF
pwdF = JPF()

IN = input("Enter a user name")
type("Username-2.png", IN)
JOP.showConfirmDialog(None, pwdF,
        "Please enter Password",
        JOP.OK_CANCEL_OPTION)
passwd = pwdF.getText()
type("Password-2.png", passwd + Key.ENTER)
click("1347731963166.png"),

# Inside find

Er = find("12631NELLAIE.png").inside().find("1347731427595.png").right(38)
click(Er)

# Tooltip and highlight
from guide import *
text("TrainDetails.png", "Train Details")
show(2)
m = find("TrainName-1.png")
m.highlight(2)
tooltip("NELLAIEXPRES.png","NELLAI EXPRESS")
show(5)


Demo view in Video :


Youtube links :http://www.youtube.com/watch?v=8ZyE_-rGI6s&feature=plcp


Note : I have given above video for easy to understand and this is taken When the script run on sikuli IDE