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() ...
随机推荐
- 「CodePlus 2017 12 月赛」可做题2(矩阵快速幂+exgcd+二分)
昨天这题死活调不出来结果是一个地方没取模,凉凉. 首先有个一眼就能看出来的规律... 斐波那契数列满足$a_1, a_2, a_1+a_2, a_1+2a_2, 2a_1+3a_2, 3a_1+5a_ ...
- cin/cout与scanf/printf的比较
转自http://www.cnblogs.com/penelope/articles/2426577.html cin .cout 基本说明: cin是标准输入流对象,代表标准输入设备(键盘), ...
- hihocoder 1509异或排序
描述 给定一个长度为 n 的非负整数序列 a[1..n] 你需要求有多少个非负整数 S 满足以下两个条件: (1).0 ≤ S < 2^60 (2).对于所有 1 ≤ i < n ,有 ( ...
- 浅谈cocosd之autorelease\retain\release的理解
三种情况,引出问题: 1) new出来的对象需要释放,而释放时,如果有其他人引用了这个对象,再次使用这个对象时,则会出现野指针情况. ==> 于是出现了引用计数的释放管理机制. 2) 对于一 ...
- [io benchmark]常用磁盘基准/压力测试工具
Unix Disk I/O Benchmarks fio - NEW! fio is an I/O tool meant to be used both for benchmark and stres ...
- vim切换显示器乱行问题解决
http://note.youdao.com/noteshare?id=ccdad950ca154a6b1597cbe2ede07b81
- Qt ------ CSS 长度单位
1. css相对长度单位 Ø em 元素的字体高度 Ø ex 字体x的高度 Ø px ...
- 「电脑应用」在mac上使用aria2
Chrome 一. 需要工具: Chrome浏览器,Aria2GUI,Chrome里BaiduExporter插件. 首先先明确一件事情,平时生活中使用的所有工具都建议到官方下载,此处用到的几样提供给 ...
- ictclas bug修复
大体上参考链接:http://blog.csdn.net/luojinping/article/details/8788743 最后注意下SegTag.java文件 public SegTag(int ...
- HTML标签marquee 来制作页面滚动
页面的自动滚动效果,可由javascript来实现,但是今天无意中发现了一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用m ...