基于python单元测试框架unittest完成appium自动化测试,生成基于html可视化测试报告

代码示例:

 #利用unittest并生成测试报告
class Appium_test(unittest.TestCase):
"""appium测试类"""
def setUp(self):
desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',#可有可无,这里是指我的模拟器
'platformVersion': '5.0',
# apk包名
'appPackage': 'com.smartisan.notes',
# apk的launcherActivity
'appActivity': 'com.smartisan.notes.NewNotesActivity',
#如果存在activity之间的切换可以用这个
# 'appWaitActivity':'.MainActivity',
'unicodeKeyboard': True,
#隐藏手机中的软键盘
'resetKeyboard': True
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
time.sleep()
self.verificationErrors = "今天天气不错在家学习!" #设置的断言 def tearDown(self):
time.sleep()
assertt = self.driver.find_element_by_id("com.smartisan.notes:id/list_rtf_view").text
# print(assertt) #调试用
self.assertEqual(assertt,self.verificationErrors,msg="验证失败!")
#断言:实际结果,预期结果,错误信息
self.driver.quit() def test_creat(self):
"""记事本中新增一条记录"""
self.driver.find_element_by_id("com.smartisan.notes:id/add_button").click()
time.sleep()
self.driver.find_element_by_class_name("android.widget.EditText").send_keys("今天天气不错在家学习!")
self.driver.find_element_by_id("com.smartisan.notes:id/send_finish_button").click() suite = unittest.TestSuite()
suite.addTest(Appium_test('test_creat')) report_file = ".\\appium_report.html"
fp = open(report_file,'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="appium测试报告",description='新增一条笔记并保存')
runner.run(suite)
fp.close()

生成测试报告:

Appium自动化测试PO模型:

其中,main.py为框架的主入口,test_creat.py调用creat_page.py,creat_page.py调用base_page.py。

PO代码示例:

main.py

 import unittest
import HTMLTestRunner #相对路径
testcase_path = ".\\testcase"
report_path = ".\\report\\appium_report.html"
def creat_suite():
uit = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(testcase_path,pattern="test_*.py")
for test_suite in discover:
# print(test_suite)
for test_case in test_suite:
uit.addTest(test_case)
return uit suite = creat_suite()
fp = open(report_path,"wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="测试结果",description="appium新建笔记测试结果")
runner.run(suite)
fp.close()

test_creat.py

 from appium import webdriver
import unittest
from appiumframework.PO.creat_page import CreatPage
import time class Test(unittest.TestCase):
"""自动化"""
def setUp(self):
desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',#可有可无
'platformVersion': '5.0',
# apk包名
'appPackage': 'com.smartisan.notes',
# apk的launcherActivity
'appActivity': 'com.smartisan.notes.NewNotesActivity',
#如果存在activity之间的切换可以用这个
# 'appWaitActivity':'.MainActivity',
'unicodeKeyboard': True,
#隐藏手机中的软键盘
'resetKeyboard': True
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
time.sleep(5)
self.verificationErrors = "今天天气不错在家学习!" def tearDown(self):
time.sleep(10)
self.driver.quit() def test_saveedittext(self):
"""保存编辑的文本"""
sp = CreatPage(self.driver)
sp.add_button_link()
sp.run_case("今天天气不错在家学习!")
#断言:实际结果,预期结果,错误信息
self.assertEqual(sp.get_finish_button_text(),self.verificationErrors,msg="验证失败!")

creat_page.py

 from appiumframework.PO import base_page
import time class CreatPage(base_page.Action):
add_button_loc = ("com.smartisan.notes:id/add_button")
edittext_loc = ("com.smartisan.notes:id/list_rtf_view")
finish_button_loc = ("com.smartisan.notes:id/send_finish_button") def add_button_link(self):
self.find_element(self.add_button_loc).click()
time.sleep(3) #等待3秒,等待登录弹窗加载完成 def run_case(self,value):
self.find_element(self.edittext_loc).send_keys(value)
time.sleep(5)
self.find_element(self.finish_button_loc).click()
time.sleep(2) def get_finish_button_text(self):
return self.find_element(self.edittext_loc).text

base_page.py

 class Action(object):
#初始化
def __init__(self,se_driver):
self.driver = se_driver #重写元素定位的方法
def find_element(self,loc):
try:
return self.driver.find_element_by_id(loc)
except Exception as e:
print("未找到%s"%(self,loc))

测试报告截图:

Appium基于Python unittest自动化测试 & 自动化测试框架 -- PO并生成html测试报告的更多相关文章

  1. Appium基于python unittest自动化测试并生成html测试报告

    本文基于python单元测试框架unittest完成appium自动化测试,生成基于html可视化测试报告 代码示例: #利用unittest并生成测试报告 class Appium_test(uni ...

  2. 简单实现接口自动化测试(基于python+unittest)

    简单实现接口自动化测试(基于python+unittest) 简介 本文通过从Postman获取基本的接口测试Code简单的接口测试入手,一步步调整优化接口调用,以及增加基本的结果判断,讲解Pytho ...

  3. 基于Python的selenuim自动化测试尝试

    工作这么多年了,终于狠下心好好开始学学自动化测试相关知识,揭开这层神秘的面纱. 困难重重,障碍很多,但好在每天都多少有点小收获. 很感谢一个QQ好友推荐的虫师,也非常感谢在这个契机读到了虫师编著的&l ...

  4. selenium+python+unittest实现自动化测试(入门篇)

    本文主要讲解关于selenium自动化测试框架的入门知识点,教大家如何搭建selenium自动化测试环境,如何用selenium+python+unittest实现web页面的自动化测试,先来看看se ...

  5. Python Unittest 自动化单元测试框架Demo

    python 测试框架(本文只涉及 PyUnit) https://wiki.python.org/moin/PythonTestingToolsTaxonomy 环境准备 首先确定已经安装有Pyth ...

  6. 符号执行-基于python的二进制分析框架angr

    转载:All Right 符号执行概述 在学习这个框架之前首先要知道符号执行.符号执行技术使用符号值代替数字值执行程序,得到的变量的值是由输入变 量的符号值和常量组成的表达式.符号执行技术首先由Kin ...

  7. ShutIt:一个基于 Python 的 shell 自动化框架

    ShutIt是一个易于使用的基于shell的自动化框架.它对基于python的expect库(pexpect)进行了包装.你可以把它看作是“没有痛点的expect”.它可以通过pip进行安装. Hel ...

  8. python用unittest+HTMLTestRunner的框架测试并生成测试报告

    直接贴代码: import unittestfrom selenium import webdriverfrom time import sleepimport osimport time # 定义打 ...

  9. python unittest自动测试框架

    编写函数或者类时进行测试,确保代码正常工作 python  unittest 模块提供了代码测试工具.按照定义测试包括两部分:管理测试依赖库的代码(称为‘固件’)和测试本身. 单元测试用于核实函数的某 ...

随机推荐

  1. block一点也不神秘————如何利用block进行回调

    我们在开发中常常会用到函数回调,你可以用通知来替代回调,但是大多数时候回调是比通知方便的,所以何乐而不为呢?如果你不知道回调使用的场景,我们来假设一下: 1.我现在玩手机 2.突然手机没有电了 3.我 ...

  2. C# 内置 DateTime类详解

    C# 内置 DateTime类详解 摘抄自微软官方文档,用来方便自己查阅:网址:https://msdn.microsoft.com/zh-cn/library/system.datetime(v=v ...

  3. 美国不同C段服务器,多ip服务器

    作为多IP服务器的拓展,多C段服务器,例如:IP分为4段,A段,B段,C段,D段.192.168.0.1/24代表着一个C段,可用IP段为192.168.0.1-255,一个C段有253个可用IP.一 ...

  4. 理解Python中的装饰器//这篇文章将python的装饰器来龙去脉说的很清楚,故转过来存档

    转自:http://www.cnblogs.com/rollenholt/archive/2012/05/02/2479833.html 这篇文章将python的装饰器来龙去脉说的很清楚,故转过来存档 ...

  5. Django_实现分页

    需求: 对于有很多数据,并不希望一次性全部展现在一个页面,需要一个分页的,定好每一页显示的内容 那,如何满足这个需求呢? 通过第三方模块  django-pure-pagination pip ins ...

  6. nginx服务器的作用与简单搭建(windows)

    Nginx是一款开源代码的反向代理服务器. 何为反向代理呢?即以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连 ...

  7. linkin大话数据结构--apache commons工具类

    Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动. 一.Commons BeanUtils 说明:针对Bean的一个工具集.由于Bean往往是有一堆ge ...

  8. k8s 如何 Failover?- 每天5分钟玩转 Docker 容器技术(127)

    上一节我们有 3 个 nginx 副本分别运行在 k8s-node1 和 k8s-node2 上.现在模拟 k8s-node2 故障,关闭该节点. 等待一段时间,Kubernetes 会检查到 k8s ...

  9. android CheckBox与监听

    <CheckBox  android:id="@+id/cb1"  android:layout_width="fill_parent"  android ...

  10. 简单的.editconfig文件

    root = true [*] charset = utf-8 indent_style = space indent_size = 2 end_of_line = lf insert_final_n ...