一: 说明

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

其它都基本相同,可参考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

unittest 运行slenium(四)---通过指定用例的形式运行用例的更多相关文章

  1. unittest 运行slenium(二)---打开浏览器及元素操作

    一: 打开win10中安装的浏览器 1. 打开的浏览器有:谷歌/火狐/ie/edge 2. 当浏览器的driver没有配置在path环境下时,在启动浏览器时需要传入driver的所在位置 3. 其中火 ...

  2. java 面向对象(四十二):反射(六)反射应用三:调用运行时类的指定结构

    调用指定的属性: @Test public void testField1() throws Exception { Class clazz = Person.class; //创建运行时类的对象 P ...

  3. 四:(之七_如何与运行中容器交互)Dockerfile语法梳理和实践

    1.指定网络连接方式:--net=””   (bridge/host/none/container: 四种类型) 注:192.168.33.18 此IP是在vagrantfile中指定的虚拟机IP:c ...

  4. <四>面向对象分析之UML核心元素之用例

    一:基本概念        --->用例定义了一组用例实例,其中每个实例都是系统所执行一系列操作,这些操作生成特定主角可以观测的值.        --->所谓用例,就是一件事情,要完成这 ...

  5. 运行tomcat6w.exe ,提示 指定的服务未安装 unable to open the service 'tomcat66'

    错误:运行tomcat6w.exe ,提示 指定的服务未安装 unable to open the service 'tomcat6'(我用的是官网下载的解压版) 解决方法: 打开命令行提示符窗口=& ...

  6. Arduino可穿戴教程之第一个程序——上传运行程序(四)

    Arduino可穿戴教程之第一个程序——上传运行程序(四) 2.4.5  上传程序 现在所有Arduino IDE的设置都完成了,我们就可以将示例程序上传到板子中了.这非常简单,只需要单击如图2.45 ...

  7. 运行tomcat6w.exe ,提示 指定的服务未安装 unable to open the service 'tomcat6'

    错误:运行tomcat6w.exe ,提示 指定的服务未安装 unable to open the service 'tomcat6'(我用的是官网下载的解压版) 解决方法: 打开命令行提示符窗口=& ...

  8. java 面向对象(四十):反射(四)反射应用一:创建运行时类的对象

    1.代码举例Class<Person> clazz = Person.class; Person obj = clazz.newInstance();System.out.println( ...

  9. Python接口测试实战4(下) - 框架完善:用例基类,用例标签,重新运行上次失败用例

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

随机推荐

  1. python学习:python打包成exe

    1) 安装pyinstaller pip install pyinstaller 目前已经支持 python 3.7 版本 2) 打开cmd窗口,进入到要打包的python文件所在目录, pyinst ...

  2. python对 windows系统监控插件

    在python编程的windows系统监控中,需要监控监控硬件信息需要两个模块:WMI 和 pypiwin32 .

  3. 【k8s node断电重启】

    kubernetes断电重启 导致部分pod无法删除 dashboard上处于黄色 kubectl get处于terminate 状态 kubectl delete报错: An error occur ...

  4. 触屏Tap模拟事件

    触屏的click因为有双击判断所以有200ms的延迟,zepto里的touch.js兼容不好所以tap也没法直接用. gibhub上有个fastclick太大了. 自己用touched写个简单的模拟t ...

  5. WPF TextBlock 文本换行的两种方式

    第一种: <TextBlock> This is line 1.<LineBreak/> This is line 2. </TextBlock> 第二种 < ...

  6. Linux杀毒软件(ClamAV)

    Clam AntiVirus是一个类UNIX系统上使用的反病毒软件包.主要应用于邮件服务器,采用多线程后台操作,可以自动升级病毒库. 一.下载安装 1.下载 clamav官网:http://www.c ...

  7. Cookie,Session,Token详解

    Cookie,Session,Token详解 Cookie : ​ 是一个非常具体的东西,指的就是浏览器里面能永久存储的一种数据,仅仅是浏览器实现的一种数据存储功能. ​ Cookie由服务器生成,发 ...

  8. QueryList::Query() The received content is empty!的经准灵活解决办法

    QueryList::Query() The received content is empty! 最近因为项目问题出现The received content is empty!,我也有过在网上寻找 ...

  9. Android studio 3.1.3真机调试报错,no target device found

    Android studio 3.1.2 的 Android monitor 改为 Android profiler,直接点这个就可以真机调试,在手机安装相应app 如果不行,报错,"no ...

  10. k8s 启动pod的问题

    版本: k8s 1.5 docker 1.3 CentOS 7.6 使用命令 kubectl get pods输出no resources.解决方法是修改 apiserver 的配置文件 vim /e ...