zoukankan      html  css  js  c++  java
  • Pycharm+Python+Unittest+HTMLTestRunner编写Android自动化测试一(环境搭建)

    本系列文章是针对Android手机自动化测试做的分享总结,方便以后工作中遇到可以随时查阅,首先搭建环境Python36,安装项目所用工具Pycharm等。

    工具下载安装

    Pycharm:https://ptest1234.ctfile.com/fs/16324556-289107881 (破解码地址:http://idea.lanyus.com/)

    Python36:https://ptest1234.ctfile.com/fs/16324556-289108039

    HTMLTestRunner:地址同上,存放位置在Python36安装目录,如:E:Python36Lib

    以上工具安装完成以后,需要导入所对应到资源文件:urllib3、uiautomator,安装方式有两种:

    1.使用工具Pycharm:打开工具-》File-》Settings-》project:项目名-》project Interpreter,如果没有的点击添加按钮,获取

    2.使用CMD命令方式安装,开始-》运行-》输入CMD,回车,命令窗口分别输入,等待下载安装:

    pip install uiautomator

    pip install urllib3

    Unittest案例事例

    # -*- coding:utf-8 -*-
    import sys
    import importlib
    importlib.reload(sys)
    
    import unittest
    import HTMLTestRunner,sys,StringIO
    import time
    import os
    from uiautomator import device as d
    
    class MyTestCase(unittest.TestCase):
        def setUp(self):
            #print 'aaa' 运行前先运行此函数
            pass
    
        def tearDown(self):   #所有用例运行完后,运行此函数
            pass
    
        def testCase1(self):
            self.assertEqual(2,2,"testError")
        def testCase2(self):
            self.assertEqual(2,2,"testError")
    
    
    #添加Suite
    
    def Suite():
        suiteTest = unittest.TestSuite()
        suiteTest.addTest(MyTestCase("testCase1"))
        suiteTest.addTest(MyTestCase("testCase2"))
        return suiteTest
    
    
    if __name__ == '__main__':
        # 确定生成报告的路径
        timer = time.strftime('%Y-%m-%d %H_%M_%S ', time.localtime(time.time()))
        filePath = timer+"pyResult.html"
        fp = open(filePath,'wb')
    
        # 生成报告的Title,描述
        runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='Python Test Report',description='This  is Python  Report')
        runner.run(Suite(1))
        fp.close()
  • 相关阅读:
    2020年寒假假期总结0210
    2020年寒假假期总结0209
    2020年寒假假期总结0208
    2020年寒假假期总结0207
    2020年寒假假期总结0206
    yolo-v4:Optimal Speed and Accuracy of Object Detection解析
    Docker 练习
    tensorflow2.0 GPU版本镜像文件
    flink项目实战
    高等数理统计知识点
  • 原文地址:https://www.cnblogs.com/ptest/p/10122732.html
Copyright © 2011-2022 走看看