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 自动化实现实例-模块化调用的更多相关文章

  1. Python+Selenium 自动化实现实例-数据驱动实例

    #coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.implicitly_wait(10) ...

  2. Python+Selenium 自动化实现实例-实现文件下载

    #coding=utf-8 from selenium import webdriver #实例化一个火狐配置文件 fp = webdriver.FirefoxProfile() #设置各项参数,参数 ...

  3. Python+Selenium 自动化实现实例-Css捕捉元素的几种方法

    #coding=utf-8 from selenium import webdriverimport timedriver = webdriver.Chrome()driver.get("h ...

  4. Python+Selenium 自动化实现实例-打开浏览器模拟进行搜索数据并验证

    #导入模块 from selenium import webdriverfrom selenium.webdriver.common.keys import Keys #启动火狐浏览器driver = ...

  5. Python+Selenium 自动化实现实例-处理分页(pagination)

    场景 对分页来说,我们最感兴趣的是下面几个信息 总共有多少页 当前是第几页 是否可以上一页和下一页 代码 下面代码演示如何获取分页总数及当前页数.跳转到指定页数 #coding:utf-8 from ...

  6. Python+Selenium 自动化实现实例-定位frame中的元素

    场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如何理解这 ...

  7. Python+Selenium 自动化实现实例-单元测试报告

    代码如下: # -*- coding: utf-8 -*- from selenium import webdriver import unittest,time import HTMLTestRun ...

  8. Python+Selenium 自动化实现实例-获取测试对象的Css属性

    #coding:utf-8 '''获取测试对象的css属性场景 当你的测试用例纠结细枝末节的时候,你就需要通过判断元素的css属性来验证你的操作是否达到了预期的效果.比如你可以通过判断页面上的标题字号 ...

  9. Python+Selenium 自动化实现实例-定位一组对象(checkbox,inputs)

    # -*- coding: utf-8 -*- from selenium import webdriver import time import os dr = webdriver.Chrome() ...

随机推荐

  1. laravel5.1 使用中间表的多对多关联

    用户表user 标签表tag 中间表user_tag(user_id,tag_id) 在user模型中定义tags关联如下: public function tags() { return $this ...

  2. hihocoder #1584 : Bounce

    题意; 有一个n*m的网格阵,球从左上角开始在网格中碰撞,碰到边界就直角反弹,到达格子的角落结束,求途中经过一次的格子数. 代码: //神马规律啊,设x表示球与垂直面的撞击次数,y为球与水平墙面的撞击 ...

  3. 个人最常用的vim操作

    本文只记录个人工作中最常用到的vim快捷键,不是很全,但是已经覆盖了绝大多数功能. 参考:<鸟哥Linux私房菜>以及https://www.cnblogs.com/momofan/p/5 ...

  4. 全表 or 索引

    这一篇文章证实了以前对MySQL优化程序的工作原理. MySQL就像一个人一样,总是聪明的去选择当前最快的方式去查询,而不是像Oracle数据那样死板地根据规格去查询. 查询的要求在于快.而对于数据库 ...

  5. JavaScript中callee与caller,apply与call解析

    1. arguments.callee 1.1 解释 返回正被执行的 Function 对象,也就是所指定的 Function 对象的正文. 1,.2 说明 callee 属性的初始值就是正被执行的 ...

  6. Flask---使用Bootstrap新建第一个demo

    Flask---使用Bootstrap新建第一个demo 参考自http://www.jianshu.com/p/417bcbad82fb 还有<Flask web开发> 前端用到Boot ...

  7. [ERROR] Too many connections 尚未解决

    [ERROR] - com.alibaba.druid.support.logging.Log4j2Impl.error(Log4j2Impl.java:53) - create connection ...

  8. 说一说ASP.NET web.config 加密及解密方法 (代码)

    /// <summary> /// 保护web.config的加密和解密 /// </summary> public class ProtectHelper { /// < ...

  9. 如何写出高性能SQL语句

    优化SQL查询:如何写出高性能SQL语句 1.首先要搞明白什么叫执行计划? 执行计划是数据库根据SQL语句和相关表的统计信息作出的一个查询方案,这个方案是由查询优化器自动分析产生欀如一条SQL语句如果 ...

  10. 【CodeForces】576 C. Points on Plane

    [题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...