当前位置:网站首页>PO模式深入封装
PO模式深入封装
2022-07-01 09:40:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
目标
1. 能够采用继承的思想对PO模式进行深入的封装
1. V6版本
把共同操作提取封装到父类中,子类直接调用父类的方法,避免代码冗余
1. 对象库层-基类,把定位元素的方法定义在基类中
2. 操作层-基类,把对元素执行输入操作的方法定义在基类中
1.1 示例代码
# base_page.py
from po.utils import DriverUtil class BasePage:
"""
基类-对象库层
"""
def init (self):
self.driver = DriverUtil.get_driver()
def find_element(self, location):
return self.driver.find_element(location[0], location[1])
class BaseHandle: """
基类-操作层
"""
def input_text(self, element, text): """
在输入框里输入文本内容,先清空再输入
:param element: 要操作的元素
:param text: 要输入的文本内容
"""element.clear() element.send_keys(text)from selenium.webdriver.common.by import By
from po.v6.common.base_page import BasePage, BaseHandle
class LoginPage(BasePage): """
对象库层
"""
def init (self): super(). init ()
# 用户名输入框
self.username = (By.ID, "username") # 密 码
self.password = (By.ID, "password")
# 验证码
self.verify_code = (By.ID, "verify_code")
# 登录按钮
self.login_btn = (By.NAME, "sbtbutton")
# 忘记密码
self.forget_pwd = (By.PARTIAL_LINK_TEXT, "忘记密码")
def find_username(self):
return self.find_element(self.username)
def find_password(self):
return self.find_element(self.password)
def find_verify_code(self):
return self.find_element(self.verify_code)
def find_login_btn(self):
return self.find_element(self.login_btn)
def find_forget_pwd(self):
return self.find_element(self.forget_pwd)
class LoginHandle(BaseHandle): """
操作层
"""
def init (self): self.login_page = LoginPage()
def input_username(self, username): self.input_text(self.login_page.find_username(), username)
def input_password(self, pwd): self.input_text(self.login_page.find_password(), pwd)
def input_verify_code(self, code): self.input_text(self.login_page.find_verify_code(), code)
def click_login_btn(self): self.login_page.find_login_btn().click()
def click_forget_pwd(self): self.login_page.find_forget_pwd().click()
class LoginProxy: """
业务层
"""
def init (self): self.login_handle = LoginHandle()
# 登 录
def login(self, username, password, verify_code):
# 输入用户名
self.login_handle.input_username(username)
# 输入密码
self.login_handle.input_password(password)
# 输入验证码
self.login_handle.input_verify_code(verify_code)
# 点击登录按钮
self.login_handle.click_login_btn()
# 跳转到忘记密码页面
def to_forget_pwd_page(self):
# 点击忘记密码
self.login_handle.click_forget_pwd()发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/131762.html原文链接:https://javaforall.cn
边栏推荐
- button按钮清除边框
- uniapp微信小程序组件按需引入
- [unity shader] substitution of bool type in the property definition
- Niuke monthly race 22- collect pieces of paper
- MT7628K eCos开发入门
- HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
- Learning practice: comprehensive application of cycle and branch structure (II)
- LeetCode 344. Reverse string
- Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
- Swag init error: cannot find type definition: response Response
猜你喜欢

Spark's action operator

主流实时流处理计算框架Flink初体验

SQL learning notes (01) - basic knowledge of database

集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常

The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
![[untitled]](/img/1a/e18918cc09db9b072759409a5f39a1.png)
[untitled]

睡了二哥。。。

Learning practice: comprehensive application of cycle and branch structure (II)

历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...

硬件中台项目
随机推荐
[unity rendering] customized screen post-processing
ES6-const本质与完全不可改实现(Object.freeze)
Get the list of a column in phpexcel get the letters of a column
SQL学习笔记(02)——数据库表操作
HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
直播管理项目
js重写自己的函数
云原生到底是什么?它会是未来发展的趋势吗?
Dotnet console uses microsoft Maui. Getting started with graphics and skia
JS rewrite their own functions
Precautions for lvgl v8.2 string display on keil MDK (take little bear pie as an example)
Solution of EPS image blur by latex insertion
delete和delete[]引发的问题
SQL学习笔记(04)——数据更新、查询操作
韦东山板子编译内核问题解决
Installation and use of NoSQL database
JS prototype trap
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
MT7628K eCos开发入门
Latex插入的eps图片模糊解决方法