自动化测试框架(一)

初到新公司,自己琢磨着写一套Android手机的自动化测试框架,于是在网上走访各博客,论坛。参考了许多牛人的文章,尝试搭建了一个自动化测试框架。

整个框架使用的Python 语言。

框架简介:此框架是对 Android Uiautomator 的Python封装,支持Android4.1及以上版本。 需要安装Android SDK,设置ANDROID_HOME环境变量以及 adb环境。

框架原理:通过建立json-RPC服务,实现PC(client端)到手机(RPC server端)的远程控制

框架优点:脚本编写简单。相比于原生的uiautomator,需要编写Java代码,build文件,编译jar包,push到手机端执行

实现功能 1)UI操作与按键事件;   2)执行结果检测(文本检测,控件检测,图片对比);   3)用例批量执行 ;  4)生成测试报告  ; 5)抓取手机log

框架结构:

 

脚本代码:

#-*- coding:utf-8 -*-
'''
用例标题:检查联系人界面显示
测试步骤:
1.无联系人时检查界面显示;
预期结果:
1.显示新建联系人,导入联系人,从云端导入,其他手机导入四个选项;
'''
from aw import * 

######################################             
TAG=__file__.split("\\")[-1]         
TAG = TAG.split('.')[0]              
######################################
class TestScript(unittest.TestCase):
    def setUp(self):
        Common(DUT).goHome()
    def test_step(self):
        for i in range(LOOP.loop1):
            Common(DUT).clickByText("联系人",screeScroll=True,direction="left_right")
            Common(DUT).wait(1)
        
            result = Checkpoint(DUT).checkIfExist("检测点1",text="扫名片") \
            and Checkpoint(DUT).checkIfExist("检测点2",text="新建联系人")\
            and Checkpoint(DUT).checkIfExist("检测点3",text="导入联系人") \
            and Checkpoint(DUT).checkIfExist("检测点4",text="扫二维码")
            self.assertEqual(result, True)
            
    def tearDown(self):
        Common(DUT).goBack(1)
        Common(DUT).goHome()
        Common(DUT).clearRecentApp()

if __name__ == "__main__":
    unittest.main()

测试报告:

报告生成 参考 HTMLTestRunner库, http://www.cnblogs.com/Roger1227/p/3327311.html

有感兴趣的可以留言探讨。

posted on 2017-02-22 11:04  改改哥  阅读(379)  评论(0编辑  收藏  举报