Reputation: 71
I am testing a website called-https://huew.co
for that I am developing my framework. In utils/create_driver, I wrote my code which will open the browser by user input like if user enter 'chrome' in terminal and env=local
Example: python -m pytest test/test_infilect.py --type=chrome --env=local then chrome browser should initialize and open the url which is provided.
but i am getting Error- UnboundLocalError: local variable 'driver' referenced before assignment
And Warning:
PytestDeprecationWarning: the pytest.config
global is deprecated. Please use request.config
or pytest_configure
(if you'r
e a pytest plugin) instead.
url = pytest.config.option.env.lower()
PytestDeprecationWarning: the pytest.config
global is deprecated. Please use request.config
or pytest_configure
(if you'r
e a pytest plugin) instead.
browser_info = pytest.config.option.env.lower()
Help in regarding the same.
from selenium.webdriver import Chrome,Firefox,Ie
import pytest
# @pytest.fixture
def get_browser_instance():
browser_info = pytest.config.option.env.lower()
url = pytest.config.option.env.lower()
if browser_info == 'chrome':
driver = Chrome('./browser_exe/chromedriver.exe')
elif browser_info == 'firefox':
driver = Firefox('./browser_exe/geckodriver.exe')
elif browser_info == 'ie':
driver = Ie('./browser_exe/IEDriverServer.exe')
driver.maximize_window()
driver.implicitly_wait(60)
if url == 'local':
driver.get('https://huew.co/')
return driver
Test should run when I am entering command from pycharms terminal- python -m pytest test/test_infilect.py --type=chrome --env=local
Upvotes: 2
Views: 3177
Reputation: 807
Simply pass request
as an argument to your fixture and replace references to pytest.config
in your fixture body with request.config
.
Upvotes: 1