首先,我们得知道PO模式是什么,P(Page)O(Object)
1.打开浏览器
2.输入网易云主页的网址
3.点击登陆按钮,等待页面跳转
4.点击同意协议,点击跳转qq登录
5 点击QQ账号密码登录
6输入账号密码,回到网易云音乐页面
我们可以先创建几个文件夹,base(用于存放父类) page(用来定位操作页面上的元素) data(用于存放测试数据) log(用于打印日志) report(用于存放测试报告) screenshot(用于页面截图存放) script(用于存放测试脚本) tools(放置测试报告模板) config(日志初始化) runsuite(执行测试套件) utils)(创建工具类)
base
from utils import DriverUtil
import logging
import time
import os
from config import BASE_DIR
class BasePage:
"""
对象库层-基类
"""
def __init__(self):
self.driver = DriverUtil.GetDriver()
def find_element(self, location):
logging.info("location={}".format(location))
return self.driver.find_element(location[0], location[1])
class BaseHandle:
"""
操作层-基类
"""
def input_text(self, element, text):
"""
在输入框里输入文本内容,先清空再输入
:param element: 要操作的元素
:param text: 要输入的文本内容
"""
element.clear()
element.send_keys(text)
def click_object(self,element):
"定位元素并点击"
element.click()
class BaseProxy:
"""
业务层-基类
"""
def __init__(self):
self.driver = DriverUtil.GetDriver()
def ScreenShot(self):
try:
t = time.strftime("%Y-%m-%d-%H-%M-%S")
print(t)
img_path = "{}/screenshot/-{}.png".format(BASE_DIR,t)
print(img_path)
self.driver.get_screenshot_as_file(img_path)
except BaseException as msg:
print("%s:截图失败!!!!!!!!!!!!!!" %msg)
def obtain_title(self):
self.driver.title()
# 获取当前句柄切换
def Windows_switch(self):
driver = DriverUtil.GetDriver()
handle = driver.window_handles
print(handle)
driver.switch_to_window(handle[1])
def Windows_switch_return