1、实例demo是用谷歌浏览器在百度首页搜python的动作脚本;

      BaiDu_test是指脚本中自己定义的类名,test_get是指你的类中定义的testcase方法。

   在if name函数下加入testcase时,python3.6版本的方法是 

suiter = addtest(类名('测试方法'))

 suiter = addTest(BaiDu_test("test_get"))

from selenium import webdriver
import unittest
import time
from HTMLTestRunner import HTMLTestRunner class BaiDu_test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = "https://www.baidu.com/"
self.driver.implicitly_wait(10)
self.driver.maximize_window() def test_get(self):
driver = self.driver
driver.get(self.url)
print("当前网址"+driver.current_url)
time.sleep(5)
driver.find_element_by_id("kw").send_keys("python")
time.sleep(2)
driver.find_element_by_id("su").click() def tardown(self):
#清除缓存
self.driver.refresh()
self.driver.quit() if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(BaiDu_test('test_get'))
sop = open(r'D:\test_02.html','wb')
runner = HTMLTestRunner(stream=sop,
title="asd",
description='asdasd')
runner.run(suite)

2、在python3.7版本中是以引用方法加入用例

suiter =  addtest(类名 . 测试方法())

                           suiter = addTest(myclass.testcase())

from selenium import webdriver
import unittest
import time
from HTMLTestRunner import HTMLTestRunner class BaiDu_test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = "https://www.baidu.com/"
self.driver.implicitly_wait(10)
self.driver.maximize_window() def test_get(self):
driver = self.driver
driver.get(self.url)
print("当前网址"+driver.current_url)
time.sleep(5)
driver.find_element_by_id("kw").send_keys("python")
time.sleep(2)
driver.find_element_by_id("su").click() def tardown(self):
#清除缓存
self.driver.refresh()
self.driver.quit() if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(BaiDu_test.test_get())
sop = open(r'D:\test_02.html','wb')
runner = HTMLTestRunner(stream=sop,
title="asd",
description='asdasd')
runner.run(suite)

Python3.7版本unittest框架添加用例的方法的更多相关文章

  1. unittest框架里的常用断言方法:用于检查数据

    1.unittest框架里的常用断言方法:用于检查数据. (1)assertEqual(x,y) 检查两个参数类型相同并且值相等.(2)assertTrue(x) 检查唯一的参数值等于True(3)a ...

  2. Python3 完美解决unittest框架下不生成测试报告

    前提: 1.运行测试用例一切正常,只是没有测试报告显示 2.使用命令行pyhon 脚本名字.py 却可以生成测试报告 3.pycharm 在运行测试用例的时候 默认是以unittest 框架来运行的, ...

  3. python unittest 框架添加测试用例及运行

    找出要测试的testcase,并加入到Testsuite,运行Testsuite并把结果给TestResult1.创建TestSuite实例对象suite = unittest.TestSuite() ...

  4. python3 unittest框架失败重跑加截图支持python2,python3

    github源码地址下载:https://github.com/GoverSky/HTMLTestRunner_cn.git 解压文件后取出/HTMLTestRunner_cn.py文件丢进C:\Py ...

  5. unittest框架(一)用例管理

    在unittest框架的自动化接口测试中,可以用yaml文件来管理用例,这样一方面,不会像excel管理用例那么死板:另一方面,数据读取出来就是一个字典,便于取值,用起来更灵活. 首先,需要安装一个模 ...

  6. 基于python3在nose测试框架的基础上添加测试数据驱动工具

    [本文出自天外归云的博客园] Python3下一些nose插件经过2to3的转换后失效了 Python的nose测试框架是通过python2编写的,通过pip3install的方式安装的nose和相关 ...

  7. 【python3+request】python3+requests接口自动化测试框架实例详解教程

    转自:https://my.oschina.net/u/3041656/blog/820023 [python3+request]python3+requests接口自动化测试框架实例详解教程 前段时 ...

  8. 第9课:备份mysql数据库、重写父类、unittest框架、多线程

    1. 写代码备份mysql数据库: 1)Linux下,备份mysql数据库,在shell下执行命令:mysqldump -uroot -p123456 -A >db_bak.sql即可 impo ...

  9. selenium自动化测试、Python单元测试unittest框架以及测试报告和日志输出

    部分内容来自:https://www.cnblogs.com/klb561/p/8858122.html 一.基础介绍 核心概念:test case, testsuite, TestLoder,Tex ...

随机推荐

  1. 颜色空间之CIE2000色差公式

    CIEDE2000色差公式   为了进一步改善工业色差评价的视觉一致性,CIE专门成立了工业色差评价的色相和明度相关修正技术委员会TC1-47(Hue and Lightness Dependent ...

  2. ExtJS4.2下将表单元素放在菜单时不能进行拷贝的问题解决办法

    通过浏览器F12我们发现,在菜单对应的dom元素上面,有几个系统附加的事件处理函数,只要我们将它去掉就可以了.示意代码如下: { xtype: "button", scope: z ...

  3. 小A的位运算-(前缀和+位运算)

    https://ac.nowcoder.com/acm/contest/549/D 题意:从N个数里面选出N-1个数要让它们或起来的值最大. 解题: 假设n个数分别存在a数组里. 从左到右连续或运算结 ...

  4. python入门(十四):面向对象(属性、方法、继承、多继承)

    1.任何东西1)属性(特征:通常可以用数据来描述)(类变量和实例变量)2)可以做一些动作(方法) 类来管理对象的数据.属性:类变量和实例变量(私有变量)方法:    1)实例方法    2)类方法   ...

  5. BOOST_PREVENT_MACRO_SUBSTITUTION

    [BOOST_PREVENT_MACRO_SUBSTITUTION] 用于防止函数被macro替换的问题. 例如: 参考: 1.https://blog.csdn.net/yanxiangtianji ...

  6. Appium 学习三:Appium-Desktop 填坑

    之前使用appium执行自动化脚本,现使用appium-desktop  遇到了一些问题 1.使用name定位的报错   Locator Strategy 'name' is not supporte ...

  7. CMake support in Visual Studio

    Visual Studio 2017 introduces built-in support for handling CMake projects. This makes it a lot simp ...

  8. python3安装pcap遇到的问题

    最近想在win7上安装pypcap,遇到了一下问题,现在大概总结一下: 直接使用pip install pypcap,提示pcap.h not found: 网上下载pypcap安装包,运行pytho ...

  9. grid布局

    display: grid; //行 //每一行中有几块,每块所占的width的百分比(1) grid-template-columns: 70% 30%; //每个div的width 100px,自 ...

  10. odoo qweb 记录

    默认的打印功能修改,比如在动作中的打印功能: 继承抽象模型 models.AbstractModel 重写 _get_report_values class PayslipDetailsReportI ...