Python3.7+appium1.4+unittest单元测试框架+app自动化代码【杭州多测师_王sir】【杭州多测师】
1、采用的是appium1.4
2、线性代码目前没有进行分层封装
3、被测app用的是百度阅读
#coding=utf-8 """ =========================== Author:杭州多测师_王sir Time:2022-09-17 14:37 website:https://duoceshi.net =========================== """ from appium import webdriver from time import sleep import unittest from app_auto.HTMLTestRunner3_New import HTMLTestRunner class Test(unittest.TestCase): @classmethod def setUpClass(cls) -> None: desired_caps={ 'platformName':'Android', #平台系统:Android or Ios 'deviceName':'SMG9350', #设备名称 'platformVersion':'android4.4W', #平台版本 'appPackage':'com.baidu.yuedu', #包名 'appActivity':'com.baidu.yuedu.splash.SplashActivity', #activity 'unicodeKeyboard': True, #使用unicode编码方式发送字符串 'resetKeyboard':True #是将键盘隐藏起来 } #这个对象就是已经打开了的app cls.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps) cls.driver.implicitly_wait(10) @classmethod def tearDown(self) -> None: sleep(4) def test001_customer_center(self): ''' 左上角个人中心相关操作 :return: ''' #点击人头 self.driver.find_element_by_id("com.baidu.yuedu:id/title_account").click() self.driver.find_element_by_name("我的收藏").click() self.driver.find_element_by_name("取消").click() #点击取消 self.driver.find_element_by_name("我的购买").click() self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.find_element_by_name("我的阅历").click() self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.find_element_by_name("我的阅读基因").click() self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.find_element_by_name("我的笔记").click() self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.find_element_by_name("阅读币").click() self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.find_element_by_name("积分").click() self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.find_element_by_name("代金券").click() self.driver.find_element_by_id("com.baidu.yuedu:id/backbutton").click() #点击返回 self.driver.find_element_by_name("设置").click() self.driver.find_element_by_id("com.baidu.yuedu:id/sb_volumn_page").click()#点击音量键翻页 self.driver.find_element_by_id("com.baidu.yuedu:id/tv_cache_desc").click()#清理缓存 self.driver.find_element_by_id("com.baidu.yuedu:id/new_my_about").click() #关于百度阅读 self.driver.find_element_by_id("com.baidu.yuedu:id/backbutton").click() # 点击返回 self.driver.find_element_by_id("com.baidu.yuedu:id/backbutton").click() # 点击返回设置 self.driver.back() bookshelf = self.driver.find_element_by_id("com.baidu.yuedu:id/lefttitle").text self.assertEqual(bookshelf, "书架") # 进行断言 def test002_bookshelf(self): '''操作书架tab页面''' self.driver.find_element_by_id("com.baidu.yuedu:id/folder_book_cover1").click() #com.baidu.yuedu:id/board_folder_name self.driver.find_element_by_id("com.baidu.yuedu:id/board_folder_name").click() self.driver.find_element_by_name("确定").click() self.driver.find_element_by_id("com.baidu.yuedu:id/rl_close").click() # 点击+号 self.driver.find_element_by_id("com.baidu.yuedu:id/first_ball").click() #点击云导入 self.driver.find_element_by_name("取消").click() # 点击取消 self.driver.back() bookshelf = self.driver.find_element_by_id("com.baidu.yuedu:id/lefttitle").text self.assertEqual(bookshelf,"书架") #进行断言 def test003_book(self): """ 图书tab相关用例 :return: """ self.driver.find_element_by_name("图书").click() self.driver.find_element_by_name("个性推荐").click() self.driver.find_element_by_name("免费").click() self.driver.find_element_by_name("排行").click() self.driver.find_element_by_name("分类").click() self.driver.find_element_by_id("com.baidu.yuedu:id/ball").click() #点击购物车 self.driver.find_element_by_name("去书城逛逛").click() def test004_story(self): """ 小说tab相关用例 :return: """ self.driver.find_element_by_name("小说").click() self.driver.find_element_by_name("推荐").click() self.driver.find_element_by_name("免费").click() self.driver.find_element_by_name("排行").click() self.driver.find_element_by_name("分类").click() self.driver.find_element_by_id("com.baidu.yuedu:id/ball").click() #点击购物车 self.driver.find_element_by_name("去书城逛逛").click() def test005_search(self): """ 搜索框相关的用例 :return: """ #com.baidu.yuedu:id/full_text_search_bar_search self.driver.find_element_by_id("com.baidu.yuedu:id/search_account").click() #点击搜索框 self.driver.find_element_by_id("com.baidu.yuedu:id/full_text_search_bar_input").send_keys("123") #输入内容 self.driver.find_element_by_id("com.baidu.yuedu:id/full_text_search_bar_search").click() # 点击搜索 self.driver.find_element_by_id("com.baidu.yuedu:id/full_text_search_bar_back").click() #点击返回按钮 bookshelf = self.driver.find_element_by_id("com.baidu.yuedu:id/lefttitle").text self.assertEqual(bookshelf, "书架") # 进行断言 if __name__ == '__main__': path=r"D:\project\app_auto" discover=unittest.TestLoader().discover(start_dir=path,pattern='lesson*.py') dir=r'D:\project\app_auto'+'\\'+'ui.html' filename=open(dir,'wb') runner=HTMLTestRunner(stream=filename, title='UI自动化测试报告', description='用例执行情况如下',tester='xxx') runner.run(discover)