我有2个文件:
conftest.py
import pytest
from selenium import webdriver
driver = None
@pytest.fixture
def browserSetAndClose():
global driver
EXE_PATH = r'C:\Users\1602746\Softwares\chromedriver.exe'
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(executable_path = EXE_PATH, options = chromeOptions,
desired_capabilities = chromeOptions.to_capabilities())
driver.implicitly_wait(10)
driver.maximize_window()
driver.get('http://the-internet.herokuapp.com/')
yield driver
driver.quit()
xzbc.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from browser_factory import conftest
def test_abTest(browserSetAndClose):
wait = WebDriverWait(conftest.driver, 15)
wait.until(expected_conditions.element_to_be_clickable((By.XPATH, "//a[starts-with(@href, '/abtest')]"))).click()
a = wait.until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "h3"))).text
assert 'A/B Test' in a
问题是我不断收到错误消息-
未找到装置'browserSetAndClose'
当我运行测试用例函数test_abTest时。
我尝试了一切,但徒劳无功。