#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc:学习unittest的用法
注意setUp/setUpClass,tearDown/tearDownClass的区别
① setUp():每个测试函数运行前运行
② tearDown():每个测试函数运行完后执行
③ setUpClass():必须使用@classmethod 装饰器,所有test运行前运行一次
④ tearDownClass():必须使用@classmethod装饰器,所有test运行完后运行一次 unittest还有一些不常用的装饰器:
@unittest.skip(reason):无条件跳过测试,reason描述为什么跳过测试
@unittest.skipif(conditition,reason):condititon为true时跳过测试
@unittest.skipunless(condition,reason):condition不是true时跳过测试
@unittest.expectedFailure:如果test失败了,这个test不计入失败的case数目
"""
import unittest
import time
from selenium import webdriver class SearchTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Firefox()
cls.driver.implicitly_wait(30)
cls.driver.maximize_window()
cls.base_url = "http://www.baidu.com"
cls.driver.get(cls.base_url + "/") cls.search_text = cls.driver.find_element_by_id("kw")
cls.search_btn = cls.driver.find_element_by_id("su") def test_search_btn_displayed(self):
self.assertTrue(self.search_btn.is_displayed())
self.assertTrue(self.search_btn.is_enabled()) def test_search_text_maxlength(self):
max_length = self.search_text.get_attribute("maxlength")
self.assertEqual("", max_length) def test_search(self):
self.search_text.clear()
self.search_text.send_keys("unittest")
self.search_btn.click() time.sleep(2)
title = self.driver.title
self.assertEqual(title, u"unittest_百度搜索") @classmethod
def tearDownClass(cls):
# close the browser window
cls.driver.quit() if __name__ == '__main__':
unittest.main(verbosity=3)

selenium+python笔记3的更多相关文章

  1. selenium+python笔记11

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...

  2. selenium+python笔记10

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 &qu ...

  3. selenium+python笔记9

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删 ...

  4. selenium+python笔记8

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...

  5. selenium+python笔记7

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 测试126邮箱的登陆功能 1.使用公共方法public. ...

  6. selenium+python笔记6

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 将登陆动作封装成function "" ...

  7. selenium+python笔记5

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 登陆126邮箱 """ f ...

  8. selenium+python笔记4

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...

  9. selenium+python笔记2

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 操作浏览器 """ fro ...

随机推荐

  1. VC++实现在系统托盘来新消息闪烁,鼠标悬停显示窗口

    转载:http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c8115/How-to-Implement-a-Mouse ...

  2. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  3. .Net需要掌握的知识

    一.C#开发 1.C#基础 变量定义 如何变量的初始化 变量的作用域 常量 字符串处理 使用正则表达式 什么是CTS类型?数据类型如何分类以及各个数据类型范围 类型的转化分类 显式转换何隐式转化如何区 ...

  4. celery入门

    认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...

  5. [POJ1681]Painter's Problem(高斯消元,异或方程组,状压枚举)

    题目链接:http://poj.org/problem?id=1681 题意:还是翻格子的题,但是这里有可能出现自由变元,这时候枚举一下就行..(其实这题直接状压枚举就行) /* ━━━━━┒ギリギリ ...

  6. ManualResetEvent & AutoResetEvent

      参考资料: 1. https://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx 2. https: ...

  7. 关于【bootstrap modal 模态框弹出瞬间消失的问题】

    前提是你没有重复引入bootstrap.js\bootstrap.min.js和modal.js.一下提供一个小例子. <button class="btnbtn-primary bt ...

  8. iOS - OC 异常处理

    1.@try 语句 @try { // Code that can potentially throw an exception 可能会抛出异常的代码块 statement . . . } @catc ...

  9. [转载] 一些非常好的 linux 基础工具

    http://linuxtools-rst.readthedocs.org/zh_CN/latest/index.html 作者整理的非常好, 需要的时候可以拿来参考

  10. OCR识别-python版(一)

    需求:识别图片中的文字信息环境:windows系统 开发语言:python 使用工具类:1.pyocr 2.PIL 3.tesseract-ocr 步骤: 1.pyocr 网络通直接使用命令:pip ...