简体   繁体   中英

Appium browser button launch app with parameter

my test scenario is
open browser -> click the 'launch app button'-> open app with parameter(which page?which id)
I've try start activity but it just open the app without the parameter
Anyone have an idea? Is that possible to do the scenario with autotesting?
Here is my code:

import os
import unittest
from appium import webdriver
from selenium.webdriver.common.by import By
import time

class AppiumTest(unittest.TestCase):
    def setUp(self):
        adb_devices_result = os.popen("adb devices").read()
        if adb_devices_result.find("List of devices attached") < 0:  # adb is not working
            return None
        deviceId = adb_devices_result.replace("List of devices attached", "").replace("\n", "").split("\t")[0]
        model = os.popen("adb -s " + deviceId + " shell getprop ro.product.model").read()
        osVersion = os.popen("adb -s " + deviceId + " shell getprop ro.build.version.release").read()
        apkVersion = os.popen("adb -s " + deviceId + " shell dumpsys package com.twca.middemo | grep versionName").read()
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'platformName': 'Android',
                'browserName': 'Chrome',
                'deviceName': deviceId,
                'udid': deviceId,
                'model': model,
                'osVersion': osVersion,
                'appVersion': apkVersion,
                'chromedriverExecutable': 'C://chromedriver_win32//chromedriver.exe',
            }
        )
    def testFirstAutomationTest(self):
        self.driver.get('https://demo.com.tw/channel/launchApp.htm?q=91zKN1ZC3Jupwa9vSX2M')
        self.driver.find_element(By.XPATH, '//button[text()="APP"]').click()
        self.driver.start_activity("com.tw.android.test", "com.twLauncherActivity")  
        time.sleep(10)
        
    def tearDown(self):
        time.sleep(1)

if __name__ == '__main__':
    unittest.main()

Appium allows you to start Activity with Intent, there is a good example in Python client tests:

driver.start_activity(
  app_package='com.example.myapp',
  app_activity='.ExampleActivity',
  app_wait_package='com.example.waitapp',
  intent_action='android.intent.action.MAIN',
  intent_category='android.intent.category.LAUNCHER',
  intent_flags='0x10200000',
  optional_intent_arguments='--es "activity" ".ExampleActivity"',
  dont_stop_app_on_reset=True
)

So you should be able to open your app with pre-defined state, well still depends on the app.

To better undersand how it works, I suggest this article

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