Ошибка при передаче фикстуры в параметр функции
Проблема при передаче в параметре фикстуры в функцию
Импорт и фикстура:
import pytest
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
@pytest.fixture()
def browser():
chrome_browser = webdriver.Chrome()
chrome_browser.implicitly_wait(10)
return chrome_browser
Функия, в которую передаю фикстуру, её вызов:
def check_Botton(browser):
browser.get('https://www.qa-practice.com/elements/button/simple')
browser.find_element(By.ID, 'submit-id-submit').click()
assert browser.find_element(By.ID, 'result-text').is_displayed()
check_Botton(browser)
Ошибка:
browser.get('https://www.qa-practice.com/elements/button/simple')
^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'get'
Пробовал гуглить, вроде, корректно передаю. Пробовал передавать как check_Botton(browser())
, так как передается функция, но возникает ошибка, отсылающая к документации:
raise Failed(msg=reason, pytrace=pytrace)
Failed: Fixture "browser" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
See https://docs.pytest.org/en/stable/explanation/fixtures.html for more information about fixtures, and
https://docs.pytest.org/en/stable/deprecations.html#calling-fixtures-directly about how to update your code.
Перепроверял вот таким образом, работает корректно:
def check_Botton():
browser = webdriver.Chrome()
browser.get('https://www.qa-practice.com/elements/button/simple')
browser.find_element(By.ID, 'submit-id-submit').click()
assert browser.find_element(By.ID, 'result-text').is_displayed()
check_Botton()
Источник: Stack Overflow на русском