简体   繁体   中英

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

I thought I would find easily the answer to my question on Google or here. I only found the command launch_app .

My findings on the internet :

So I searched for some examples of launch_app to try to understand how to run an app. But unfortunately there is nothing on the web.

The offical doc fives you 2 sames pages:

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

Where it explained that it launches an app, but they don't give some real example code.

There is no tutorial.

My research effort:

So I tried on my own, I simply added the command as explained in the doc:

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()

Error I get:

But it doesn't launch the instagram app and it gives me this error message:

selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

Which is normal because app was not launched.

Anyone can tell me how can I start an app on Android/Appium with python please? How to use this launch_app() correctly?

Thanks

Correct you appPackage and appActivity capability with :

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

With the above capability you just call .launch_app() .

Or without the above capability you can use startActivity like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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