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() ...
随机推荐
- Implement Queue by Two Stacks
As the title described, you should only use two stacks to implement a queue's actions. The queue sho ...
- 【arc080F】Prime Flip
Portal --> arc080_f Solution 这题的话..差分套路题(算吗?反正就是想到差分就很好想了qwq) (但是问题就是我不会这种套路啊qwq题解原话是:&quo ...
- oracle的lpad()函数
lpad函数 lpad函数是Oracle数据库函数,lpad函数从左边对字符串使用指定的字符进行填充.从其字面意思也可以理解,l是left的简写,pad是填充的意思,所以lpad就是从左边填充的意思. ...
- Socket初识2
一.Socket一些概念 sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) 1.1 参数1:Socket Families(地址簇) / ...
- 「Linux」centos7安装mysql
1.yum仓库下载MySQL:sudo yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch. ...
- Bootstrap 按钮下拉菜单
向下拉 <div class="dropdown"> <button class="btn btn-default" data-toggle= ...
- Mac(Linux)上安装memcached步骤
Mac上安装memcached类似于在Linux平台上安装memcached. 主要需要做两块: 一.安装libevent库: 二.安装memcached; 一.安装libevent库 libeven ...
- Chrome工具使用
(1) Chrome插件的使用 本来还想说FQ了,结果实验半天没成功,最后才知道公司已经邮件通知了,郁闷,FQ后我把我的插件重新装了一遍,觉得好像又懂了好多,记载下来我装的一些东西和有关PostMan ...
- hdu 3118 Arbiter
http://acm.hdu.edu.cn/showproblem.php?pid=3118 题意:删除最少的边使图没有奇环 二分图的定义:如果顶点能分为两个互不相交的子集,则图为二分图 二分 ...
- Disruptor的使用
..................2015年的第一天................... 本文代码托管在 https://github.com/hupengcool/disruptor-start ...