Appium学习

      一、基础配置

import unittest
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

capabilities = {
    'platformName': 'Android',
    'automationName': 'uiautomator2',
    'deviceName': '127.0.0.1:21503',#连接的设备名称
    'appPackage': 'com.tjlianxin.smartcanteen363',#要测试的包名
    'appActivity': 'com.lianxin.smartcanteenposc7.ui.spflash.SpflashActivity',#要测试包名的主活动名称
    'language': 'zh',
    'locale': 'CN'
}

appium_server_url = 'http://localhost:4723/wd/hub'

class TestAppium(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities))

    def tearDown(self) -> None:
        if self.driver:
            self.driver.quit()

    def test_find_battery(self) -> None:
        wait = WebDriverWait(self.driver, 10)
        el = wait.until(EC.presence_of_element_located((AppiumBy.XPATH, '//*[@text="确定"]')))
        el.click()

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

1.appPackage名可以使用下面的adb命令来查询所有的包名,找到你要测试程序的包名

adb shell pm list packages

2.appActivity界面主活动名称可以使用下面的语句查询包名的主活动界面名称,注意:com.tjlianxin.smartcanteen363需要替换为你测试程序的包名

adb shell dumpsys package com.tjlianxin.smartcanteen363

查询完成之后会显示出很多的数据,找到MAIN或者是LAUNCHER这两个字符,我找出来的是这样的,取出上面的包名的活动名称

      android.intent.action.MAIN:
        e4653d com.tjlianxin.smartcanteen363/com.lianxin.smartcanteenposc7.ui.spflash.SpflashActivity filter 2346502
          Action: "android.intent.action.MAIN"
          Category: "android.intent.category.LAUNCHER"

 那么你得实际活动名就是:

com.lianxin.smartcanteenposc7.ui.spflash.SpflashActivity

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值