当前位置:网站首页>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
边栏推荐
- Error org apache. catalina. core. StandardContext. FilterStart start filter exception
- SQL学习笔记(03)——数据约束关系
- 7-Zip 遭抵制?呼吁者定下“三宗罪”:伪开源、不安全、作者来自俄罗斯!
- Strange, why is the ArrayList initialization capacity size 10?
- [unity shader] substitution of bool type in the property definition
- Swift control encapsulation - paging controller
- High precision factorial
- JS functionarguments object
- Rich text interpolation
- Who has the vision to cross the cycle?
猜你喜欢

Nacos service configuration and persistence configuration
![[untitled]](/img/1a/e18918cc09db9b072759409a5f39a1.png)
[untitled]

云原生到底是什么?它会是未来发展的趋势吗?

睡了二哥。。。

电脑USB、HDMI、DP各种接口及速度

Mikrotik Routeros Internet access settings

Structure de l'arbre - - - arbre binaire 2 traversée non récursive

JS scope chain and closure

How to realize the usage of connecting multiple databases in idel

嵌入式开发用到的一些工具
随机推荐
Nacos service configuration and persistence configuration
短路运算符惰性求值
HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
那个程序员,被打了。
历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...
ES6 const essence and completely immutable implementation (object.free)
Cortex M4 systick details
Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
Mikrotik Routeros Internet access settings
微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”
Short circuit operator lazy evaluation
UE small knowledge point controller possess pawn process
华为帐号多端协同,打造美好互联生活
Who has the vision to cross the cycle?
uniapp微信小程序组件按需引入
Rich text interpolation
es6-顶层对象与window的脱钩
Concept of digital currency
Problems caused by delete and delete[]
“中移链”国密引擎在BSN正式上线