一: 说明

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

其它都基本相同,可参考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. layer confirm 三种选择按钮

    layer.confirm('请选择是否通过提现?(tips:同意直接打款,驳回不可恢复)', { btn : ['通过-打款','不通过','通过-已打款'], btn1:function(){ a ...

  2. 静态站点生成器-md-vue-vuepress

    推荐指数:

  3. Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack

    现象 在用`mobx-react-router`的`this.props.history.push("/")`的时候,浏览器会提示 Warning: Hash history ca ...

  4. 17、vue-cli3 js项目中引入ts混用(typeScript)

    说明: vue3.0搭建的项目,不过没有引入ts,后来需要用到一个插件是用ts写的,所以vue要用到ts... 一.安装typescript及loader npm install typescript ...

  5. java程序cpu问题排查

    方法一: 转载:http://www.linuxhot.com/java-cpu-used-high.html 1.jps 获取Java进程的PID. 2.jstack pid >> ja ...

  6. RabbitMQ官方教程二 Work Queues(GOLANG语言实现)

    RabbitMQ官方教程二 Work Queues(GOLANG语言实现) 在第一个教程中,我们编写了程序来发送和接收来自命名队列的消息. 在这一部分中,我们将创建一个工作队列,该队列将用于在多个wo ...

  7. vue中使用animate.css实现动画

    参考链接:https://www.cnblogs.com/ccyinghua/p/7872694.html 参考链接:https://www.jianshu.com/p/2e0b2f8d40cf 使用 ...

  8. python开发【学习目录】:目录

    python开发[学习目录]:目录 Python开发:环境搭建(python3.PyCharm) Python开发[第一篇]:初识Python Python开发[第二篇]:Python基础知识 Pyt ...

  9. SecureCRT系列:生成公私钥

    SecureCRT下载地址:http://www.portablesoft.org/securecrt-securefx-legacy-versions/1.打开我们的SecureCRT客户端,点击t ...

  10. springboot整合druid、mybatis

    目的: 1.springboot配置数据库连接池druid 测试druid中url监控 2.springboot整合mybatis 测试查删案例 3.springboot整合pagehelper sp ...