pycharm的页面分层
基础层:页面上获取的定位
页面层:将基础层进行组合
用例:将页面层组装成一个流程
不多说了,直接贴代码吧
LoginBase.py
#-*- coding:utf-8 -*-
# @Author : Eason猪油渣
# @Time : 2023/3/15 21:28
class LoginBase:
def login_input(self,input_placeholder):
return "//input[@placeholder='"+input_placeholder+"']"
def login_button(self,button_name):
return "//span[text()='"+button_name+"']"
LoginPage.py
#-*- coding:utf-8 -*-
# @Author : Eason猪油渣
# @Time : 2023/3/15 21:47
from base.LoginBase import LoginBase
from base.ObjectMap import ObjectMap
from selenium.webdriver.common.by import By
from common.yaml_config import Getconf
class LoginPage(LoginBase,ObjectMap):#继承登录的定位类和工具类
def login_input_value(self,driver,input_placeholder,input_value): #输入框
input_xpath=self.login_input(input_placeholder)
return self.element_fill_value(driver,By.XPATH,input_xpath,input_value)
#element_fill_value点击元素,可看我(9)篇文档对点击元素的封装
def click_login(self,driver,button_name): #点击框
button_xpath=self.login_button(button_name)
return self.element_click(driver,By.XPATH,button_xpath) #element_click点击元素,可看我(7)篇文档对点击元素的封装
def login(self,driver,user):#组合登录流程
self.element_to_url(driver,'/login?url=%2F') #element_to_url封装,看(10)篇文档
username,password=Getconf().get_username_password(user)
self.login_input_value(driver,'用户名',username)
self.login_input_value(driver, '密码', password)
self.click_login(driver,"登录")
TestLogin.py
#-*- coding:utf-8 -*-
# @Author : Eason猪油渣
# @Time : 2023/3/15 21:23
from config.driver_config import DriverConfig
from page.LoginPage import LoginPage
import time
class TestLogin:
def test_login(self):
driver=DriverConfig().driver_config(self)
LoginPage().login(driver,"jay")
time.sleep(5)
driver.quit()
利用的是pytest进行的运行。还没有做好报告之类的,还得慢慢学习