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 ...
随机推荐
- 是否用new来新建对象
class A{ }: 1.不使用new来新建对象 A a: 使用完后什么也不用做,系统自动调用析构函数.使用空间是栈. 2.使用new来新建对象 A* a=new A(); delete a;/ ...
- CodeForces 478C Table Decorations
Table Decorations Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- Python入门-引号
Python 接收单引号(' ),双引号(" ),三引号(''' """) 来表示字符串,引号的开始与结束必须的相同类型的. 其中三引号可以由多行组成,编写多行 ...
- Linux基础※※※※访问Windows共享文件夹
参考Linux公社链接:http://www.linuxidc.com/Linux/2014-06/103749.htm 实际上,可以直接用sambaclient程序访问共享资源. 列出共享主机的列表 ...
- s表达式和json表达式
s表达式 + 1 2 3普通表达式 1+2+3json表达式{ +:[1, 2, 3]}优点,一个运算符,无限个参数 s表达式 * (+ 1 2) 3普通表达式 1+(2*3)json表达式{ *:[ ...
- 基于jQuery的移动轮播图(支持触屏)
移动轮播图我看到两款, 一款是无线天猫的m.tmall.com,实现了无缝轮播. 一款是蘑菇街的,没有实现无缝轮播. 我自己重写一个,类似蘑菇街 <!doctype html> <h ...
- Yii javascript 的结合 账号禁用 激活 的设置。
2014-02-16 控制器中的代码: public function actionUpdown(){ //print_r($_POST);die(); if(Buser::model()->u ...
- 个人博客Week3
必应软件客户端测评 话不多说 先来一张高大上的客户端界面截图! 首先 映入眼帘的就是四个主要的模块!(1)词典(2)例句(3)翻译(4)应用 (1)词典: 在查询词条的时候,一旦查询了一个词条就不能够 ...
- Git学习(1)Git 简介
Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件. Git ...
- php生成mysql的数据字典
<?php header('content-type:text/html;charset=utf-8'); define('DB_HOST','localhost'); define('DB_U ...