繁体   English   中英

如何使用Appium / Python在真实设备上启动应用程序?

[英]How to start an application on real device with Appium/Python?

我以为我可以在Google或此处轻松找到问题的答案。 我只找到命令launch_app

我在互联网上的发现:

因此,我搜索了一些launch_app示例,以尝试了解如何运行应用。 但不幸的是,网上没有任何东西。

官方文档可为您提供2个相同的页面:

  1. http://appium.io/docs/en/commands/device/app/launch-app/
  2. https://appium.readthedocs.io/en/stable/en/commands/device/app/launch-app/

它在哪里解释说它会启动一个应用程序,但是他们没有给出一些实际的示例代码。

没有教程。

我的研究工作:

因此,我自己尝试了一下,我只是按照文档中的说明添加了命令:

from datetime import time
from time import sleep

from appium import webdriver
import unittest

from selenium.webdriver.common.by import By


class Instagram(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName']='Android'
        desired_caps['platformVersion']='6.0'
        desired_caps['deviceName']='S6S5IN3G'
        desired_caps['noReset']='true'
        desired_caps['appPackage']='com.instagram'
        desired_caps['appActivity']=' com.instagram.android/com.instagram.android.activity.MainTabActivity'

        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
        #self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub',desired_caps)
        self.driver.launch_app()

错误我得到:

但它不会启动instagram应用,并且会显示以下错误消息:

selenium.common.exceptions.NoSuchElementException:消息:使用给定的搜索参数无法在页面上找到元素。

这是正常现象,因为未启动应用程序。

有人可以告诉我如何使用pythonAndroid/Appium上启动应用程序吗? 如何正确使用这个launch_app()

谢谢

使用以下命令更正您的appPackageappActivity功能:

self.dc['appPackage'] = 'com.instagram.android'
self.dc['appActivity'] = '.activity.MainTabActivity'

有了以上功能,您只需调用.launch_app()

如果没有上述功能,则可以这样使用startActivity

self.driver.startActivity("com.instagram.android", ".activity.MainTabActivity")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM