我有两个脚本,脚本 A 一个是链接手机 A(进入某个应用,然后按菜单键,把这个应用杀掉,然后再进入这个应用,不停循环);脚本 B(是控制一个 Android 设备 B,然后隔一段时间判断元素,然后进行截屏),现在想要用一台电脑同时控制手机 A 跑脚本 A,设备 B 跑脚本 B,该怎么做呢?求解答
脚本 A
#! /usr/bin/env python
#coding=utf-8
import os
import time
import unittest
from appium import webdriver
import selenium
import subprocess
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(file), p))
desired_caps = {}
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:4723/wd/hub', desired_caps)

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)

脚本 B
#! /usr/bin/env python
#coding=utf-8
import os
import time
import unittest
from appium import webdriver
import selenium
import subprocess
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(file), p))
desired_caps = {}
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)

print"BACK"
driver.press_keycode(3)
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+=1


↙↙↙阅读原文可查看相关链接,并与作者交流