selenium+python笔记3
2016-05-19 10:10
447 查看
#!/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("255", 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)
相关文章推荐
- Python:模块(一)
- 如何在命令行模式下查看Python帮助文档---dir、help、__doc__
- PYTHON实战开发作业 -WEEK1
- Python转义字符
- python 手记--好记性不如烂笔头
- python中日期和时间格式化输出
- Python 趣味百题
- Python time和datetime模块
- 人脸验证算法Joint Bayesian详解及实现(Python版)
- 批处理与python代码混合编程的实现方法
- 在Pythonanywhere上部署Django
- python 的import机制2
- python 各进制转换
- Python基础(四) 基础拾遗、数据类型进阶
- 深度学习(一)autoencoder的Python实现(2)
- [Python for Data Analysis] Chapter10 时间序列
- bat和python批量重命名文件的实现代码
- 批处理与python代码混合编程的方法
- ubuntu 更新python2.7 ssl 错误解决
- tornado总结7-文件切片异步非阻塞下载