当前位置:网站首页>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学习笔记(02)——数据库表操作
- The market is relatively weak recently
- 好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
- 谁拥有穿越周期的眼光?
- LVGL V8.2字符串显示在Keil MDK上需要注意的事项(以小熊派为例)
- Clickhouse: Test on query speed of A-share minute data [Part 2]
- Live broadcast management project
- SSH服务器拒绝密码,再试一次;PermitRootLogin yes无效问题
- Computer USB, HDMI, DP various interfaces and speeds
猜你喜欢

Eat a rich woman's melon...

Hololens2 development -6-eyetracking and speech recognition

Import and export of power platform platform sharepointlist

吃一个女富豪的瓜。。。

这样理解mmap,挺有意思!

Fried money, lost 10million.

SQL学习笔记(01)——数据库基本知识

TC8:UDP_USER_INTERFACE_01-08

Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"

架构实战营 模块九:设计电商秒杀系统
随机推荐
SQL learning notes (01) - basic knowledge of database
SSH服务器拒绝密码,再试一次;PermitRootLogin yes无效问题
那个程序员,被打了。
主流实时流处理计算框架Flink初体验
嵌入式开发用到的一些工具
UE small knowledge point controller possess pawn process
Import and export of power platform platform sharepointlist
Can you afford to buy a house in Beijing, Shanghai, Guangzhou and Shenzhen with an annual salary of 1million?
Meituan P4 carefully collated microservice system architecture design manual to see the world of microservice architecture
PHP code audit and File Inclusion Vulnerability
Initial experience of Flink, a mainstream real-time stream processing computing framework
架构实战营 毕业总结
JS scope chain and closure
JS prototype trap
项目必用的全局异常处理器,你学会了吗
Upload labs for file upload - white box audit
JS prototype inheritance can only inherit instances, not constructors
Introduction to mt7628k eCos development
Short circuit operator lazy evaluation
JS prototype chain