当前位置:网站首页>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
边栏推荐
- SQL学习笔记(04)——数据更新、查询操作
- 那个程序员,被打了。
- Dspic30f6014a LCD block display
- 这样理解mmap,挺有意思!
- ES6 decoupling top-level objects from windows
- SQL学习笔记(02)——数据库表操作
- The "China Mobile Chain" state secret engine was officially launched on BSN
- Some tools used in embedded development
- 短路运算符惰性求值
- scratch大鱼吃小鱼 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月
猜你喜欢

Hololens2 development -6-eyetracking and speech recognition

Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture

dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门

微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”

Mikrotik Routeros Internet access settings

华为帐号多端协同,打造美好互联生活

Packetdrill script analysis guide

7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!
![Problems caused by delete and delete[]](/img/d9/a1c3e5ce51ef1be366a973aa42d1f0.png)
Problems caused by delete and delete[]

Live broadcast management project
随机推荐
Construction of esp8266 FreeRTOS development environment
123. how to stop a thread?
吃一个女富豪的瓜。。。
Apple amplification! It's done so well
SQL learning notes (04) - data update and query operations
Eat a rich woman's melon...
“中移链”国密引擎在BSN正式上线
怎么理解JS Promise
一个悄然崛起的国产软件,低调又强大!
Postgraduate entrance examination vocabulary 2023 sharing (1)
Dspic30f6014a LCD block display
js重写自己的函数
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!
Spark's action operator
Cortex M4 systick details
Project procurement management
Comparison between Oracle JDK and openjdk
JS prototype inheritance can only inherit instances, not constructors
SQL学习笔记(02)——数据库表操作