selenium+pytest.fixture
Posted @半良人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium+pytest.fixture相关的知识,希望对你有一定的参考价值。
import time
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
@pytest.fixture(scope='session')
def driver():
dr = webdriver.Chrome()
dr.maximize_window()
yield dr
time.sleep(30)
dr.quit()
@pytest.fixture()
def login(driver):
driver.get('http://www.baidu.com')
login_phone = (By.XPATH, '//form/div[1]/div/div/div/div/input')
login_pwd = (By.XPATH, '//input[@placeholder="请输入密码"]')
login_bt = (By.XPATH, '//form/div[4]/div/div[1]/div/button')
driver.find_element(*login_phone).send_keys('11111111111')
driver.find_element(*login_pwd).send_keys('654321')
driver.find_element(*login_bt).click()
@pytest.fixture()
def click_menu(driver, login):
def func(menu, sub_menu):
menu2 = "//*[text()=' " + menu + " ']"
ordermang = (By.XPATH, menu2)
baobeilist = (By.LINK_TEXT, sub_menu)
time.sleep(20)
driver.find_element(*ordermang).click()
driver.find_element(*baobeilist).click()
time.sleep(20)
return func
以上是关于selenium+pytest.fixture的主要内容,如果未能解决你的问题,请参考以下文章
fixture (使用pytest.fixture 替换使用setup, yield替换使用teardown)