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.