import random
import unittest
from appium import webdriver
from time import sleep
from HTMLTestRunner import HTMLTestRunner
import time
import pppyyy
# 写在前面,将手机USB调试权限打开,将充电不熄屏打开,已经绑定手环,更好AGPS
class Dttest(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("start setup")
desired_caps = {
‘platformName‘: ‘Android‘, # 被测手机是安卓
‘platformVersion‘: ‘10‘, # 手机安卓版本
‘deviceName‘: ‘xxx‘, # 设备名,安卓手机可以随意填写
‘appPackage‘: ‘com.honbow.fitdock‘, # 启动APP Package名称
‘appActivity‘: ‘com.honbow.letsfit.HBActivity‘, # 启动Activity名称
#‘unicodeKeyboard‘: True, # 使用自带输入法,输入中文时填True
#‘resetKeyboard‘: True, # 执行完程序恢复原来输入法
‘noReset‘: True, # 不要重置App
‘newCommandTimeout‘: 6000,
‘automationName‘: ‘UiAutomator2‘
}
# 连接Appium Server,初始化自动化环境
cls.driver = webdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps)
# 设置缺省等待时间
cls.driver.implicitly_wait(5)
# cls.driver.find_element_by_class_name("android.widget.Button").click() # 测试版本加本行代码,非测试版本不用
cls.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/e.b.a.a.c[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ImageView").click()
cls.driver.find_element_by_id("layout_desc").click()
cls.driver.find_element_by_id("rl_download_dial").click()
@classmethod
def tearDownClass(cls):
print("over")
def test_bp1(self):
bp1 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.LinearLayout/android.widget.TextView[2]")
bp1.click()
count = 0
while True:
count = count + 1
sleep(1)
# print(count)
if bp1.text == "当前表盘":
print(count)
break
elif count > 60*3:
pppyyy.screenmap("bpone{}.png".format(random.randint(0,10000)))
break
self.assertEqual(bp1.text, "当前表盘")
def test_bp2(self):
bp2 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.TextView[2]")
bp2.click()
count = 0
while True:
count = count + 1
sleep(1)
print(count)
if bp2.text == "当前表盘":
print(count)
break
elif count > 60*3:
pppyyy.screenmap("bpone{}.png".format(random.randint(0,10000)))
break
self.assertEqual(bp2.text, "当前表盘")
def test_bp3(self):
bp3 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[3]/android.widget.LinearLayout/android.widget.TextView[2]")
bp3.click()
count = 0
while True:
count = count + 1
sleep(1)
print(count)
if bp3.text == "当前表盘":
print(count)
break
elif count > 60*3:
pppyyy.screenmap("bpone{}.png".format(random.randint(0,10000)))
break
self.assertEqual(bp3.text, "当前表盘")
def test_bp4(self):
bp4 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[4]/android.widget.LinearLayout/android.widget.TextView[2]")
bp4.click()
count = 0
while True:
count = count + 1
sleep(1)
#print(count)
if bp4.text == "当前表盘":
print(count)
break
elif count > 60*3:
pppyyy.screenmap("bpone{}.png".format(random.randint(0,10000)))
break
self.assertEqual(bp4.text, "当前表盘")
def test_bp5(self):
bp5 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[5]/android.widget.LinearLayout/android.widget.TextView[2]")
bp5.click()
count = 0
while True:
count = count + 1
sleep(1)
print(count)
if bp5.text == "当前表盘":
print(count)
break
elif count > 60*3:
pppyyy.screenmap("bpone{}.png".format(random.randint(0,10000)))
break
self.assertEqual(bp5.text, "当前表盘")
# def test_bp6(self):
# self.driver.swipe(600, 1000, 600, 300, duration=3000)
# bp2 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[6]/android.widget.LinearLayout/android.widget.TextView[2]")
# bp2.click()
# sleep(40)
# if bp2.text != "当前表盘":
# pppyyy.screenmap("bptwo{}.png".format(random.randint(0,10000)))
# self.assertEqual(bp2.text, "当前表盘")
#
# def test_bp7(self):
# self.driver.swipe(600, 1000, 600, 300, duration=3000)
# bp2 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[7]/android.widget.LinearLayout/android.widget.TextView[2]")
# bp2.click()
# sleep(60)
# if bp2.text != "当前表盘":
# pppyyy.screenmap("bptwo{}.png".format(random.randint(0,10000)))
# self.assertEqual(bp2.text, "当前表盘")
#
# def test_bp8(self):
# self.driver.swipe(600, 1000, 600, 300, duration=3000)
# bp2 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[8]/android.widget.LinearLayout/android.widget.TextView[2]")
# bp2.click()
# sleep(60)
# if bp2.text != "当前表盘":
# pppyyy.screenmap("bptwo{}.png".format(random.randint(0,10000)))
# self.assertEqual(bp2.text, "当前表盘")
#
# def test_bp9(self):
# self.driver.swipe(600, 1000, 600, 300, duration=3000)
# bp2 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[9]/android.widget.LinearLayout/android.widget.TextView[2]")
# bp2.click()
# sleep(40)
# if bp2.text != "当前表盘":
# pppyyy.screenmap("bptwo{}.png".format(random.randint(0,10000)))
# self.assertEqual(bp2.text, "当前表盘")
#
# def test_bp10(self):
# self.driver.swipe(600, 1000, 600, 300, duration=3000)
# bp2 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[10]/android.widget.LinearLayout/android.widget.TextView[2]")
# bp2.click()
# sleep(70)
# if bp2.text != "当前表盘":
# pppyyy.screenmap("bptwo{}.png".format(random.randint(0,10000)))
# self.assertEqual(bp2.text, "当前表盘")
if __name__ == ‘__main__‘:
for i in range(20):
suite = unittest.TestSuite()
suite.addTest(Dttest("test_bp1"))
suite.addTest(Dttest("test_bp2"))
suite.addTest(Dttest("test_bp3"))
suite.addTest(Dttest("test_bp4"))
suite.addTest(Dttest("test_bp5"))
# suite.addTest(Dttest("test_bp6"))
# suite.addTest(Dttest("test_bp7"))
# suite.addTest(Dttest("test_bp8"))
now_time = time.strftime("%Y-%m-%d %H_%M_%S")
fp = open(‘./report/‘ + now_time + ‘result.html‘, ‘wb‘)
runner = HTMLTestRunner(stream=fp,
title="3+PRO",
description="运行环境:Windows 10, redmi10X"
)
runner.run(suite)
fp.close()
自动化压测表盘传输工具