Python+Selenium 自动化实现实例-模块化调用
public 目录存一些公共模块,供用例调用。login.py 内容如下:
# coding=utf-8
import time # login def login(driver):
driver.find_element_by_class_name("ui-dialog-close").click() # 关闭弹窗
driver.find_element_by_xpath("//*[@id='topbar_nav']/li[1]/a[1]").click() # 点击登录按钮
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("hj123456")
driver.find_element_by_xpath("//input[@class='btn']").click() # 点击确认登录按钮 # logout def logout(driver):
time.sleep(2)
driver.find_element_by_link_text(u"退出").click()
接下来login_lizi_public 文件引用login.py 中所定义的函数,代码如下:
#coding=utf-8
from selenium import webdriver
from public import login
import unittest class LoginTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.base_url = "http://www-test.lizi.com"
self.driver.implicitly_wait(5) def test_lizi(self):
driver = self.driver
driver.get(self.base_url)
#调用登录函数
login.login(driver)
text = driver.find_element_by_css_selector('.name').text
print text
self.assertEqual(text,u"被风吹过的夏天",msg="error")
#调用退出函数
login.logout(driver) def tearDown(self):
self.driver.quit() if __name__ == "__main__":
unittest.main()
Python+Selenium 自动化实现实例-模块化调用的更多相关文章
- Python+Selenium 自动化实现实例-数据驱动实例
#coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.implicitly_wait(10) ...
- Python+Selenium 自动化实现实例-实现文件下载
#coding=utf-8 from selenium import webdriver #实例化一个火狐配置文件 fp = webdriver.FirefoxProfile() #设置各项参数,参数 ...
- Python+Selenium 自动化实现实例-Css捕捉元素的几种方法
#coding=utf-8 from selenium import webdriverimport timedriver = webdriver.Chrome()driver.get("h ...
- Python+Selenium 自动化实现实例-打开浏览器模拟进行搜索数据并验证
#导入模块 from selenium import webdriverfrom selenium.webdriver.common.keys import Keys #启动火狐浏览器driver = ...
- Python+Selenium 自动化实现实例-处理分页(pagination)
场景 对分页来说,我们最感兴趣的是下面几个信息 总共有多少页 当前是第几页 是否可以上一页和下一页 代码 下面代码演示如何获取分页总数及当前页数.跳转到指定页数 #coding:utf-8 from ...
- Python+Selenium 自动化实现实例-定位frame中的元素
场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如何理解这 ...
- Python+Selenium 自动化实现实例-单元测试报告
代码如下: # -*- coding: utf-8 -*- from selenium import webdriver import unittest,time import HTMLTestRun ...
- Python+Selenium 自动化实现实例-获取测试对象的Css属性
#coding:utf-8 '''获取测试对象的css属性场景 当你的测试用例纠结细枝末节的时候,你就需要通过判断元素的css属性来验证你的操作是否达到了预期的效果.比如你可以通过判断页面上的标题字号 ...
- Python+Selenium 自动化实现实例-定位一组对象(checkbox,inputs)
# -*- coding: utf-8 -*- from selenium import webdriver import time import os dr = webdriver.Chrome() ...
随机推荐
- 《Java程序设计》第7周学习总结 20165218 2017-2018-1
20165218 2017-2018-1 <Java程序设计>第7周学习总结 教材学习内容总结 JDBC与MySQL数据库 数据库的功能:数据的存储.查询.修改.安全 MySQL:数据库: ...
- 【bzoj3173】最长上升子序列
Portal --> bzoj3173 Solution 感觉自己需要智力康复qwq 首先题目给的这个序列肯定是一个\(1-n\)的排列,并且插入的顺序是从小到大 仔细思考一下会发现如果知道了最 ...
- Mybatis中jdbcType和javaType对应关系
Mybatis中javaType和jdbcType对应关系 JDBC Type Java Type CHAR String VARCHAR ...
- 聊一聊PHP的依赖注入(DI) 和 控制反转(IoC)
简介 IoC Inversion of Control 控制反转DI Dependency Injection 依赖注入 依赖注入和控制反转说的实际上是同一种东西,它们是一种设计模式,这种设计模式用来 ...
- HDU1536:S-Nim(sg函数)
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- centos7 配置 yum 安装的 jdk
yum 安装的 java,jdk 路径默认是 /usr/lib/jvm/java-* 我们修改 .bash_profile 文件加上下面几行: export JAVA_HOME=/usr/lib/jv ...
- [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
在配置了zabbix服务端后,发现:“zabbix server is running”的Value值是“no”, 用:netstat -atnlp|grep 10051 发现没有出现zabbix_s ...
- eclipse插件大全(官方)
eclipse插件大全:http://marketplace.eclipse.org/metrics/successful_installs 各个版本插件: http://download.eclip ...
- HTML标签marquee 来制作页面滚动
页面的自动滚动效果,可由javascript来实现,但是今天无意中发现了一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用m ...
- NOIP模拟2
期望得分:100+100+100=300 实际得分:70+40+20=130 T1 [SCOI2007]kshort弱化版 Description 有n个城市和m条单向道路,城市编号为1~n.每条道路 ...