Thursday, March 16, 2017

Exception Handling(Asserts):

Exception Handling:
find operations (explicit and implicit) when not successful raise an Exception FindFailed, that
will stop the script immediately.

For more sophisticated concepts, you can implement your own exception handling using the standard Python construct try: ... except: ... .


AssertionError:


 When it encounters an assert statement, Python evaluates the accompanying expression, which is hopefully true. If the expression is false, Python raises an AssertionError exception.

Sample Code:
import sys, os

def TestOne():
    App.focus("fieldworks")
    find("1477810460138.png").highlight(2)
    find(Pattern("1477810513968.png").targetOffset(28,0)).right(250).click()
    type("Testing")
    wait(2)
    assert exists("Testing.png")
    
try:
    TestOne()
except (AssertionError, FindFailed) as e:
    #print str(sys.exc_info())

    print "Print Error stack lines... " + str(e)



Monday, March 13, 2017

Region: Explanation and Examples(rectangular pixel area on a screen)


A Region is a rectangular area on a Screen.
A Region does not know anything about it’s visual content (windows, pictures, graphics, text, ...). It only knows the position on the screen and its dimension.

New Regions can be created in various ways:

• specify their position and dimension
• extend a given Region in all directions (expand or shrink)
• based on adjacent rectangles up to the bounds of the screen horizontally or vertically.
• based on their corners

class Region

Region(x, y, w, h)
Region(region)
Region(Rectangle)
Create a region object
Parameters
• x – x position of top left corner
• y – y position of top left corner.
• w – width of the region.
• h – height of the region.
• region – an existing Region object.
• rectangle – an existing object of class java.awt.Rectangle
Returns a new Region object.


Extending Region:


These methods return a new region object, that is based on the specified region (sometimes called spatial operators). The range parameter, if given as positive integer number, restricts the dimension of the new region (width and/or height respectively) to that value.


nearby([range ])

The new region is defined by extending (>0) or shrinking (<0) the current region’s dimensions in all
directions by range number of pixels. The center of the new region remains the same.
Parameters range – an integer indicating the number of pixels or the current default if omitted.
Returns a new Region object
above([range ])
below([range ])
left([range ])
right([range ])
Returns a new Region that is defined with respect to the given region:
•above: new bottom edge next pixel row above given region’s top edge
•below: new top edge next pixel row below given region’s bottom edge
•left: new right edge next pixel column left of given region’s left edge
•right: new left edge next pixel column right of given region’s right edge
Parameters range – a positive integer defining the new dimension aspect (width or height)
Returns a new Region object.

Example 1:

Example 1 Code:
FindReg3 = find("NewEntryBox.png") 
Below = FindReg3.below()
Right = FindReg3.right()
display = Region(Below.getX(), Right.getY(), Right.getW(), Below.getH())
print display
display.highlight(3) # This region result will show in rectangle in red color.

print Below.getX() # 87
print Right.getY() # 111
print Right.getW() # 1186
print Below.getH() # 642

Example 2: 
Example 2 Code:
FindReg7 = find(Pattern("HelpButton.png").similar(0.80))
Above = FindReg7.above()
Left = FindReg7.left()

display2 = Region(Left.getX(), Above.getY(), Left.getW(), Above.getH())
print display2
display2.highlight(3) # This region result will show in rectangle in red color.

print Left.getX() #0
print Above.getY() #0
print Left.getW() #564
print Above.getH() #639

Example 3:
Example 3 Code:
FindReg8 = find("EntryBlueBar.png") 
Below = FindReg8.below()
Right = FindReg8.right()
display = Region(Below.getX(), Right.getY(), Below.getW()+Right.getW(), Below.getH()+Right.getH())
print display
display.highlight(3) # This region result will show in rectangle in red color.

print Below.getX() # 545
print Right.getY() # 103
print Below.getW() # 84
print Right.getW() # 737
print Below.getH() # 641
print Right.getH() # 24


Example for Find Nearby:
find("1477685939643.png").nearby(50).find("1477685955906.png").highlight(3)

Example for Find Left  # test done in docs.seleniumhq.org

find("1477684805339.png").left(350).find("1477684837599.png").highlight(3)







Example for Find Below # test done in docs.seleniumhq.org/download

find("Languae.png").below(150).find("Java-1.png").right(500).find("Download.png").highlight(3)




Example for Find Above # test done in docs.seleniumhq.org/download

find("Languae.png").below(250).find("1477685671961.png").right(700).find("1477685540801.png").above(150).find("1477685743514.png").highlight(3)






Friday, March 10, 2017

Find Operation and explanation about the "Find" print message

Find:

Find a given image within monitor screen. If more than one similar picture find in the screen, "find" will work with most similiar picture. Let me explain "Pattern" Command

Class Pattern:

A pattern is used, to associate an image file with additional attributes used in find operations and when acting on a match object.
find(Pattern("India.png").similar(0.80).targetOffset(10,2))

Similarity:

Return a new Pattern object containing the same attributes (image, click point) with the minimum similarity set to the specified value.The value should be between 0 and 1. The deafult value in 0.70 E.g. 0.70 or 0.80

TargetOffset(dx, dy):

By default, the click point is the center of the found match. By setting the target offset, it is possible to specify a click point other than the center. dx and dy will be used to calculate the position relative to the center. E.g. targetOffset(10,2)

Highlight (seconds):

This feature will help to highlight in rectangle with red color if picture find on screen.





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

Monday, April 9, 2012

Sikuli scripts handled When crash on Fieldworks.


Scenario : Sikuli scripts handled When crash on Fieldworks.

Explanation :
I automated, When Crash is appears on flex using sikuli script(E.g Particular scenario). Its mean, If suppose crash appears while testing on flex then screenshot and error lines are saved on appropriate file path.

E.g

import os
ERR = find("Anerrorhasoc-1.png").below(450)
ERR.click("1332009700327-1.png")
click("iewDetalIs-1.png"), sleep(5)
assertNotExist("Anerrorhasoc.png")

#def Test_D(self): # Taking screenshot in MSpaint
wait(1)
type(Key.PRINTSCREEN)
wait(1)
openApp("mspaint.exe")
wait(3)
type("v",KEY_CTRL)
type("s",KEY_CTRL), wait(0.40)
type(Key.BACKSPACE), wait(0.40)
type("Filename-1.png", "Text"), click("1332053249614.png"), wait(0.30)
closeApp("Text - Paint")
click("1333175341121.png")

#def Test_C(self): # Taking error line
dir = r"F:\Office\Script\sikulitestfiles"
fname = "Text.txt"
os.popen("start /D %s %s"%(dir,fname))
wait(5)
type("v",KEY_CTRL)
type("s",KEY_CTRL)
closeApp("Text - Notepad")



Note : Please watch below video to understand easy way.


Thursday, April 5, 2012

Read lines from *.txt file(Notepad) and pasted into an application using sikuli

Scenario : Creating new text on interlinear pane and insert a add approve analysis in word analysis pane.

Explanation :
This scenario is created for mainly to read lines from *.txt file and pasted into an application using python syntax. I have added this script into sikuli script and given below for sample code to understand.

Example :

theFile = file(r"F:\Office\Script\sikulitestfiles\Text.txt")
for line in theFile:
print line # print line in sikuli
click("1330680438453.png"), type(line)
theFile.close()

Full Code in picture view :


Demo view in Video :

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