python selenium ddt data-driven testing (eight)

6, test case

14633667-b512845aed32ab0a.png

test_gateway.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-04-15 09:00:00
# @Author  : Canon
# @Link    : https://www.python.org
# @Version : 3.6.1

import re
import unittest
import ddt
from common.browser import get_driver
from common.excel_utils import ExcelUtils as Exc
from common.logger import Log
from common.conf_utils import Gateway
from action.gateway import pay as Pa
from action.gateway import threepay as Tp
from action.gateway import threequick as Tq
from action.gateway import twopay as Twp
from action.gateway import twoquick as Twq
from action.gateway import twohalfpay as Thp
from action.gateway import twohalfquick as Thq
from action.gateway import result as Res
from action.home.gateway import Home

# 日志
log = Log()


@ddt.ddt
class TestGateway(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # 浏览器驱动
        cls.driver = get_driver()
        log.info("----- 启动浏览器 -----")
        # 浏览器最大化
        cls.driver.maximize_window()
        # 测试地址
        cls.addr = "http://xxx/test"
        # 接口类型
        cls.create = "3"
        cls.pay = "2"

    @classmethod
    def tearDownClass(cls):
        log.info("----- 关闭浏览器 -----")
        cls.driver.close()

    def setUp(self):
        # 获取支付域名列表数据
        self.payval = Gateway().read_domain("domain")

    def tearDown(self):
        pass

    @ddt.data(*Exc(Gateway().read_path("xlsx", "threepay"), "PayPage").list_in_dict())
    def test_threepay(self, test_data):
        # 进入 测试
        Home(self.driver).enter_three()
        # 提交 3方支付
        addr_thr = self.addr + Gateway().read_val("addr", "thr")
        Tp.Action(self.driver).put_three(addr_thr, test_data["终端ID"][:6], test_data["终端ID"])
        # 信用卡支付
        domain = re.findall(r"/\w+/\w+\.", self.driver.current_url)[0].replace(".", "")
        for val in self.payval:
            for domain_conf in val[1].split(","):
                if domain == domain_conf.strip():
                    getattr(Pa.PayAction(self.driver), val[0])(test_data)
                    break
        # 断言:测试结果与预期结果对比
        self.assertEqual(test_data['payment_details'], Res.Back(self.driver).back_datails())
        self.assertEqual(test_data['payment_status'], Res.Back(self.driver).back_status())


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

7, the test report

Generate test reports based on HTMLTestRunner.py public methods of common

14633667-8db526eb58d27d61.png

I reproduced in: https: //www.jianshu.com/p/3d742e1c875f

Guess you like

Origin blog.csdn.net/weixin_33912453/article/details/91057450