基于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基于PO模型的自动化测试(Python)的更多相关文章

  1. Appium基于Python unittest自动化测试 & 自动化测试框架 -- PO并生成html测试报告

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

  2. Appium+Python之PO模型(Page object Model)

    思考:我们进行自动化测试时,如果把代码都写在一个脚本中,代码的可读性会变差,且后期代码维护也麻烦,最好的想法就是测试对象和测试用例可以分离,可以很快定位问题,代码可读性高,也比较容易理解.这里推荐大家 ...

  3. 移动端自动化测试Appium 从入门到项目实战Python版☝☝☝

    移动端自动化测试Appium 从入门到项目实战Python版 (一个人学习或许会很枯燥,但是寻找更多志同道合的朋友一起,学习将会变得更加有意义✌✌)  说到APP自动化测试,Appium可是说是非常流 ...

  4. 【Selenium07篇】python+selenium实现Web自动化:PO模型,PageObject模式!

    一.前言 最近问我自动化的人确实有点多,个人突发奇想:想从0开始讲解python+selenium实现Web自动化测试,请关注博客持续更新! 这是python+selenium实现Web自动化第七篇博 ...

  5. Selenium+Python ---- 免登录、等待、unittest单元测试框架、PO模型

    1.免登录在进行测试的过程中难免会遇到登录的情况,给测试工作添加了工作量,本文仅提供一些思路供参考解决方式:手动请求中添加cookies.火狐的profile文件记录信息实现.人工介入.万能验证码.去 ...

  6. 基于 Agent 的模型入门:Python 实现隔离仿真

    2005 年诺贝尔经济学奖得主托马斯·谢林(Thomas Schelling)在上世纪 70 年代就纽约的人种居住分布得出了著名的 Schelling segregation model,这是一个 A ...

  7. selenium3 web自动化测试框架 三:项目实战中PO模型的设计与封装

    po模型设计思想 Page Object 模式主要是将每个页面设计为一个class,其中包含页面中的需要测试的元素(按钮,输入框,标题等),这样在Selenium测试页面中可以通过调取页面类来获取页面 ...

  8. 移动端自动化测试appium 从入门到项目实战Python版✍✍✍

    移动端自动化测试appium 从入门到项目实战Python版 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程 ...

  9. 移动端自动化测试Appium 从入门到项目实战Python版

    移动端自动化测试Appium 从入门到项目实战Python版  整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课 ...

随机推荐

  1. DesignPattern系列__09设计模式概述

    设计模式介绍 设计模式是程序员在面对同类软件工程设计问题所总结出来的有用的经验,模式不是代码,而是某类问题的通用解决方案, 设计模(Design pattern)代表了最佳的实践.这些解决方案是众多软 ...

  2. [b0038] python 归纳 (二三)_多进程数据共享和同步_队列Queue

    1  队列读写 # -*- coding: utf-8 -*- """ 多进程 共享 队列 multiprocessing.Process 逻辑: 一个进程往队列写数据, ...

  3. Angular 学习笔记(三)

    调试时抓取作用域: 1.右键选取审查元素,调出 debugger(或按 F12) 2.调试器允许用变量 $0 来获取当前选取的元素 3.在 console 中执行 angular.element($0 ...

  4. 事务的四大性质:ACID

    1. 原子性(Atomicity) 一个原子事务要么完整执行,要么干脆不执行.这意味着,工作单元中的每项任务都必须正确执行.如果有任一任务执行失败,则整个工作单元或事务就会被终止.即此前对数据所作的任 ...

  5. CodeForces-1253B(贪心+模拟)

    题意 https://vjudge.net/problem/CodeForces-1253B 把一个序列划成几段,使得每一段都是+x在-x前面,二者均要有. 问划成几段,每一段的大小是多少. 思路 用 ...

  6. GitHub密钥生成

    前提电脑上需装有Git软件 这里提供百度云下载地址:https://pan.baidu.com/s/1r0y4XRyQCz7ZJBnZJhAtqw 提取码:88qf  1.登录GitHub账号 2.点 ...

  7. Redis学习笔记(八、缓存设计)

    目录: 缓存更新策略 缓存粒度 缓存穿透 缓存雪崩 缓存击穿 缓存更新策略: 1.内存溢出淘汰策略 当redis的使用内存超过maxmemory时会触发相应的策略,具体策略由maxmemory-pol ...

  8. 密度聚类 - DBSCAN算法

    参考资料:python机器学习库sklearn——DBSCAN密度聚类,     Python实现DBScan import numpy as np from sklearn.cluster impo ...

  9. 第九章 基于HTTP的功能追加协议

    第九章 基于HTTP的功能追加协议 通过在HTTP的基础上添加新的功能来提高性能和功能. 一.消除HTTP瓶颈的SPDY SPDY(SPeeDY)目的是提高HTTP性能,缩短Web页面的加载时间(50 ...

  10. mq代替db

    系统有个很严重的性能问题,法国人浪费了半年多都没有解决,他们试图从sql的角度分析哪里能有改善,大方向错了,再努力也没用. 我接手以后,也走了点弯路,一上手觉得肯定能用cache解决问题,结果cach ...