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() ...
随机推荐
- Unity3D手游开发日记(5) - 适合移动平台的植被随风摆动
一直在思考怎么让场景更有生机,我觉得植被的随风摆动是必不可少的.CE3引擎的植被bending就做得特别棒.我也准备在手机上做一套. 先分析一下植被摆动常见的几种做法.其实不管哪种做法,核心就是让植被 ...
- Linux内核分析2
周子轩原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 本次实验是通过分析一个简单 ...
- 解题:SDOI 2013 保护出题人
题面 首先是愉快的推式子 $dp[i]=max(dp[i],\frac{sum[i]-sum[j-1]}{x[i]+(i-j)*d})(1<=j<=i<=n)$(考虑有一只僵尸正好走 ...
- selenium测试 - open Firefox
环境:Python2.7+selenium3+Firefox47 问题1: 在打开火狐浏览器时报错:‘geckodriver‘ executable needs to be in PATH fro ...
- centos7安装python-pip(转)
好久没更新博客了............. 来一发................ 在使用centos7的软件包管理程序yum安装python-pip的时候会报一下错误: No package pyt ...
- C/C++ Volatile关键词深度剖析
文章来源:http://hedengcheng.com/?p=725 背景 此微博,引发了朋友们的大量讨论:赞同者有之:批评者有之:当然,更多的朋友,是希望我能更详细的解读C/C++ Volatile ...
- sleep php函数
<?php echo date('h:i:s') . "<br />"; //暂停 10 秒 sleep(10); //重新开始 echo date('h:i:s ...
- PhpStorm 快速查找文件 `Ctrl`+`Shift`+`N`
PhpStorm 快速查找文件 `Ctrl`+`Shift`+`N`
- windows中apache+tomcat整合,使php和java项目能够独立运行
一.下载和安装 1.安装php 网上有安装教程,不再赘述 2.安装apache 比如安装目录为e:\apache; 项目根目录为e:\www; 网上有安装教程,不再赘述 3.安装jdk 不再 ...
- 基于packstack的openstack单节点安装
一.安装源处理 1.更新base源为网易的源 cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo ...