当在pytest中的另一个文件中定义了灯具时,灯具不可见

时间:2019-09-06 09:15:43

标签: python selenium pytest

我有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时。

我尝试了一切,但徒劳无功。

此外,这是项目结构的图像,以显示上述文件位于不同的目录中: Snapshot to show the above file locations in the project structure

0 个答案:

没有答案