Appium基于Python unittest自动化测试 & 自动化测试框架 -- PO并生成html测试报告
基于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测试报告的更多相关文章
- Appium基于python unittest自动化测试并生成html测试报告
本文基于python单元测试框架unittest完成appium自动化测试,生成基于html可视化测试报告 代码示例: #利用unittest并生成测试报告 class Appium_test(uni ...
- 简单实现接口自动化测试(基于python+unittest)
简单实现接口自动化测试(基于python+unittest) 简介 本文通过从Postman获取基本的接口测试Code简单的接口测试入手,一步步调整优化接口调用,以及增加基本的结果判断,讲解Pytho ...
- 基于Python的selenuim自动化测试尝试
工作这么多年了,终于狠下心好好开始学学自动化测试相关知识,揭开这层神秘的面纱. 困难重重,障碍很多,但好在每天都多少有点小收获. 很感谢一个QQ好友推荐的虫师,也非常感谢在这个契机读到了虫师编著的&l ...
- selenium+python+unittest实现自动化测试(入门篇)
本文主要讲解关于selenium自动化测试框架的入门知识点,教大家如何搭建selenium自动化测试环境,如何用selenium+python+unittest实现web页面的自动化测试,先来看看se ...
- Python Unittest 自动化单元测试框架Demo
python 测试框架(本文只涉及 PyUnit) https://wiki.python.org/moin/PythonTestingToolsTaxonomy 环境准备 首先确定已经安装有Pyth ...
- 符号执行-基于python的二进制分析框架angr
转载:All Right 符号执行概述 在学习这个框架之前首先要知道符号执行.符号执行技术使用符号值代替数字值执行程序,得到的变量的值是由输入变 量的符号值和常量组成的表达式.符号执行技术首先由Kin ...
- ShutIt:一个基于 Python 的 shell 自动化框架
ShutIt是一个易于使用的基于shell的自动化框架.它对基于python的expect库(pexpect)进行了包装.你可以把它看作是“没有痛点的expect”.它可以通过pip进行安装. Hel ...
- python用unittest+HTMLTestRunner的框架测试并生成测试报告
直接贴代码: import unittestfrom selenium import webdriverfrom time import sleepimport osimport time # 定义打 ...
- python unittest自动测试框架
编写函数或者类时进行测试,确保代码正常工作 python unittest 模块提供了代码测试工具.按照定义测试包括两部分:管理测试依赖库的代码(称为‘固件’)和测试本身. 单元测试用于核实函数的某 ...
随机推荐
- 【绘图技巧】ps快捷键的用法
Ctrl+N:新建画布 Ctrl+O:打开对话框 F: 在三种画布中切换 Z:缩放工具(临时) Ctrl+0:满画面显示 空格:切换到手(临时) Ctrl+":网 ...
- NSLog( @"%@", i );
NSLog( @"%@", i ); %@需要显示对象,所以这个i必须是个对象类型.
- 顺序一致性内存模型与JMM的“顺序一致性”
顺序一致性内存模型是一个被计算机科学家理想化了的理论参考模型,它为程序员提供了极强的内存可见性保证.顺序一致性内存模型有两大特性.1)一个线程中的所有操作必须按照程序的顺序来执行.2)(不管程序是否同 ...
- FORTH 安装使用
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- linux根据端口号查询来源程序
1.根据端口号查询进程 netstat -tunlp|grep port 2.根据进程查询来源程序 ps aux | grep pid 上图看出所属进程为2281 上图看出占用8083端口的程序为n ...
- win7下JAVA环境变量配置方法
1.首先,根据自己的需要下载1.6或者1.7的JDK,安装JDK.(安装的时候记一下安装目录,后面会用到) 2.右键计算机→属性→高级系统设置→高级→环境变量,在系统变量部分新建名为"JAV ...
- String.Format 格式化货币的小问题
今天在开发过程中,遇到一件让我觉得比较纳闷的事情:用String.Format 格式化充值金额的时候,我这样处理: String.Format("{0:C2}", dr[" ...
- android adapter 中添加OnClickListener事件
public class SearchAutoAdapter extends BaseAdapter { private OnClickListener mOnClickListener; publi ...
- MySQL中, 如何查询某一天, 某一月, 某一年的数据.
今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天(包括昨天和今天的数据) SELECT * FROM 表名 WHERE TO_ ...
- 18_Python列表常用方法总结
''' 1.列表切片索引\截取 2.列表的增删改查 3.列表最大值\列表最小值\排序 4.列表的遍历 5.列表的嵌套 6.列表和字符串的互转 7.判断元素是否在列表中 ''' #列表使用中括号表示 元 ...