selenium-pageobject设计模式
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from pip._vendor.distlib.locators import Page
from selenium.webdriver.support.ui import Select#导入下拉框函数
import unittest
class Page(object):
login_url = 'http://qf-uatqapp-w2/ProductApplication/Application'
def __init__(self, selenium_driver, base_url=login_url):
self.base_url = base_url
self.driver = selenium_driver
self.timeout = 30
self.driver.maximize_window()
def on_page(self):
return self.driver.current_url == (self.base_url + self.url)
def _open(self, url):
url=self.base_url
self.driver.get(url)
self.driver.maximize_window()
#assert self.on_page(), 'Did not land on %s' %url
def open(self):
self._open(self.url)
def find_element(self, *loc):
return self.driver.find_element(*loc)
def switch_frame(self, loc):
return self.driver.switch_to_frame()
class LoginPage(Page):
url = '/'
username_loc = (By.ID, "Account")
password_loc = (By.ID, "Pwd")
submit_loc = (By.ID,"Log_Submit")
def type_username(self, username):
self.find_element(*self.username_loc).send_keys(username)
def type_password(self,password):
self.find_element(*self.password_loc).send_keys(password)
def submit(self):
self.find_element(*self.submit_loc).click()
class ProductPage(Page):
customername_loc = (By.ID, "customerName")
customerID_loc = (By.ID,"customerIDCard")
applyCity_loc = (By.ID,"applyCity")
# productCode_loc = (By.ID,"//option[@value='productCodesyd-6-24']")
# productCode_value = (By.XPATH,"//option[@value='BYQSF0000']")
# platform_loc = (By.ID,"platform")
#platform_value = (By.XPATH,"//option[@value='BYQSF0000']")
def type_customername(self, customername):
self.find_element(*self.customername_loc).send_keys(customername)
def type_customerID(self, customerId):
self.find_element(*self.customerID_loc).send_keys(customerId)
def type_applyCity(self, applyCityvalue):
Select(self.find_element(*self.applyCity_loc)).select_by_value(applyCityvalue)#下拉框函数
def test_user_login(driver, username, password):
page = LoginPage(driver)
page.open()
page.type_username(username)
page.type_password(password)
page.submit()
def test_apply_product(driver,customername, customerID, applyCityvalue):
page1 = ProductPage(driver)
page1.type_customername(customername)
page1.type_customerID(customerID)
page1.type_applyCity(applyCityvalue)
def main():
driver = webdriver.Chrome()
username = 'jiahua'
password = 'Quarkhj05'
customername = u'huajia'
customerId = '310104198408020057'
applyCityvalue = '025,025'
test_user_login(driver,username,password)
driver.implicitly_wait(30)
test_apply_product(driver,customername, customerId, applyCityvalue)
if __name__ == '__main__':
main()
unittest.main()
原文转自http://www.cnblogs.com/jerryhua/p/5794868.html
selenium-pageobject设计模式的更多相关文章
- PageObject设计模式,在selenium自动化测试中的运用
PageObject设计模式1. Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 2. web测试时,建议 ...
- selenium的PageObject设计模式
PageObject设计模式1. Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 2. web测试时,建议 ...
- PageObject设计模式 在selenium 自动化测试里面的应用
PageObject设计模式1. Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 2. web测试时,建议 ...
- 聊聊UI自动化的PageObject设计模式
当我们开发UI自动化测试用例时,需要引用页面中的元素(数据)才能够进行点击(动作)并显示出页面内容.如果我们开发的用例是直接对HTML元素进行操作,则这样的用例无法"应对"页面中U ...
- Page-Object设计模式
自动化脚本初写之际一定是只求完成功能测试,页面by.id.by.name.by.xpath满篇飞.业务逻辑代码重复率也是越来越高.慢慢的写着写着开始重构,开始封装一些方法.代码量好一些的人会在代码开始 ...
- 记我的第二次自动化尝试——selenium+pageobject+pagefactory实现自动化下单、退款、撤销回归测试
需求: 系统需要做下单.退款.撤销的回归测试,有下单页面,所以就想到用selenium做WEB UI 自动化 项目目录结构: common包上放通用的工具类方法和浏览器操作方法 pageobject包 ...
- Python+Selenium+PageObject
一.安装page_objects测试库 二.目录介绍 1.pages包:用于各界面元素定位,如BaseLoginPage.py 2.testcases包:用于编写各功能测试用例,如Login.py 3 ...
- selenium +python之Page Obiect设计模式
PageObject是selenium自动化测试项目开发实践的最佳设计模式之一,它主要体现对界面交互细节的封装,这样可以使测试案例更关注于业务而非界面细节,从而提高测试案例的可读性. 1.认识Page ...
- selenium自动化测试框架之PO设计模式
面向对象的特性:封装.继承.多态.在自动化中一样适用,Selenium自动化测试中有一个名字常常被提及PageObject(思想与面向对象的特性相同),通过PO模式可以大大提高测试用例的维护效率. 传 ...
- [小北De编程手记] : Lesson 08 - Selenium For C# 之 PageFactory & 团队构建
本文想跟大家分享的是Selenium对PageObject模式的支持和自动化测试团队的构建.<Selenium For C#>系列的文章写到这里已经接近尾声了,如果之前的文章你是一篇篇的读 ...
随机推荐
- winform版弹框操作
公共弹框帮助类操作手册 1.说明 封装了对于winform操作的一些提示框,包括数据加载耗时的时候,提示数据正在加载,请稍后的提示窗体,动态提示给用户一些有用的信息.例如网吧里面续费提醒等. 2.操作 ...
- DelphiXE2 DataSnap开发技巧收集
DelphiXE2 DataSnap开发技巧收集 作者: 2012-08-07 09:12:52 分类:Delphi 标签: 作为DelphiXE2 DataSnap开发的私家锦囊, ...
- 制作一个简洁的jquery插件
原文:http://mp.weixin.qq.com/s?__biz=MzAxMzgwNDU3Mg==&mid=401571467&idx=1&sn=08cb00963e6ef ...
- Python第一模块
一.Python简介 二.Python种类 三.Python环境 windows: 1.需要配置环境变量 2.更新:卸载重装 linux:1.常用命令: 查看默认Python版本 Python -V ...
- ubuntu 下搭建nginx
1.安装nginx sudo apt-get install nginx 2.nginx 的启动和关闭启动 nginx:# nginx -c /etc/nginx/nginx.conf 3.关闭 ng ...
- Scala包
#引入包的全部成员的办法 import scala.collection._ #引入同一个包中的几个成员 import scala.collection.{A,B} #重名 要 重命名 import ...
- CC1310电源
CC1310的电源好扯,把目前遇到的问题记录一下 1 全局LDO和DCDC的输出电压问题 手册上要求的VDDR和VDDR_RF的电压范围是1.7~1.95V,但实际测试时, 在接收状态下无论是全局LD ...
- JavaScript 随笔2 面向对象 原型链 继承
第六章 面向对象的程序设计 1.创建对象的几种方式 A)工厂模式 function CreatObj(name,sex,age){ this.name=name; this.sex=sex; this ...
- less预处理的好处,补充关于之前发表的rem单位的运用于计算
我认识的less 优点:优雅,好用,简单,可复用性强, 缺点:less并其实不能为我们减少沉余css代码,还是要靠自己的CSS基础去判断哪些是沉余代码或者是可以合并的代码 之前发表的一篇文章一看就懂得 ...
- 足球游戏AI_资料收集
实况足球中文官网 浅谈足球游戏的人工智能 用遗传算法加强足球游戏的人工智能 足球规则图解 守门员的技巧你知道吗? 教你足球守门员守门技术练习方法和技巧 足球守门员规则 判断点球方向