app测试——ui自动化

一、打开模拟器或手机

二、连接模拟器:adb  connect  127.0.0.1模拟器的端口号

三、安装测试包

安装测试包:adb  install   E:\dcs\two\app\baiduyuedu_5520.apk(测试包文件路径)

四、开appium

五、sdk中的tools中的uiautomatorviewer.bat

  • 双击打开,获取页面的页面元素

  • 替换成uiautomatorviewer.bat(有xpath,如果没有xpath的)
  • 步骤:第一步:再tools下的lib中替换jar包

 

  • 第二包存放在E:\app\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-20

  • 第三:将tools下uiautomatorviewer.bat(删除,用这个最新的插件)


一、pycarm中参数

  • 'platformName':'Android',      #平台系统:

  • 'deviceName':'OPPO R17',     #设备名称

  • 'platformVersion':'android-5.1W',    #平台版本

  • 'appPackage':'com.moji.mjweather',     #包名

  • 'appActivity':'com.moji.mjweather.LauncherActivity',   #activity

  • 'unicodeKeyboard': True, #使用unicode编码方式发送字符串 }
  • 'resetKeyboard':True} #是将键盘隐藏起来
  • dx=webdriver.Remote("http://127.0.0.1:4723/wd/hub",sc)

二、示例代码

from appium import webdriver
from time import *
import unittest
from uizdh.HTMLTestRunnerNew import HTMLTestRunner
import os
class appui(unittest.TestCase):
    def setUp(self) -> None:
        cs = {
            'platformName': 'Android',  # 平台系统:Android or Ios
            'deviceName': 'OPPO R17',  # 设备名称
            'platformVersion': 'android-5.1W',  # 平台版本
            'appPackage': 'com.baidu.yuedu',  # 包名
            'appActivity': 'com.baidu.yuedu.splash.SplashActivity',  # activity
            'unicodeKeyboard': True,  # 使用unicode编码方式发送字符串
            'resetKeyboard': True  # 是将键盘隐藏起来
        }
        self.dx = webdriver.Remote("http://127.0.0.1:4723/wd/hub", cs)
        sleep(10)
    def tearDown(self) -> None:
        self.dx.quit()
    def test1_ydts(self):   # 阅读图书
        self.dx.find_element_by_id("com.baidu.yuedu:id/folder_book_cover0").click()
        sleep(5)
        self.dx.find_element_by_id("com.baidu.yuedu:id/myyuedu_tv_book_title").click()
        sleep(5)
    def test2_search(self): # 搜索图书
        self.dx.find_element_by_id("com.baidu.yuedu:id/tab_search").click()
        sleep(5)
        self.dx.find_element_by_id("com.baidu.yuedu:id/full_text_search_bar_input").send_keys("狼图腾")
        sleep(5)
        self.dx.find_element_by_xpath("//android.widget.ImageView[@content-desc='百度阅读']").click()
        sleep(5)
    def test3_grzx(self):# 进入个人中心
        self.dx.find_element_by_id("com.baidu.yuedu:id/title_left_account").click()
        sleep(5)
    def test4_drts(self):  # 导入图书
        self.dx.find_element_by_id("com.baidu.yuedu:id/iv_close").click()
        sleep(5)
    def test5_qhlm(self):  # 切换小说栏目
        self.dx.find_element_by_id("com.baidu.yuedu:id/webbooktitle").click()
        sleep(5)
if __name__ == '__main__':
    # unittest.main()
    lj = r"E:\1\python\PycharmProjects\untitled\uizdh"
    bglj = r"E:\1\python\PycharmProjects\untitled\uizdh"
    # lj=os.path.dirname(os.getcwd())
    # bglj=os.path.join(lj)
    d = unittest.TestLoader().discover(start_dir=lj,pattern="appuisz*.py")
    new = strftime("%y-%m-%d %H-%M-%S")
    file = bglj+"/"+str(new)+"appui.html"
    f = open(file,"bw")
    HTMLTestRunner(
        stream = f,title = "appui自动化报告",description = "用例执行情况",tester = "dcs"
    ).run(d)

posted @ 2025-04-02 16:02  uai  阅读(31)  评论(0)    收藏  举报