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 模块提供了代码测试工具.按照定义测试包括两部分:管理测试依赖库的代码(称为‘固件’)和测试本身. 单元测试用于核实函数的某 ...
随机推荐
- Struts 2 标签库及使用
1 Struts 2 基本的标签属性. 1) name:指定表单元素的名称,该属性与Action中定义的属性相对应. 2) value:指定表单元素的值. 3) required:指定表单元素的必填 ...
- 20170505 PHP实践中知识点
1.json_encode 不转义 2.empty() 与 isset() 区别 在使用 php 编写页面程序时,我经常使用变量处理函数判断 php 页面尾部参数的某个变量值是否为空,开始的时候我习惯 ...
- 针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行
<?php//针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行,http://ken.01h.net/define('PHP_LOCK_FILE', dirname(__FILE__ ...
- python_14_生成器
什么是生成器? -- 动态的生成有规律的列表和元组,查询多少才会生成多少数据,不需要时数据不存在 - 大到10几万数据,就省空间了 什么是列表生成式? -- [ handle_i_result for ...
- python_大学排名爬取
逻辑思路是什么? 1. 获取页面 2. 处理页面,提取信息 3. 格式输出 先走面向过程编程: 1. 要定义3个函数,对应以上三个过程 2. 在__main__函数中传入参数,并执行以上三个过程 #! ...
- 防盗链[referer]
原文出处:http://www.cnblogs.com/devilfree/archive/2012/09/11/2680914.html 总结一下今天学习防盗链Filter的一些知识点: 防盗链要实 ...
- SQL 2005/2008 连接SQL 2000报18456错误
在看文章前,你先看看下面这两个问题,考考你对MSSMS工具的掌握情况: 1: SQL 2005/2008 能连接 SQL 2000数据库服务器吗? 2: SQL 2000 能连接SQL 2005/20 ...
- IO (二)
1 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应的类: BufferedWriter BufferedReader 缓冲区要结合流才能使用. 在流的基础上对流的功能进行了增强. 2 Bu ...
- Spring 当 @PathVariable 遇上 【. # /】等特殊字符
@PathVariable注解应该不是新鲜东西了Spring3.0就开始有了 URL中通过加占位符把参数传向后台 举个栗子,如下比较要说的内容比较简单就大概齐的写一下 画面侧 $.ajax({ typ ...
- copy-webpack-plugin最简使用示例
拷贝文件的插件 加载插件 $ npm install copy-webpack-plugin --save-dev API new CopyWebpackPlugin(patterns: Array, ...