zoukankan      html  css  js  c++  java
  • unittest 运行slenium(四)---通过指定用例的形式运行用例

    一: 说明

    跟数据驱动唯一的区别为用例数据获取时,及运行方式不同。

    其它都基本相同,可参考https://www.cnblogs.com/xiaodingdong/p/11753220.html

    二: 指定用例形式

    1. 读取excel的数据之后,通过”函数“这个列表名来作为pandas的新序号。 不需要将数据转换为list。 代码如下

    def excel_to_pandas(excel: str, sheet: str, title_name: str) -> object:
        """
        读取用例
        :return: 将数据转换成Pandas进行返回
        """
        excel_path = get_ini_file(excel)
        # 读取相应路径中的数据
        read = OpenExcelPandas(name=excel_path, sheet=sheet)
        ex_data = read.internal_read_excel(title_name)
        # ex_data = [row for row in ex_data.itertuples(index=True)]
        return ex_data

    2. 缺点为:test函数名要对应excel中函数列表中所定义的名字。并且要求是唯一性。

     3. 代码如下:

    import os
    import inspect
    
    import unittest
    from case.zentao import user_login
    
    from business.zentao.login import user_login_business
    from business.zentao.login.user_login_business import UserLoginBusiness
    
    base_path = os.path.split(os.path.dirname(__file__))[1]
    base_name = base_path + "-" + os.path.splitext(os.path.basename(__file__))[0]
    excel_data = user_login.excel_to_pandas(user_login.login_excel, user_login.login_sheet_two, '函数')
    
    
    class TestLoginUserTwo(unittest.TestCase):
    
        @classmethod
        def setUpClass(cls) -> None:
            cls.business_login = UserLoginBusiness(base_name)
    
        def setUp(self) -> None:
            self.business_login.create_browser()
            pass
    
        def tearDown(self) -> None:
            self.business_login.login_page.browser_action.close_driver_browser()
            pass
    
        def user_login_format(self, method_name):
            # 设置日志需要输出的函数名
            self.business_login.log.fun_name = method_name
            self.business_login.log.info("%s序号的用例开始运行" % method_name)
            # 打印需要输出的内容
            # self.business_login.log.info("用例中所以的内容为:%s" % case)
    
            # 定义第三方存储对象,可以让其它对象进行调用使用。
            self.business_login.data_case_singe = excel_data.loc[method_name]
    
            # 运行执行用例需要执行的动作
            self.business_login.user_pass_error()
    
            self.business_login.log.info("%s序号的用例运行完毕" % method_name)
            pass
    
        def test_format_error(self):
            self.user_login_format(inspect.stack()[0][3])
            pass
    
        def test_not_input(self):
            self.user_login_format(inspect.stack()[0][3])
            pass
    
        def test_input_account(self):
            self.user_login_format(inspect.stack()[0][3])
            pass
    
        def test_input_password(self):
            self.user_login_format(inspect.stack()[0][3])
            pass
    
        def test_succeed_skip(self):
            self.user_login_format(inspect.stack()[0][3])
            pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=2)

    项目所在位置:

    https://github.com/namexiaohuihui/demotest

  • 相关阅读:
    postgresql导入及导出
    高效构建Web应用 教你玩转Play框架 http://www.anool.net/?p=577
    强制远程桌面
    js对日期操作 获取两个日期的相差是否在几月之内
    ACM 擅长排列的小明
    路由vue-router
    小村系列之十五:倒了(修订版)
    小村系列之十三:次贷危机
    小村系列之十:民族主义的兴衰
    小村系列之八:村长开会
  • 原文地址:https://www.cnblogs.com/xiaodingdong/p/11753317.html
Copyright © 2011-2022 走看看