0805-SPAG.sikuli\0805-SPAG.sikuli

(Download this script)
from __future__ import division
myApp = App("0000003458763848")

def init():
    Device_0000003458763848 = AndroidDevice.getDevice("0000003458763848")
    Device_0000003458763848.keyDown(  3)
    Device_0000003458763848.keyUp(  3)
    Device_0000003458763848.sleep(  2189,    4)

def start(s):
    print s
    global round_all
    round_all+=1

def end(s):
    global round_now
    round_now+=1
    print s

def contact():
    init()
    start( "Start Test 1 contact")
    Device_0000003458763848 = AndroidDevice.getDevice("0000003458763848")
    Device_0000003458763848.sleep(  2132,    1)
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 186, 633)
    Device_0000003458763848.pointer(    66,   ACTION_UP, 186, 633)
    Device_0000003458763848.sleep( 5145,   30)
    Device_0000003458763848.verify("com.android.contacts", "com.android.contacts.DialtactsActivity")
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 181, 214)
    Device_0000003458763848.pointer(    68,   ACTION_UP, 181, 214)
    Device_0000003458763848.sleep(  5725,   57)
    Device_0000003458763848.verify("com.android.contacts", "com.android.contacts.ContactsListActivity")
    if not exists():
        raise Exception("test failed")
    end( "Test 1 contact Success!")


def Installapplication():
    start("Start Test 2 Installapplication")
    run("adb uninstall com.pinterest")
    init()
    Device_0000003458763848 = AndroidDevice.getDevice("0000003458763848")
    Device_0000003458763848.sleep(  3474,  289)
    Device_0000003458763848.verify("com.android.launcher2", "com.android.launcher2.Launcher")
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 420, 637)
    Device_0000003458763848.pointer(    84,   ACTION_UP, 420, 637)
    Device_0000003458763848.sleep( 5844,    9)
    Device_0000003458763848.verify("com.android.vending", "com.android.vending.AssetBrowserActivity")
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 237, 272)
    Device_0000003458763848.pointer(    69,   ACTION_UP, 237, 272)
    Device_0000003458763848.sleep( 11535,  283)
    Device_0000003458763848.verify("com.android.vending", "android.view.View")
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 401, 173)
    Device_0000003458763848.pointer(    96,   ACTION_UP, 401, 173)
    Device_0000003458763848.sleep(  3826,   90)
    Device_0000003458763848.verify("com.android.vending", "com.google.android.finsky.activities.PurchaseDialog")
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 232, 298)
    Device_0000003458763848.pointer(   110,   ACTION_UP, 232, 298)
    Device_0000003458763848.sleep( 55464,  450)
    Device_0000003458763848.verify("com.android.vending", "com.android.vending.AssetBrowserActivity")
    Device_0000003458763848.pointer(     0, ACTION_DOWN, 129, 236)
    Device_0000003458763848.pointer(    95,   ACTION_UP, 129, 236)
    Device_0000003458763848.sleep( 5000,  0)
    result=0
    if exists():
        result=1
    Device_0000003458763848 = AndroidDevice.getDevice("0000003458763848")
    Device_0000003458763848.sleep(  3403,  119)
    Device_0000003458763848.verify("com.android.vending", "android.widget.Button")
    Device_0000003458763848.keyDown(  4)
    Device_0000003458763848.keyUp(  4)
    Device_0000003458763848.sleep(  4633,   58)
    Device_0000003458763848.verify("com.android.vending", "com.android.vending.AssetBrowserActivity")
    Device_0000003458763848.keyDown(  4)
    Device_0000003458763848.keyUp(  4)
    if result ==0:
        raise Exception("test failed")
    round_now+=1
    end("Test 2 Installapplication Success!")


def takepic():
    start("Start Test 3 takepic")
    end("Test 3 takepic Success!")


def ShootVideo():
    start("Start Test 4 ShootVideo ")
    end("Test 4 ShootVideo Success!")



def gmap():
    start("Start Test 5 gmap")
    end("Test 5 gmap Success!")



import os
import shutil
from time import strftime
CPU=0
IO=""
round_all=0
round_now=0
BASEDIR = os.path.normpath("d:/Experiment/0805-SPAG.sikuli")
#BASEDIR = os.path.normpath(u"/home/jcppkkk/Dropbox/HighSpeedLab/論文資料/Experiment/0805-SPAG.sikuli")
logpath = os.path.join(BASEDIR, 'log%d%s.csv'%(CPU, IO))
log2path = os.path.join(BASEDIR, 'logp%d%s.csv'%(CPU, IO))
def log(str):
    logfile = open(logpath, "a")
    logfile.write(str)
    logfile.close()
def log2():
    global round_all
    global round_now
    logfile = open(log2path, "a")
    logfile.write('%f,' %(round_now/round_all))
    logfile.close()
for x in range(100):
    try:
        #contact()
        Installapplication()
        #takepic()
        #ShootVideo()
        #gmap()
    except (Exception, java.lang.Exception), inst:
        print "Test", round_now, "Failed." , inst
        log('0,')
        log2( )
        sleep(5)
        (a,b,c) = str(inst).partition(".")
        filepath = os.path.join(BASEDIR, 'errors', 'R%d.%s.%s.png'%(round_now, strftime("%m%d.%H%M%S"), a))
        print filepath
        myApp.focus()
        shutil.move(capture(myApp.window()), filepath)
    finally:
        log('1,')
        log2()
log('\n')
log2('\n')