这章总结selenium在UI测试方面的用法

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys class PythonOrgSearch(unittest.TestCase): def setUp(self):
self.driver = webdriver.Firefox() def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source def tearDown(self):
self.driver.close() if __name__ == "__main__":
unittest.main()

首先创建一个类 PythonOrgSearch ,其中 test_search_in_python_org 方法中写的是一个测试用例,像JUnit中@before@after一样的作用,可以用setUp和tearDown函数。这两个函数分别表示在每个测试用例执行前需要做的操作和执行后需要做的操作。不用在每个测试用例中都进行声明,只要写在两个函数中就会自动调用

参考 http://selenium-python.readthedocs.io/navigating.html

selenium python bindings 写测试用例的更多相关文章

  1. selenium python bindings 元素定位

    1. 辅助 Firepath Firefox是所有做前端的必不可少的浏览器因为firebug的页面元素显示很清晰.用selenium 去定位元素的时候Firefox还有一个非常友好的工具就是firep ...

  2. <译>Selenium Python Bindings 1 - Installation

    Installation Introduction Selenium Python bindings 提供了一个简单的API来使用Selenium WebDriver编写使用功能/验收测试.通过Sel ...

  3. <译>Selenium Python Bindings 2 - Getting Started

    Simple Usage如果你已经安装了Selenium Python,你可以通过Python这样使用: #coding=gbk ''' Created on 2014年5月6日 @author: u ...

  4. <译>Selenium Python Bindings 5 - Waits

    如今,大多数的Web应用程序使用AJAX技术.当页面加载到浏览器,页面中的元素也许在不同的时间间隔内加载.这使得元素很难定位,如果在DOM中的元素没有呈现,它将抛出ElementNotVisibleE ...

  5. selenium python bindings 初步用法及简单参考例子

    掌握selenium最简单的方法就是参考例子进行学习,下面给出之前项目的测试例子及分析 # -*- coding: utf-8 -*- import time from selenium import ...

  6. <译>Selenium Python Bindings 6 - WebDriver API

    本章涉及Selenium WebDriver的所有接口. Recommended Import Style 推荐的导入风格如下: from selenium import webdriver 然后,你 ...

  7. <译>Selenium Python Bindings 4 - Locating Eelements

    有各种不同的策略来定位页面中的元素.你可以使用最合适定位方式用于你的用例.Selenium提供了以下方法来定位页面中的元素: find_element_by_id find_element_by_na ...

  8. <译>Selenium Python Bindings 3 - Navigating

    当你想要通过webdriver导航到一个链接,正常的方式点是通过调用get方法: driver.get("http://www.google.com") Interacting w ...

  9. selenium python bindings 项目结构总结

    一个合理的文档结构在import的过程中会避免很多错误,踩完坑来记录. webtests/ framework.py webdriver.py test_file.py module/ __init_ ...

随机推荐

  1. shell command to replace UltraEdit

    cat abc.txt |hexdump -C cat abc.txt |hexdump -C

  2. Tomcat服务器优化(内存,并发连接数,缓存)

    a) 内存优化:主要是对Tomcat启动参数进行优化,我们可以在Tomcat启动脚本中修改它的最大内存数等等.b) 线程数优化:Tomcat的并发连接参数,主要在Tomcat配置文件中server.x ...

  3. vue之父子组件执行对方的方法

    一.子组件执行父组件中的方法 1.父组件将方法名传给子组件,子组件进行调用 父组件中: <Vbutton typeBtn="success" :btnUserMethod=& ...

  4. 多台服务器-SSH免密登录设置

    在4台服务器-SSH免密登录设置,如以下4台服务器 master1 node001 node002 node003 我想在master1对4台服务器进行拉取或者分发任务或者是集群服务器的批量操作,但是 ...

  5. svg圆环缓冲动画

    代码如下 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8& ...

  6. Batch - attrib 命令

    原文地址:CMD中使用attrib命令设置文件只读.隐藏属性详解 本文介绍一个cmd下的一个attrib.exe的小程序,它可以用来设置文件的属性.我们知道文件的属性有只读.隐藏.系统.存档和无内容索 ...

  7. 【JZOJ6421】匹配

    description analysis 对于普通树形\(DP\)可以设\(f[i][0/1],g[i][0/1]\)表示\([1,i]\)的线段树的最大值.方案数 \(0\)表示不选择根与某个儿子相 ...

  8. CF1265B Beautiful Numbers

    题意 给一个长度为\(n\)的排列\(P\),求对于\(1\) 到 \(n\)中的每个数\(m\),是否能找到一段长度为\(m\)的区间使得区间内的数是一个\(1\)到\(m\)的排列. 输出一个\( ...

  9. c实现swap函数陷阱

    swap函数陷阱 使用c实现一个交换两个数的函数,代码很简单: void swap(int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; } 只有3行代码,且 ...

  10. (转)sql的group by应用

    转载于:http://www.studyofnet.com/news/247.html 本文导读:在实际SQL应用中,经常需要进行分组聚合,即将查询对象按一定条件分组,然后对每一个组进行聚合分析.创建 ...