Appium 新人求助:Appium 多设备,测试用例只在一个设备上执行。

xiaobai1315 · 2019年01月26日 · 最后由 xiaobai1315 回复于 2019年01月27日 · 1236 次阅读

平台:Mac

问题描述:

运行代码后,两台设备都会启动 APP,但是只有一台设备在执行用例,而且会执行两次。

appium 启动服务:

appium -p 4723 -bp 4724
appium -p 4725 -bp 4726

代码

def desired_caps(platformVersion, udid, deviceName ,port):
    with open("../config/desired_caps.yaml", 'r', encoding='utf-8') as f:
        data = yaml.load(f)

    caps = dict()

    caps['platformVersion'] = platformVersion
    caps['udid'] = udid
    caps['deviceName'] = deviceName

    caps['platformName'] = data['platformName']
    caps['appPackage'] = data['appPackage']
    caps['appActivity'] = data['appActivity']
    caps['unicodeKeyboard'] = data['unicodeKeyboard']
    caps['resetKeyboard'] = data['resetKeyboard']
    caps['automationName'] = data['automationName']
    caps['noReset'] = data['noReset']

    base_path = os.path.dirname(os.path.dirname(__file__))
    file_path = os.path.join(base_path, 'app', 'kaoyan.apk')
    caps['app'] = file_path

    driver = webdriver.Remote('http://{}:{}/wd/hub'.format(data["ip"], port), caps)
    driver.implicitly_wait(2)

    usernameTF = 'com.XXX'
    pwdTF = 'com.XXX'
    loginBtn = 'com.XXX'

    driver.find_element_by_id(usernameTF).send_keys("1231231231")
    driver.find_element_by_id(pwdTF).send_keys("123123123")
    driver.find_element_by_id(loginBtn).click()


if __name__ == '__main__':

    _version = ["7.1.1", "6.0.1"]
    _udid = ["ZX1G429WZM", "bbda9633"]
    _name = ["Nexus 6", "Galaxy S5"]

    desired_process = []
    for i in range(2):
        port = 4723 + i * 2

        desired = multiprocessing.Process(target=desired_caps, args=(_version[i], _udid[i], _name[i], port))
        desired_process.append(desired)

    for process in desired_process:
        process.start()

    for process in desired_process:
        process.join()

求大神帮忙,非常感谢!!!

共收到 2 条回复 时间 点赞

大神都回家过年了吗😭 😭 😭

已解决,caps 需要指定 systemPort

xiaobai1315 关闭了讨论 01月27日 10:43
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册