base层封装
(记住变成self.driver了,其他方法同理)
#鼠标悬停
def action_chain(self,loc):
sel = self.locater(loc)
ActionChains(self.driver).move_to_element(sel).perform()
page页面的元素以及操作流
class ProductManagePage(BasePage):
#页面元素
#点击主页
product_home = (By.XPATH,“/html/body/div[2]/div/div[3]/ul/li[1]/a”)
#鼠标悬停手机
phone_perform = (By.XPATH,“/html/body/div[1]/div[3]/div/div[2]/div/div[1]/div[1]/h3/div/a”)
#选择悬浮框里面的手机元素
phone_click = (By.XPATH,“/html/body/div[1]/div[3]/div/div[2]/div/div[1]/div[2]/div[1]/div[2]/dl[1]/dd/a[1]”)
#页面动作
def select_phone(self,driver):
#登录
lp = LoginPage(self.driver)
lp.login()
sleep(3)
#查找点击手机元素
self.click(ProductManagePage.product_home)
sleep(1)
self.action_chain(ProductManagePage.phone_perform)
sleep(1)
self.click(ProductManagePage.phone_click)
testcase层方法执行
class SelectPhone(unittest.TestCase):
def setUp(self) -> None:
global driver
# 打开浏览器
self.driver = webdriver.Chrome()
driver = self.driver
# 加载网页
self.driver.get("http://tpshop.com/Home/user/login.html")
def test_02_selectphone(self):
sp = ProductManagePage(self.driver)
sp.select_phone(driver)
def tearDown(self) -> None:
pass