コード例 #1
0
def ScreenOnOff(count):
    d.screen.on()
    time.sleep(3)
    d.press.home()
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.right()
    d.press.right()
    d.press.right()
    d.press.right()
    d.press.right()
    d.press.right()
    d.press.right()
    if d(text='Power').exists == False:
        print "Failed"
        d.screenshot('snapshot_%d.png' % count)
    d.press.enter()
    time.sleep(3)
    d.press.right()
    d.press.enter()

    time.sleep(12)
    print "cycles %d" % count
コード例 #2
0
def check_wifi(count):
    cmd = 'adb shell ifconfig wlan0'
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)

    s, err = p.communicate()
    #print s
    #print type(s)
    pattern = re.compile('inet addr')
    r = pattern.findall(s)
    #print r
    if len(r) == 0:
        print "wifi disconnect"
        get_log(count)
        d.screen.on()
        d.press.home()
        d.press.down()
        d.press.down()
        d.press.down()
        d.press.down()
        d.press.down()
        d.press.right()
        d.press.right()
        d.press.enter()
        time.sleep(2)
        d.press.enter()
        d.screenshot('wifi_%d.png' % count)
        return 0
コード例 #3
0
ファイル: taiji.py プロジェクト: liushui312/uiautomator
def runtest(serialno, loop):
    print "liu: in runtest"
    if serialno:
        print "liu: in serialno"
        from uiautomator import Device
        d = Device(serialno)
    else:
        print "liu: in else"
        from uiautomator import device as d

    print "总共 %d 次循环" %loop

    for i in range(1, loop+1):
        print "第 %d 次循环" %i
        d.screen.on()
        d.press.home()
        d(description="Apps").click()
        d(text="Basemark ES2 Taiji Free").click()
        time.sleep(2)

        if d(text="Agree").exists:
            d(text="Agree").click()

        d(text="Run Benchmark").click()
        while not d(text="FRAMES PER SECOND").exists:
            time.sleep(2)
        else:
            d.screenshot("%s/screenshot/%d_taiji_%s.png"\
                    %(sys.path[0], i, now.strftime(ISOFORMAT)))

        d.press.home()
        i += 1

    print "***** test end ********"
コード例 #4
0
def attack_boss(pos):
    click_range(pos[0], pos[1])
    if not wait_for_end():
        warning()
        return
    time.sleep(2)
    box_time = 0
    while True:
        d.screenshot(pic_name)
        if judge.is_exploration_home_page(pic_name):
            print('quit to exploration home page')
            break
        print('find box')
        pos = judge.get_boss_box_pos(pic_name)
        if not pos:
            print('no box', box_time)
            if box_time < 5:
                time.sleep(1)
                box_time += 1
                continue
            break
        print('get box')
        click_range(pos[0], pos[1])
        time.sleep(1)
        print('close reward')
        click_range(1200, 175)
    return True
コード例 #5
0
def wifiStatus(ap, ap2, passwd):
    time.sleep(5)
    print "Checking status"
    if d(text="Wi-Fi password not valid").exists:
        print "password not valid"
        d.screenshot("password_not_valid.png")
        wifi_connect(0, ap, passwd, 40)
        wifi_connect(0, ap2, passwd, 40)
        time.sleep(2)
        d.press.up()
        time.sleep(2)
        d.press.up()
        time.sleep(2)
        d.press.up()
        time.sleep(2)
        d.press.up()
        time.sleep(2)
        d.press.up()
        time.sleep(5)
    elif d(text="Hide password").exists:
        print "Enter password"
        d.screenshot("Enter_password_.png")
        os.popen('adb shell input text asdfghjkl')
        #        d.press.enter()
        time.sleep(5)
    elif d(text="Couldn't connect to").exists:
        print "Coundn't connect ..."
        d.press.back()
        d.press.back()
    else:
        print "Connected to AP"
コード例 #6
0
def traverse(pageNum, resultFolder):
    current = d.dump('temp.xml', compressed=False)
    thirdPartyComponentList = {}
    parser = xml.sax.make_parser()
    parser.setFeature(xml.sax.handler.feature_namespaces, 0)
    Handler = DumpFileHandler(thirdPartyComponentList)
    parser.setContentHandler(Handler)
    parser.parse('temp.xml')
    thirdPartyComponentList = Handler.thirdPartyComponentList

    if len(thirdPartyComponentList) > 0:
        d.screenshot(os.path.join(resultFolder, str(pageNum) + ".png"))
        d.dump(os.path.join(resultFolder,
                            str(pageNum) + ".xml"),
               compressed=False)
        writePath = os.path.join(resultFolder, str(pageNum) + '.txt')
        writeFile = open(writePath, 'w')
        for component in thirdPartyComponentList:
            writeFile.write(component + '\n')
        writeFile.close()

    componentList = {}
    UISelectorList = d(packageName=packageName, clickable=True)
    for component in UISelectorList:
        componentList[component] = 'clickable'
    for component in componentList.keys():
        if componentList[component] == 'clickable' and component.exists:
            print(component.info)
            component.click()
            new = d.dump('temp.xml', compressed=False)
            print(current == new)
            if (current != new):
                print('here')
                traverse(pageNum + 1, resultFolder)
    d.press.back()
コード例 #7
0
ファイル: ui_deep.py プロジェクト: majestyhao/uidroid
def check_clicked(clicked_list):
    global back_counter
    global dev
    #os.system('adb start-server')
    #from uiautomator import device as dev
    #time.sleep(5)
    #dev.info

    # dump ui hierarchy into a xml file and extract info from it
    ISOTIMEFORMAT = '%m%d-%H-%M-%S'
    global current_time, nodelist
    current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
    dev.dump("./data/" + current_time + "hierarchy.xml")
    dev.screenshot("./data/" + current_time + ".png")
    dom = xml.dom.minidom.parse("./data/" + current_time + "hierarchy.xml")

    global flag_start_logcat
    global flag_start_activity
    global flag_stop_activity

    # 得到xml文档元素对象
    root = dom.documentElement
    nodelist = root.getElementsByTagName('node')
    nodelist = nodelist_redef(nodelist)
    for i in nodelist:
        if i not in clicked_list:
            ui_interaction(i)
            return nodelist
    dev.press.back()
    global flag_back
    flag_back = True
    print "back2"
    back_counter += 1
    return []
コード例 #8
0
def screen():
    # screenshot
    os.system(
        'adb shell screencap -p /sdcard/screentest.png')  #//+time end pull all
    # # pull to latop
    os.system(
        'adb pull /sdcard/Unknown /home/hauying/Desktop/auto_python/png ')
    d.screenshot("xxx.png")
コード例 #9
0
ファイル: Message_Helper.py プロジェクト: sonaliekagga/sonali
 def wifi(self):
   device.screen.on()
   device.press.menu()
   device(text ="Settings").click()
   device(text ="Wireless & networks").down(className="android.widget.TextView").click()
   device.screenshot("home.png")
   device.swipe(591,191,688,245)
   device.press.home()
コード例 #10
0
ファイル: 025.common.py プロジェクト: Renzhiai/rza-s-python
def save_fail_img(path="d:/img"):
	d.screenshot(c.getconfigs.get_log_path("img_path")+"/"+get_time()+".png")
	#if d(text="OK").exists:
	#	d(text="OK").click()
	#if d(resourceId="android:id/button1").exists:
	#	d(resourceId="android:id/button1").click()
	#else:
	#	d.press("home")
	return True
コード例 #11
0
ファイル: 025.common.py プロジェクト: 51qiuzhu/rza-s-python
def save_fail_img(path="d:/img"):
    d.screenshot(
        c.getconfigs.get_log_path("img_path") + "/" + get_time() + ".png")
    #if d(text="OK").exists:
    #	d(text="OK").click()
    #if d(resourceId="android:id/button1").exists:
    #	d(resourceId="android:id/button1").click()
    #else:
    #	d.press("home")
    return True
コード例 #12
0
def export_error(screen_dump=None):
    timestr = time.strftime("%Y%m%d-%H%M%S")
    filename = f'Erro - {timestr}.png'
    DEVICE.screenshot(filename)
    logger.error(
        f'Erro de exportação. Verificar tela capturada em "{filename}"')
    if __logging_level == logging.DEBUG and screen_dump:
        logger.debug(
            f'Tela desconhecida. DUMP: {xml.etree.ElementTree.tostring(screen_dump,encoding="unicode")}'
        )
コード例 #13
0
def get_experience_goblin():
    pos = judge.get_attack_pos(pic_name)
    if not pos:
        return
    for i in range(6):
        print('find experience pos', i, time.time())
        pos = judge.get_experience_pos(pic_name)
        if not pos:
            print('not found')
            time.sleep(0.3)
            d.screenshot(pic_name)
            continue
        search_box = (pos[0] - 300, pos[1] - 300, pos[0] + 300, pos[1])
        im = judge.get_crop_pic(pic_name, search_box)
        print('find attack pos', time.time())
        pos_list = judge.get_attack_pos(im, all_pos=True, pic_as_img=True)
        if not pos_list:
            print('not found')
            return
        print('find nearest', time.time())
        pos_list = [(x[0] + pos[0] - 200, x[1] + pos[1] - 300)
                    for x in pos_list]
        min_dis = 100000000000
        min_pos = None
        for apos in pos_list:
            dis = math.sqrt((apos[0] - pos[0])**2 + (apos[1] - pos[1])**2)
            if dis < min_dis:
                min_pos = apos
                min_dis = dis
        if not min_pos:
            return
        print('find attack again', time.time())
        pos = min_pos
        d.screenshot(pic_name)
        im = judge.get_crop_pic(
            pic_name, [pos[0] - 250, pos[1] - 250, pos[0] + 250, pos[1] + 250])
        pos_list = judge.get_attack_pos(im, all_pos=True, pic_as_img=True)
        if not pos_list:
            print('not found')
            return
        print('find nearest', time.time())
        pos_list = [(x[0] + pos[0] - 250, x[1] + pos[1] - 250)
                    for x in pos_list]
        min_dis = 100000000000
        min_pos = None
        for apos in pos_list:
            dis = math.sqrt((apos[0] - pos[0])**2 + (apos[1] - pos[1])**2)
            if dis < min_dis:
                min_pos = apos
                min_dis = dis
        if not min_pos:
            return
        print('attack pos', min_pos, time.time())
        return min_pos[0], min_pos[1]
コード例 #14
0
def quit_tansuo():
    if not judge.is_quit_page(pic_name):
        warning()
        return
    click_range(50, 70)
    d.screenshot(pic_name)
    if not judge.is_quit_ok_page(pic_name):
        warning()
        return
    click_range(850, 450)
    time.sleep(2)
    return True
コード例 #15
0
ファイル: android.py プロジェクト: queenaLou/utils
def screenshot_uiauto(adir, info):
    """uiautomator的截图方式

    :param adir:
    :param info:
    :return:
    """
    temp = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time()))
    filename = '{0}-{1}.png'.format(temp,info)
    filename = os.path.join(adir,filename)
    print filename
    from uiautomator import device as d
    d.screenshot(filename)
コード例 #16
0
def screenshot(shot):
	"""Screenshot will be taken and saved as the given file name 

	Example:
	| screenshot | screenshot1.png|
	"""
	cwd = os.getcwd()
	print cwd
	newpath = os.path.abspath(os.path.join(cwd, os.pardir))+'/screenshots/'
	print newpath
	if not os.path.exists(newpath): 
		os.makedirs(newpath)
	shot_path =  newpath+shot
	d.screenshot(shot_path)
コード例 #17
0
def wait_for_end():
    for j in range(180):  # * 3 seconds
        d.screenshot(pic_name)
        time.sleep(1)
        if judge.is_reward_continue_page(pic_name):
            print('win')
            click_range(1200, 185)
            return True
        elif judge.is_failed(pic_name):
            print('failed')
            click_range(1200, 185)
            return True
    else:
        print(' not find stop reward ')
コード例 #18
0
ファイル: vellamo.py プロジェクト: liushui312/uiautomator
def runtest(serialno, loop):
    print "liu: in runtest"
    if serialno:
        print "liu: in serialno"
        from uiautomator import Device
        d = Device(serialno)
    else:
        print "liu: in else"
        from uiautomator import device as d

    print "总共 %d 次循环" %loop
    d.watcher("Vellamo out of memory").when(text="Vellamo Out of Memory").click(text="ok")
    for i in range(1, loop+1):
        print "第 %d 次循环" %i
        d.screen.on()
        d.press.home()
        removeRecentList(d, "Benchmarking Application")
        d(description="Apps").click()
        d(text="Vellamo").click()
        time.sleep(2)

        if d(text="Accept").exists:
            d(text="Accept").click()
        if d(text="Welcome").exists:
            d.swipe(500,240,100,240)
            d.swipe(500,240,100,240)
            d.swipe(500,240,100,240)
        d(className="android.support.v4.view.ViewPager", \
            resourceId="com.quicinc.vellamo:id/act_main_pager_portrait")\
            .child(className="android.view.View")[0].click()

        #d(className="android.view.View")[2].click()
        if d(text="Yes").exists:
            d(text="Yes").click()
        while not d(text="Your device's score!").exists:
            time.sleep(2)
        else:
            d.screenshot("%s/screenshot/%d_vellamo_%s.png"\
                    %(sys.path[0], i, now.strftime(ISOFORMAT)))

        d.press.home()
        i += 1

    print "***** test end ********"
コード例 #19
0
def wifiStatus():
    time.sleep(8)
    print "Checking status"
    if d(text="Wi-Fi password not valid").exists:
        print "password not valid"
        d.screenshot("password_not_valid.png")
        #os.popen('adb kill-server')
        sys.exit()
    elif d(text="Hide password").exists:
        print "Enter password"
        d.screenshot("Enter_password_.png")
        #os.popen('adb kill-server')
        sys.exit()
    elif d(text="Couldn't connect to").exists:
        print "Coundn't connect ..."
        d.press.back()
        d.press.back()
    else:
        print "Connected to AP"
コード例 #20
0
ファイル: android.py プロジェクト: queenaLou/utils
def screenshot_minicap(adir, info):
    """使用minicap,会自动根据手机当前方向旋转图片,用来作为bug截图最为合适

    :param adir:
    :param info:
    :return:
    """
    print "开始截图..."
    temp = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time()))
    filename = '{0}-{1}.png'.format(temp,info)
    filename = os.path.join(adir,filename)
    import atx
    d = atx.connect()
    """ :type: atx.device.AndroidDevice"""

    d.screenshot_method = atx.SCREENSHOT_METHOD_MINICAP
    d.screenshot(filename)
    print 'result is {0}'.format(filename)
    execute_cmd("mspaint {0}".format(filename))
コード例 #21
0
def isSame(name):
    d.screenshot("E:\\workspace\\corneliusWorkPython\\snapshot\\snapshot.png")
    # result.writeToFile("E:\\workspace\\corneliusWorkPython\\snapshot\\snapshot.png", 'png')
    sleep(1.5)

    if name == "only":
        im = Image.open(
            "E:\\workspace\\corneliusWorkPython\\snapshot\\snapshot.png")
        box = (417, 608, 599, 695)
        region = im.crop(box)
        region.save(
            "E:\\workspace\\corneliusWorkPython\\snapshot\\snapshot1.png")
    else:
        im = Image.open(
            "E:\\workspace\\corneliusWorkPython\\snapshot\\snapshot.png")
        box = (417, 608, 687, 695)
        region = im.crop(box)
        region.save(
            "E:\\workspace\\corneliusWorkPython\\snapshot\\snapshot1.png")
    component = 0.0
    if name == "city":
        path = "E:\\workspace\\corneliusWorkPython\\snapshot\\city.png"
        component = compareImage(path)
    elif name == "by" or name == "jc":
        path = "E:\\workspace\\corneliusWorkPython\\snapshot\\by.png"
        component = compareImage(path)
    elif name == "gc":
        path = "E:\\workspace\\corneliusWorkPython\\snapshot\\gc.png"
        component = compareImage(path)
    elif name == "business":
        path = "E:\\workspace\\corneliusWorkPython\\snapshot\\business.png"
        component = compareImage(path)
    elif name == "bj":
        path = "E:\\workspace\\corneliusWorkPython\\snapshot\\bj.png"
        component = compareImage(path)
    elif name == "only":
        path = "E:\\workspace\\corneliusWorkPython\\snapshot\\only.png"
        component = compareImage(path)
    if component < 0.4:
        return True
    else:
        return False
コード例 #22
0
def find_ap(ap, ap2, def_timeout, count, passwd):
    ap_text = 'Saved'
    if d(text='Saved').exists == False:
        try:
            d(text='See all').click()
            time.sleep(3)
            d(scrollable=True).scroll.to(text='Saved')
            if d(text=ap_text).exists == False:
                print "Failed. Saved AP not found on AP list"
                d.screenshot("Failed_not_found_%d.png" % count)
                backHome()
                wifi_scan_time(ap, ap2)
                wifi_connect(0, ap, passwd, def_timeout)
                wifi_connect(0, ap2, passwd, def_timeout)
                return 1
        except:
            d.screenshot("Failed_exception_%d.png" % count)
            backHome()
            wifi_connect(0, ap, passwd, def_timeout)
            wifi_connect(0, ap2, passwd, def_timeout)
コード例 #23
0
def wifi_switch_test(count,ap,ap2,passwd,timeout):
    try:
        print ap
        print "click you"
        time.sleep(1)
        d(text=ap).click()
    except:
        time.sleep(1)
        d(text='See all').click()
        print "click all"
        try:
            time.sleep(1)
            d(scrollable=True).scroll.to(text=ap)
            d(text=ap).click()
        except:
            print "Can't find ap %s in AP list" %ap
            d.screenshot("cant_find_ap_%d.png" %count)
            wifi_connect(count,ap2,passwd,timeout)
            wifi_connect(count,ap,passwd,timeout)
            backHome()
コード例 #24
0
def auto_yuhun(times):
    for i in range(times):
        try:
            print('times', i + 1)
            time.sleep(2)
            d.screenshot(pic_name)
            print('find challenge in')
            if not judge.is_yuhun_challenge_in_page(pic_name):
                print('not challenge in page')
                warning()
                return
            click_range(1041, 578)
            print('challenge in')
            if not wait_for_end():
                warning()
                return
        except Exception as e:
            print(e)
            print(traceback.format_exc())
            warning()
    warning()
コード例 #25
0
def auto_challenge(times):
    refresh_times = 0
    for i in range(times):
        try:
            print('times', i + 1)
            time.sleep(2)
            d.screenshot(pic_name)
            print('check reward')
            if judge.is_reward_continue_page(pic_name):
                print('get reward for count')
                click_range(650, 570)
                d.screenshot(pic_name)
            print('find challenge')
            pos = judge.find_can_challenge_pos(pic_name)
            if not pos:
                print('can not get challenge pos')
                if refresh_times == 0:
                    print('refresh')
                    click_range(1180, 600)
                    d.screenshot(pic_name)
                    print('find refresh ok')
                    if judge.is_refresh_ok(pic_name):
                        click_range(850, 500)
                    else:
                        warning()
                        return
                    refresh_times = 1
                    continue
                warning()
                return
            refresh_times = 0
            print('pos is ', pos)
            top, right = pos
            click_range(right - 40, top + 40)
            d.screenshot(pic_name)
            print('find challenge in')
            if not judge.is_challenge_in_page(pic_name, top, right):
                print('not challenge in page')
                warning()
                return
            click_range(right - 128, top + 295)
            print('challenge in')
            if not wait_for_end():
                warning()
                return
        except Exception as e:
            print(e)
            print(traceback.format_exc())
            warning()
    warning()
コード例 #26
0
def swipe():
	d.screenshot(file1)

	t = time.time()

	d.screenshot(file2)

	screen1Delay = time.time() - t
	t = time.time()

	d.screenshot(file3)

	screen2Delay = time.time() - t
	t = time.time()

	bx, by, rx1, ry1, rx2, ry2, rx3, ry3 = getInfo(file1, file2, file3)
	vx1 = (rx2 - rx1) / screen1Delay
	vy1 = (ry2 - ry1) / screen1Delay
	vx2 = (rx3 - rx2) / screen2Delay
	vy2 = (ry3 - ry2) / screen2Delay

	# account for direction changing
	changedDir = vx2 != 0 and abs(vx1) / abs(vx2) > changeDirThreshold
	if changedDir:
		projrx3 = rx2 + vx1 * screen2Delay
		changedDir = projrx3 < minX or projrx3 > maxX
	if changedDir:
		print("Changed direction: vx1: {:f}, vx2: {:f}, vy1: {:f}, vy2: {:f}".format(vx1, vx2, vy1, vy2))
	vx = -vx1 if changedDir else vx2
	vy = -vy1 if changedDir else vy2

	procDelay = time.time() - t
	t = time.time()

	rx = rx3 + vx * (procDelay + projActDelay)
	ry = ry3 + vy * (procDelay + projActDelay)

	# account for screen limits
	usedT = 0
	if rx > maxX:
		usedT = (maxX - rx3) / vx
		rx = maxX - vx * (procDelay + projActDelay - usedT)
	elif rx < minX:
		usedT = (minX - rx3) / vx
		rx = minX - vx * (procDelay + projActDelay - usedT)
	if ry > maxY:
		usedT = (maxY - ry3) / vy
		ry = maxY - vy * (procDelay + projActDelay - usedT)
	elif ry < minY:
		usedT = (minY - ry3) / vy
		ry = minY - vy * (procDelay + projActDelay - usedT)
	if usedT != 0:
		print("Out of bounds: usedT: {:f}, rx: {:f}, ry: {:f}".format(usedT, rx, ry))

	d.swipe(bx, by, rx, ry, swipeSpeed)

	actDelay = time.time() - t

	if vx != 0:
		print("Ball: ({}, {})\nRing: ({}, {}) -> ({}, {}) -> ({}, {})\nTarget: ({}, {})".format(bx, by, rx1, ry1, rx2, ry2, rx3, ry3, rx, ry))
		print("Delays: ({:f}, {:f}, {:f}, {:f})".format(screen1Delay, screen2Delay, procDelay, actDelay))
コード例 #27
0
def screenShot():
    d.screenshot('screenShot.png')
コード例 #28
0
def wifi_switch_test(count, ap, ap2, passwd, timeout):
    try:
        print ap
        print "click you"
        time.sleep(1)
        d(text=ap).click()
    except:
        time.sleep(1)
        d(text='See all').click()
        print "click all"
        try:
            time.sleep(1)
            d(scrollable=True).scroll.to(text=ap)
            d(text=ap).click()
        except:
            print "Can't find ap %s in AP list" % ap
            d.screenshot("cant_find_ap_%d.png" % count)
            time.sleep(2)
            wifi_connect(count, ap2, passwd, timeout)
            wifi_connect(count, ap, passwd, timeout)
            backHome()
            return 1
    time.sleep(3)
    try:
        d(text='Connect').click()
        print "click connect"
        time.sleep(3)
    except:
        wifi_connect(count, ap2, passwd, timeout)
        wifi_connect(count, ap, passwd, timeout)
        backHome()
        return 1

    if d(text="Connected successfully").wait.exists(timeout=timeout * 1000):
        print "Pass"
        return 0

    elif d(textContains="Wi-Fi password not valid").exists:
        print "Password not valid"
        d.screenshot("password_not_valid_%d.png" % count)
        time.sleep(2)
        wifi_connect(count, ap2, passwd, timeout)
        wifi_connect(count, ap, passwd, timeout)
        backHome()
        return 1
    elif d(textContains="Couldn't connect to").exists:
        print "Couldn't connect to "
        d.screenshot("cant_connect_%d.png" % count)
        time.sleep(2)
        wifi_connect(count, ap2, passwd, timeout)
        wifi_connect(count, ap, passwd, timeout)
        backHome()
        return 1
    else:
        print "Connect timeout over 60s"
        d.screenshot("connect_overtime_%d.png" % count)
        time.sleep(2)
        wifi_connect(count, ap2, passwd, timeout)
        wifi_connect(count, ap, passwd, timeout)
        backHome()
        return 1
コード例 #29
0
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    time.sleep(1)
    d.press.enter()
    # print "Step ###"
    # wifi connection time
    if d(text="Connected successfully").wait.exists(timeout=def_timeout * 1000) == False:
        print "connecting time over time"
        print "Fail to connect AP"
        #fail_count = fail_count + 1
        return 1
    d(text="Connected successfully").wait.exists(timeout=120000)
    # time.sleep(def_timeout)
    time.sleep(2)
    return 0

'''
ap='xiaomi_hdd'
ap2='xiaomi_hdd_5G'
passwd='asdfghjkl'
print "password not valid"
d.screenshot("password_not_valid.png")
wifi_connect(0, ap, passwd, 40)
wifi_connect(0, ap2, passwd, 40)
print "Finish connect"
time.sleep(2)
d.press.up()
time.sleep(2)
d.press.up()
time.sleep(2)
d.press.up()
time.sleep(2)
コード例 #30
0
def screen_shot():
    'screenshot and return colorful and gray images'
    img_bytes = d.screenshot(None)
    img = Image.open(Image.io.BytesIO(img_bytes))
    return img, img.convert('L')
コード例 #31
0
# -*- coding: utf-8 -*-
# @Time : 2019/4/11 9:37
# @Author : Vanya
from uiautomator import device as d

while True:
    name = input('filename:')
    if name == 'q':
        break
    d.screenshot('pics/' + name + '.png')
# d.click(1250, 765)
コード例 #32
0
ファイル: travel_test.py プロジェクト: majestyhao/uidroid
def handle_window():
    #dev.wait.idle()
    global clk_seq, back_counter, parent_width, newnode_counter
    global menu_index, menu_flag, last_is_back
    current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
    dev.dump(dir_data + current_time + "hierarchy.xml")
    dev.screenshot(dir_data + current_time + ".png")
    logger.info('screen shot at ' + current_time)
    dom = xml.dom.minidom.parse(dir_data + current_time + "hierarchy.xml")
    root = dom.documentElement
    nodelist = []
    node_clk = {'node': None, 'index': -1, 'node_attri': {}}
    window = []
    parent_width = 0
    newnode_counter = 0
    menu_flag = False
    DFS_xml(root, nodelist, window, node_clk)
    if newnode_counter > 3:
        #if is a new window
        if menu_flag:
        # and meet with menu again
            logger.info('MENU FOUND>>>>>>>>>>>>>')
            if shown_clickable[menu_index]['width'] == 0:
                shown_clickable[menu_index]['width'] += 1
                logger.info('MMMMMMMMMMMMMMMMMMMMMMMMMENU AGAINNNNNNNN')
    # print node_clk['index']
    #print window  # useful for debug...
    # print shown_clickable
    #print clk_seq   # useful for debug...

    # if not is_same_window(window, priwindow):
    #     flag = 0
    #     for i in window_list:
    #         if is_same_window(window, i):
    #             flag = 1
    #             break
    #     if flag == 0:
    #         window_list.append(window)
    # else:
    #     samewindow += 1
    # print node_clk['index']
    # priwindow = window
    if node_clk['index'] != -1:
        node = shown_clickable[node_clk['index']]
        ui_interaction(node_clk['node'], current_time)
        logger.info(node_clk['node_attri'])
        #print node_clk['index']
        #print node['node_attri']
        node['width'] -= 1
        if clk_seq:
            parent_index = node['parent']
            parent = shown_clickable[parent_index]
            parent['width'] -= 1
            while parent['parent']:
                parent_index = parent['parent']
                parent = shown_clickable[parent_index]
                parent['width'] -= 1
                #print 'just do it !!!!!!!!!!!!!! on '
                #print parent_index

        clk_seq.append(node_clk['index'])
        last_is_back -= 1
        if last_is_back < -15:
            dev.press.back()
            last_is_back = 1
        return True
    else:
        #clk_seq.append(-1)
        dev.press.back()
        logger.info('press back')
        if len(clk_seq):
            prinode_index = clk_seq[len(clk_seq) - 1]
            prinode = shown_clickable[prinode_index]
            prinode['width'] = 0
        back_counter += 1
        if last_is_back < 0:
            last_is_back = 0
        last_is_back += 1
        return False
コード例 #33
0
def auto_task(times):
    first_start = True
    count = 0
    while True:
        try:
            have_task = False
            d.screenshot(pic_name)
            print('find entry')
            if not judge.is_exploration_in_page(pic_name):
                print('not entry page')
                if not first_start:
                    warning()
                    return
            else:
                click_range(1066, 604)
                print('entry')
                time.sleep(2)
                d.drag(1300, 130, 800, 130, 10)
            first_start = False
            move_times = 0
            retry_times = 0
            while True:
                d.screenshot(pic_name)
                print('find boss')
                pos = judge.get_attack_boss_pos(pic_name)
                if pos:
                    print('challenge in boss')
                    if not attack_boss(pos):
                        return
                    count += 1
                    print('count', count)
                    if count == times:  # finish
                        warning()
                        return
                    break
                print('no boss, find task goblin')
                pos = get_task_goblin()
                if pos:
                    have_task = True
                    click_range(pos[0], pos[1])
                    print('challenge in goblin')
                    time.sleep(1)
                    d.screenshot(pic_name)
                    if judge.is_quit_page(pic_name):
                        retry_times += 1
                        if retry_times >= 5:
                            warning()
                            return
                        print('challenge in failed retry', retry_times)
                        continue
                    time.sleep(5)
                    d.screenshot(pic_name)
                    if not judge.is_battle_page(pic_name):
                        retry_times += 1
                        if retry_times >= 5:
                            warning()
                            return
                        print('challenge in failed retry', retry_times)
                        continue
                    print('challenge in success')
                    retry_times = 0
                    if not wait_for_end():
                        warning()
                        return
                    count += 1
                    print('count', count)
                    if count == times:  # finish
                        warning()
                        return
                    continue
                print('no goblin')
                if move_times < 2:
                    print('go right', move_times)
                    d.drag(1300, 130, 300, 130, 10)
                    # click_range(pos_x, 570)  # right
                else:
                    print('quit exploration after 2 times')
                    if quit_tansuo():
                        break
                    warning()
                    return
                move_times += 1
                time.sleep(3)
            if not have_task:
                print('no tasks goblin')
                warning()
                return
        except Exception as e:
            print(e)
            print(traceback.format_exc())
            warning()
コード例 #34
0
# In[3]:

d.screen.on()

# In[8]:

d.press.camera()

# In[14]:

d.orientation

# In[90]:

d.screenshot("home.png")

# In[84]:

d.dump("hierarchy.xml", compressed=False)

# In[104]:

d(scrollable='true').info

# In[82]:

d.dump("hierarchy.xml")

# In[40]:
コード例 #35
0
def wifi_connect(count, ap, passwd, def_timeout):
    print "WIFI connect in LOOP %d" % count
    # get_log(count)
    d.press.home()
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.down()
    time.sleep(1)
    d.press.right()
    time.sleep(1)
    d.press.right()
    #d.press.right()
    # d.press.right()

    d.press.enter()
    time.sleep(3)
    d.press.enter()
    time.sleep(3)
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.down()
    d.press.down()

    d.press.enter()
    time.sleep(2)
    cmd = 'adb shell input text %s' % ap
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    cmd = 'adb shell input keyevent KEYCODE_ESCAPE'
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    time.sleep(1)
    d.press.enter()
    time.sleep(1)

    # d.press.enter()


    d.press.down()
    d.press.down()
    d.press.enter()
    cmd = 'adb shell input text %s' % passwd
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    cmd = 'adb shell input keyevent KEYCODE_ESCAPE'
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    time.sleep(1)
    d.press.enter()
    # print "Step ###"
    # wifi connection time
    if d(text="Connected successfully").wait.exists(timeout=def_timeout * 1000) == False:
        print "connecting time over time"
        print "Fail to connect AP"
        d.screenshot("connect_failed_%d.png" % count)
        time.sleep(2)
        #fail_count = fail_count + 1
        return 1
    d(text="Connected successfully").wait.exists(timeout=120000)
    # time.sleep(def_timeout)
    return 0
コード例 #36
0
def shot():
    d.screenshot("home.png")
コード例 #37
0
 def Android_Screenshot(self, error):
     Path = ("../../Result/pic/")
     now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
     d.screenshot(Path + error + '_' + now + ".jpg")
     print "Save " + Path + error + '_' + now + ".jpg"
コード例 #38
0
        # d.press.enter()
        #start=datetime.datetime.now()
        if d(text="Connected successfully").wait.exists(timeout=def_timeout * 1000) == False:
            print "connecting time over 60s"
            wifi_scan_time(ap, ap2)
        if d(text="Connected successfully").wait.exists(timeout=20000) == False:
            print "connecting time over 80s"
            return 1
        if d(text="Connected successfully").wait.exists(timeout=120000) == False:
            print "Connected within 200s"
            return 1
            backHome()
        else:
            print "Failed to switch AP"
            wifi_scan_time(ap, ap2)
            d.screenshot("Failed_switch_%d.png" % count)
            #backHome()
            wifi_connect(0, ap, passwd, def_timeout)
            wifi_connect(0, ap2, passwd, def_timeout)
            return 1
        return 0
    except:
        # backHome()
        wifi_connect(0, ap, passwd, def_timeout)
        wifi_connect(0, ap2, passwd, def_timeout)
=======
        print "click connect"
        time.sleep(3)
    except:
        wifi_connect(count,ap2,passwd,timeout)
        wifi_connect(count,ap,passwd,timeout)