Android monkeyrunner - check if screen contains an image or specific color -
i have android app wanted automate/stress-test. made image-based automation script in scar divi , run against app installed on bluestacks. want change genymotion, because bluestacks slow.
i have environment set (genymotion+image app +adb installed , working). rewrited script in python , used in monkeyrunner, but...
besides sending gestures, clicks , waits, missing image recognition functionality. found out can compare 2 screen shots imagemagic, that's not need.
i need check whether button, or @ least if specific color on screen. point me right direction this?
i'd grateful examples :(
monkeyrunner indeed offer pretty decent image based test methods. show below how take sub-image displayed screen of device. can save sub-image and/or compare reference image
first need take screenshot of current screen of device
# take screenshot image = device.takesnapshot()
then can take sub-image. example, sub-image button on screen verify button exists on screen. able can use method below. tuple (0, 0, 50, 100) below example. should provide own. (x, y, w, h) of desired sub-image.
# take sub-image sub_image = image.getsubimage((0, 0, 50, 100))
after step, can save image and/or compare reference image. compare reference image can shown below:
# load reference image comparison reference = monkeyimage.loadfromfile(path_to_reference_image) if not sub_image.sameas(reference, 0.9): print "images not match!" #
0.9 acceptance level. if 2 images match 90% or above, considered passed
hope helps. let me know if encounter problems!
Comments
Post a Comment