selenium+python笔记3
#!/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的更多相关文章
- selenium+python笔记11
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...
- selenium+python笔记10
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 &qu ...
- selenium+python笔记9
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删 ...
- selenium+python笔记8
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...
- selenium+python笔记7
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 测试126邮箱的登陆功能 1.使用公共方法public. ...
- selenium+python笔记6
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 将登陆动作封装成function "" ...
- selenium+python笔记5
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 登陆126邮箱 """ f ...
- selenium+python笔记4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...
- selenium+python笔记2
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 操作浏览器 """ fro ...
随机推荐
- Swift语法总结补充(一)
Swift基础语法学习总结Swift高级语法学习总结Swift语法总结补充(一) 1. 可选类型是一种类型,String?就是Optional<String>,所以函数参数也可以声明为它2 ...
- 互联网扫描器 ZMap 完全手册
初识 ZMap ZMap被设计用来针对整个IPv4地址空间或其中的大部分实施综合扫描的工具.ZMap是研究者手中的利器,但在运行ZMap时,请注意,您很有 可能正在以每秒140万个包的速度扫描整个IP ...
- BZOJ 2007 海拔(平面图最小割-最短路)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2007 题意:给出一个n*n的格子,那么顶点显然有(n+1)*(n+1)个.每两个相邻顶点 ...
- [UVa1213]Sum of Different Primes(递推,01背包)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- [c/c++]linux下使用c/c++操作mysql
首先需要安装相应的库文件,直接apt-get就可以. sudo apt-get install libmysqlclient-dev 编译的时候,需要额外链接到这个库.如果是apt-get安装的话,那 ...
- C语言程序设计现代方法1,2,3章
1:浮点型(float)运算比int慢,并且可能存在舍入误差 如float存储0.1,以后使用可能会变成0.099999999987 2:宏定义只用大写,这是大多数C程序猿遵循的规范! C语言区分大小 ...
- JS——JavaScript Confirm
function show_confirm(){var r=confirm("Press a button!");if (r==true) { alert("You pr ...
- Codeforces Round #286 (Div. 2) B. Mr. Kitayuta's Colorful Graph dfs
B. Mr. Kitayuta's Colorful Graph time limit per test 1 second memory limit per test 256 megabytes in ...
- JS学习笔记(二) 数据类型
参考资料: 1. http://www.w3school.com.cn/js/js_datatypes.asp 2. http://blog.sina.com.cn/s/blog_85c1dc1001 ...
- 行转列:SQL SERVER PIVOT与用法解释
在数据库操作中,有些时候我们遇到需要实现“行转列”的需求,例如一下的表为某店铺的一周收入情况表: WEEK_INCOME(WEEK VARCHAR(10),INCOME DECIMAL) 我们先插入一 ...