当前位置:网站首页>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
边栏推荐
- Hardware midrange project
- 微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”
- Cortex M4 systick details
- Can you afford to buy a house in Beijing, Shanghai, Guangzhou and Shenzhen with an annual salary of 1million?
- SQL learning notes (02) - database table operation
- PHP merges multiple arrays. The same element takes the intersection of different elements to form an array
- 树莓派4B系统搭建(超详细版)
- 遇到女司机业余开滴滴,日入500!
- es6-顶层对象与window的脱钩
- JS use toString to distinguish between object and array
猜你喜欢

京东与腾讯续签三年战略合作协议;起薪涨至26万元!韩国三星SK争相加薪留住半导体人才;Firefox 102 发布|极客头条...

SQL learning notes (01) - basic knowledge of database

Cortex M4 systick details

Some tools used in embedded development

Mikrotik Routeros Internet access settings

CSDN一站式云服务开放内测,诚邀新老用户来抢鲜

Network counting 01 physical layer

Scratch big fish eat small fish Electronic Society graphical programming scratch grade examination level 2 true questions and answers analysis June 2022

Concept of digital currency

Upload labs for file upload - white box audit
随机推荐
button按钮清除边框
Using closures to implement private variables
Cortex M4 systick details
121. thread scheduling: join() method and yield() method
[unity rendering] customized screen post-processing
uniapp微信小程序组件按需引入
In terms of use
Swift control encapsulation - paging controller
JS variable lifting
tryhackme圣诞挑战2021-Advent of Cyber 3-day1-IDOR漏洞,不安全的访问控制漏洞
硬件中台项目
Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门
Clickhouse: Test on query speed of A-share minute data [Part 2]
Sleeping second brother...
Postgraduate entrance examination vocabulary 2023 sharing (1)
Drive away bad emotions and stop worrying
UE small knowledge point controller possess pawn process
遇到女司机业余开滴滴,日入500!