#练习9:
import unittest
from selenium import webdriver
import time class GloryRoad(unittest.TestCase):
def setUp(self):
# 启动Firefox浏览器
self.driver = webdriver.Chrome(executable_path = "c:\\chromedriver") def testSoGou(self):
# 访问搜狗首页
self.driver.get("http://sogou.com")
# 清空搜索输入框默认内容
self.driver.find_element_by_id("query").clear()
# 在搜索输入框中输入“光荣之路自动化测试”
self.driver.find_element_by_id("query").send_keys(u"WebDriver实战宝典")
# 单击“搜索”按钮
self.driver.find_element_by_id("stb").click()
# 等待3秒
time.sleep(3)
assert u"吴老师" in self.driver.page_source, u"页面中不存在要寻找的关键字!".encode("gbk") def testBing(self):
# 访问搜狗首页
self.driver.get("http://cn.bing.com")
# 清空搜索输入框默认内容
self.driver.find_element_by_id("sb_form_q").clear()
# 在搜索输入框中输入“光荣之路自动化测试”
self.driver.find_element_by_id("sb_form_q").send_keys(u"WebDriver实战宝典")
# 单击“搜索”按钮
self.driver.find_element_by_id("sb_form_go").click()
# 等待3秒
time.sleep(3)
assert u"王老师" in self.driver.page_source, u"页面中不存在要寻找的关键字!".encode("gbk") def tearDown(self):
# 退出浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()

【Python】unittest-5的更多相关文章

  1. 【python】unittest中常用的assert语句

    下面是unittest模块的常用方法: assertEqual(a, b)     a == b assertNotEqual(a, b)     a != b assertTrue(x)     b ...

  2. 【Python②】python之首秀

       第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...

  3. 【python】多进程锁multiprocess.Lock

    [python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报  分类: Python(38)  同步的方法基本与多线程相同. ...

  4. 【python】SQLAlchemy

    来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...

  5. 【python】getopt使用

    来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...

  6. 【Python】如何安装easy_install?

    [Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...

  7. 【Python】 零碎知识积累 II

    [Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...

  8. 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】

    1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...

  9. 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】

    1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...

  10. 【Python】-NO.98.Note.3.Python -【Python3 解释器、运算符】

    1.0.0 Summary Tittle:[Python]-NO.98.Note.3.Python -[Python3 解释器] Style:Python Series:Python Since:20 ...

随机推荐

  1. Ant Design 日期选择组件RangePicker 选择时间范围后计算范围内的天数。

    /** *需求:同年同月,同年不同月(两个月相减大于1,小于1),不同年(两个年相减大于1(是否为闰年),小于1),起止包含的月份及天 */ //首先引入组件 import { DatePicker} ...

  2. C++的字符串多行输入

    #include<iostream> using namespace std; int main() { int r, c; char grid[50][51]; cout << ...

  3. python-爬虫-Beautifulsoup模块

    一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你 ...

  4. js 遍历

    for循环 var a = new Array("first", "second", "third") for(var i = 0;i &l ...

  5. js javascript 容错处理代码屏蔽js错误

    加入到head <SCRIPT language=javascript> window.onerror=function(){return true;} </SCRIPT> o ...

  6. java前后向查找个人理解

    举一个最简单的栗子 这个前后说的是0宽所在的位置,是在:前还是后 http://www.sb.com 1.前向正向查找 (1) 如果用:.*(?=:) 首先(?=:)被称作0宽度断言,所谓0宽度应该是 ...

  7. C++ leetcode Longest Palindromic Substring

    明天就要上课了,再过几天又要见班主任汇报项目进程了,什么都没做的我竟然有一种迷之淡定,大概是想体验一波熬夜修仙的快乐了.不管怎么说,每天还是要水一篇博文,写一个LeetCode的题才圆满. 题目:Gi ...

  8. 前端开发VScode常用插件

    名称 功能 Auto Close Tag 自动闭合HTML标签 Auto Import Typescript 自动import提示 Auto Rename Tag 修改HTML标签时,自动修改匹配的标 ...

  9. burpsuite拦截https数据包(Firefox)

    1.配置浏览器对http/https都使用burpsuite代理 http和https是分开的,对http使用了代理并不代表对https也使用了代理,要配置浏览器让其对https也使用同样的代理. 当 ...

  10. css 改变浏览器滚动条的样式

    /*滚动条样式*/ .innerbox::-webkit-scrollbar {/*滚动条整体样式*/ width: 4px; /*高宽分别对应横竖滚动条的尺寸*/ height: 4px; } .i ...