目录
appPackage 和appActivity 的获取:连接手机 dos 输入
Pycharm引入插件Appium-Python-Client----关联Appium 和Python
整体知识框架
环境准备 (windows)
1.jdk1.8.0 (64位)
2.android-sdk(直接下载安卓studio就都有了)
3.python:3.7
4.Appium-windows-1.15.1
5.Node.js
//以上安装并配置好环境变量
6.Appium-Python-Client
7.pycharm(用于编写脚本)
8.HTMLTestReportCN(用于生成测试报告)
//以下可选
yaml
//以下两个是为了定时执行用例和发送测试报告——可不用安装
9.Tomcat
10.Jenkins
appium安装和使用
官网地址:https://github.com/appium/appium-desktop/releases/tag/v1.15.1
下载后安装即可
deviceName 可通过adb devices 得到
appPackage 和appActivity 的获取:连接手机 dos 输入
adb shell dumpsys window | findstr mCurrentFocus
Pycharm引入插件Appium-Python-Client----关联Appium 和Python
HTMLTestReportCN----生成测试报告
下载并放入python 目录lib文件夹下
官网:https://github.com/findyou/HTMLTestRunnerCN
HTMLTestReportCN是unittest 拓展插件,二者配合使用
修改后的测试用例代码 :
测试用例二:FirstTest
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
import time
import unittest
from HTMLTestRunnerCN import HTMLTestReportCN
caps = {}
caps["platformName"] = "Android"
caps["platformVersion"] = "10"
caps["deviceName"] = "R28M3126C2W"
caps["appPackage"] = "cn.cntv"
caps["appActivity"] = "cn.cntv.ui.activity.SplashActivity"
class FirstTest(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
def tearDown(self) -> None:
self.driver.quit()
def test_start(self):
el1 = self.driver.find_element_by_id("com.android.permissioncontroller:id/permission_allow_button")
el1.click()
time.sleep(10)
el2 = self.driver.find_element_by_id("com.android.permissioncontroller:id/permission_allow_always_button")
el2.click()
time.sleep(10)
el3 = self.driver.find_element_by_id("com.android.permissioncontroller:id/permission_allow_button")
el3.click()
time.sleep(10)
el4 = self.driver.find_element_by_id("cn.cntv:id/agree")
el4.click()
time.sleep(10)
el5 = self.driver.find_element_by_xpath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.TextView")
el5.click()
el6 = self.driver.find_element_by_xpath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.LinearLayout[3]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.TextView")
el6.click()
el7 = self.driver.find_element_by_xpath(