当前位置:网站首页>Po mode deep encapsulation
Po mode deep encapsulation
2022-07-01 09:51:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
The goal is
1. Be able to adopt the idea of inheritance to PO Patterns are deeply encapsulated
1. V6 edition
Encapsulate the common operation extraction into the parent class , The subclass directly calls the methods of the parent class , Avoid code redundancy
1. Object library layer - Base class , Define the method of locating the element in the base class
2. The operational layer - Base class , Define the methods that perform input operations on elements in the base class
1.1 Sample code
# base_page.py
from po.utils import DriverUtil class BasePage:
"""
Base class - Object library layer
"""
def init (self):
self.driver = DriverUtil.get_driver()
def find_element(self, location):
return self.driver.find_element(location[0], location[1])
class BaseHandle: """
Base class - The operational layer
"""
def input_text(self, element, text): """
Enter text in the input box , Clear it first and then enter
:param element: The element to operate on
:param text: Text content to enter
"""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): """
Object library layer
"""
def init (self): super(). init ()
# User name input box
self.username = (By.ID, "username") # The secret code
self.password = (By.ID, "password")
# Verification Code
self.verify_code = (By.ID, "verify_code")
# The login button
self.login_btn = (By.NAME, "sbtbutton")
# Forget the password
self.forget_pwd = (By.PARTIAL_LINK_TEXT, " Forget the password ")
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): """
The operational layer
"""
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: """
The business layer
"""
def init (self): self.login_handle = LoginHandle()
# deng record
def login(self, username, password, verify_code):
# enter one user name
self.login_handle.input_username(username)
# Input password
self.login_handle.input_password(password)
# Enter verification code
self.login_handle.input_verify_code(verify_code)
# Click the login button
self.login_handle.click_login_btn()
# Jump to the forgot password page
def to_forget_pwd_page(self):
# Click forget password
self.login_handle.click_forget_pwd()Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/131762.html Link to the original text :https://javaforall.cn
边栏推荐
- 项目必用的全局异常处理器,你学会了吗
- TC8:UDP_USER_INTERFACE_01-08
- 吃一个女富豪的瓜。。。
- sql语句修改字段类型「建议收藏」
- 历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...
- Analysis and solution of JS this loss
- 7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!
- JS use toString to distinguish between object and array
- Click the screen with your finger to simulate F11 and enter the full screen
- SSH服务器拒绝密码,再试一次;PermitRootLogin yes无效问题
猜你喜欢
随机推荐
IPv6 learning notes
Comparison between Oracle JDK and openjdk
这样理解mmap,挺有意思!
4hutool实战:DateUtil-格式化时间[通俗易懂]
Some tools used in embedded development
Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture
PHP merges multiple arrays. The same element takes the intersection of different elements to form an array
What is P in cap theory
The market is relatively weak recently
Dotnet console uses microsoft Maui. Getting started with graphics and skia
Precautions for lvgl v8.2 string display on keil MDK (take little bear pie as an example)
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
Graduation summary of actual combat camp
Can you afford to buy a house in Beijing, Shanghai, Guangzhou and Shenzhen with an annual salary of 1million?
京东与腾讯续签三年战略合作协议;起薪涨至26万元!韩国三星SK争相加薪留住半导体人才;Firefox 102 发布|极客头条...
Click the screen with your finger to simulate F11 and enter the full screen
Flinkv1.13 implementation of financial anti fraud cases
SQL learning notes (04) - data update and query operations
JS scope chain and closure
JS prototype trap







