• #! /usr/bin/env python
    #coding=utf-8
    import os
    import time
    import unittest
    from appium import webdriver
    import selenium
    import subprocess
    import threading
    def killdm():
    PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(file), p))
    desired_caps = {}
    desired_caps['udid'] = 'f0eb68f9'
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '6.0.1'
    desired_caps['deviceName'] = 'f0eb68f9'
    desired_caps['appPackage'] = 'com.tencent.tws.gdevicemanager'
    desired_caps['appActivity'] = 'com.tencent.tws.phoneside.SplashScreenActivity'
    print"启动DM"
    driver = webdriver.Remote('http://localhost:4724/wd/hub', desired_caps)
    for a in range(0,10):
    print"长按MENU"
    driver.press_keycode(82)
    time.sleep(5)
    print"kill"
    driver.swipe(768, 1802, 768, 400, 500)
    time.sleep(5)
    print"调起"
    driver.start_activity('com.tencent.tws.gdevicemanager', 'com.tencent.tws.phoneside.SplashScreenActivity')
    time.sleep(5)

    def screen():
    PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(file), p))
    desired_caps = {}
    desired_caps['udid'] = 'PPW0443P6B0100755'
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '5.1'
    desired_caps['deviceName'] = 'PPW0443P6B0100755'
    desired_caps['appPackage'] = 'com.android.settings'
    desired_caps['appActivity'] = 'MainActivity'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    time.sleep(2)
    print"BACK"
    driver.swipe(22, 205, 289, 205, 500)
    time.sleep(5)
    print"判断"
    d = 0
    for i in range(0, 10):
    try:
    driver.find_element_by_id('com.tencent.tws.launcher:id/watch_face_home_status_icon_disconnect')
    d = d + 1
    time.sleep(5)
    print(d)
    except Exception:
    d = d
    time.sleep(5)
    print(d)
    i=i+1
    threads = []
    t1 = threading.Thread(target=killdm())
    threads.append(t1)
    t2 = threading.Thread(target=screen())
    threads.append(t2)
    for t in threads:
    #t1.start()
    # t2.start()
    #t.setDaemon(True)
    t.start()
    for t in threads:
    t.join()
    目前改成这样了,发现是先运行了killdm函数执行完后才执行screen函数,但是希望能同时运行这两个函数,该怎么做呢

  • @Lihuazhang 我修改了自己的帖子,请打开吧,谢谢