Skip to main content

xiaobaiauto framework 简化Web与接口等自动化实现及日志搜集、报告生成、邮件发送等功能

Project description

xiaobaiauto

介绍

简化现有Selenium、Requests等框架对于页面及接口的操作,也扩展了日志搜集、报告生成、 邮件发送等功能

版本说明

版本:   功能:                        实现:
1.*     只支持Web端                    √
2.*     支持Web+API端                  √
3.*     支持Web+API+APP端              ×
4.*     支持Web+API+APP+Pref           ×
5.*     支持Web+API+APP+Pref+Mock      ×

软件架构

集成了Selenium、SMTP、HTMLTestRunner、logging、Reuqests等模块

安装教程

pip install xiaobaiauto

使用代码之前请确保您的电脑中已经安装好浏览器及对应的驱动内容

chromedriver下载

chrome与chromdriver驱动之间存在不兼容问题,所以最好都下载最新版本为最佳效果

Case文件实例

import unittest
from xiaobaiauto.xiaobaiauto import pageObject, Report, log, EmailHandler, Api

class MyTestCase(unittest.TestCase):
    def setUp(self):
        """
            初始化日志
        :return:
        """
        self.logger = log()
        self.client = Api()
        self.page = pageObject()

    def test_api_xxx(self):
        headers = {'content-type': 'application/json'}
        json = {'type': 1, 'orderno': 'abcdef'}
        path = 'http://127.0.0.1:8080/api/v/1.0/'
        json_res = self.client.api('post', url=path, json=json, headers=headers).json()
        try:
            self.assertEqual(json_res.get('successful'), 'true')
            self.logger.info('xxx接口请求成功')
        except:
            self.logger.error('xxx接口请求失败')
        # self.logger.debug('调试日志信息')
        # self.logger.warning('警告日志信息')
        # self.logger.error('错误日志信息')

    def test_web_xxx(self):
        button_name = self.page.xpath('//a[@type="xiao" and @name="bai"]')
        button_name.click()
        input_name = self.page.xpath('//input[@id="search"]')
        input_name.send_keys("睡觉")
        try:
            self.assertEqual(self.page.title(), '小白首页')
            self.logger.info('xxx接口请求成功')
        except:
            self.logger.error('xxx接口请求失败')

    def tearDown(self):
        pass

if __name__ == '__main__':
    report_file_name = 'TestReport.html'
    suite = unittest.TestSuite()
    # 添加测试用例
    suite.addTest(MyTestCase)
    fp = open(report_file_name, 'wb')
    #   生成报告
    runner = Report(
        stream=fp,
        title='测试',
        description='备注信息',
        tester='Tser'
    )
    runner.run(suite)
    fp.close()
    #  将测试报告发送指定邮件
    email = EmailHandler(smtp='smtp.qq.com', port=25, sender_name='qq号', sender_passwd='邮箱密码')
    email.sendemail(
        _to='接收者邮箱',
        _cc='抄送者邮箱',
        title='邮件标题',
        email_content='邮箱内容',
        _type='html',
        filename=report_file_name
    )
    email.quit()

提示

QQ邮箱或者其它企业邮箱必须提前开启SMTP服务

点击这里了解QQ邮箱如何开启SMTP服务

参与贡献

作者: @Tser
©小白科技

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xiaobaiauto-2.0.0.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distribution

xiaobaiauto-2.0.0-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page