标题
app 企业微信实战(一)
课程价值
- 了解 Appium 框架结构
- 掌握 Appium 环境搭建
- 掌握 Appium Inspector 录制及查找元素的使用
- 掌握 DesireCapability 用法
大纲
- Appium 介绍
- Appium 环境搭建
- Appium Inspector
- 企业微信实战-自动打卡
时长
90分钟
PPT
脚本编写
应用
Appium 介绍
- 推荐 Appium
- 跨语言:Java、Python、nodejs等
- 跨平台
- 底层多引擎可切换
- 生态丰富,社区强大
Appium 框架结构
Appium 环境搭建
- Nodejs 12
- Appium 建议1.15
- Java 1.8
- SDK build-tools/ 下对应的版本,需要使用<=29的版本
设备的选择
- 真机 (豌豆夹,手机助手 下载驱动)
开发者选项- USB调试模式
- 模拟器
- 网易mumu,夜神,雷电
- 自动连接 sdk emulator,genimotion
连接网易mumu:
【win版】
adb connect 127.0.0.1:7555
adb shell
【mac版】
adb kill-server && adb server && adb shell
apk 安装与卸载
1、应用中心下载安装
2、本地安装(比如应用宝-应用商店)
3、命令行安装
adbb install /path/to/**.apk
appPackage , appActivity
appPackage 包名, 每个应用都有的唯 一标识
appActivity 页面的名字,每个页面都有的名字
如何获取?
命令:
Mac/Linux:
adb logcat |grep -i activitymanager
Windows:
adb logcat |findstr /i activitymanager
demo:
10-29 20:59:44.563 441 2952 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.tencent.mobileqq/.activity.SplashActivity bnds=[848,1232][1103,1713]} from uid 1000 on display 0
adb shell am start -n 包名/包名+activity名
例如:
adb shell am start -n com.tencent.wework/.launch.LaunchSplashActivity
参考链接
SDK安装:Android Studio安装(推荐使用这种方法安装SDK)
参考代码
https://github.com/ceshiren/HogwartsSDET15
作业
完成企业微信自动打卡测试用例。
课后反馈调查表
chenchen
(尘世风)
2
作业:https://github.com/shifengboy/SFDSZL/blob/master/test_appium/test_workweixin.py
wth
(吴天昊)
4
test_yao
(叮叮咚咚)
6
zwk
(草帽)
8
79499040
(超超)
10
32712784
(吴小鹏)
12
872332156
(Dandi)
13
sh2
(风息)
17
799256545
(wealth)
18
Allon
(风中的云)
19
kino
(kino)
20
代码路径:https://github.com/KinoLiang/app
1.先在主页面https://github.com/KinoLiang/app/blob/main/page/main_page.py 添加进入工作台
def goto_workplat(self):
“”"
进入到工作台页
:return:
“”"
self.find_and_click(*self.workplat_element)
return WorkplatPage(self.driver)
2.新增工作台页面封装https://github.com/KinoLiang/app/blob/main/page/workplat_page.py ,添加点击【打卡】图标进入到打卡页面
class WorkplatPage(BasePage):
def goto_attendance(self):
# 滚动查找【打卡】
self.find_by_scroll('打卡').click()
return AttendancePage(self.driver)
3.新增打卡页面https://github.com/KinoLiang/app/blob/main/page/attendance_page.py ,封装打卡页面的操作
class AttendancePage(BasePage):
hiy_element = (MobileBy.XPATH, "//[@text=‘外出打卡’]")
aty_element = (MobileBy.XPATH, '//[contains(@text, “次外出”)]')
def goto_hiy_page(self):
"""
进入到外出打卡
:return:
"""
self.find_and_click(*self.hiy_element)
def click_attendance(self):
"""
点击进行打卡
:return:
"""
self.find_and_click(*self.aty_element)
4.在用例https://github.com/KinoLiang/app/blob/main/testcase/test_attendance.py 中进行实例化调用
class TestAttendance:
def setup_class(self):
# 初始化driver和启动app
self.app = App()
self.driver = self.app.start()
# 切换到【工作台】
self.workplat = MainPage(self.driver).goto_workplat()
# 切换到【打卡】页面
self.attendance = self.workplat.goto_attendance()
def teardown(self):
self.driver.back()
def test_attendance(self):
# 调用打开页面的【外出打卡】
self.attendance.goto_hiy_page()
# 调用打卡操作
self.attendance.click_attendance()
'''
# 方法1:打印page_source,前面必须加强等
sleep(2)
print(self.driver.page_source)
assert "外出打卡成功" in self.driver.page_source
'''
# 方法2:显式等待
WebDriverWait(self.driver, 10).until(lambda x: "外出打卡成功" in x.page_source)
def teardown_class(self):
self.driver.quit()
5.最终执行效果
============================= 1 passed in 30.41s ==============================
CreateFile() Error: 2
Process finished with exit code 0
INFO:root:click
INFO:root:xpath
INFO:root://[@text=‘工作台’]
INFO:root:find_by_scroll
INFO:root:打卡
INFO:root:click
INFO:root:xpath
INFO:root://[@text=‘外出打卡’]
INFO:root:click
INFO:root:xpath
INFO:root://*[contains(@text, “次外出”)]
PASSED