Skip to content

Instantly share code, notes, and snippets.

@adamgoucher
Created October 20, 2012 02:22
Show Gist options
  • Save adamgoucher/3921739 to your computer and use it in GitHub Desktop.
Save adamgoucher/3921739 to your computer and use it in GitHub Desktop.
how to use webdriver with py.test fixtures
from selenium.webdriver import Firefox
import pytest
class TestHighcharts(object):
@pytest.fixture(autouse=True)
def fixture(self, request):
request.instance.driver = Firefox()
request.instance.driver.get("http://localhost:9000")
def cleanup():
request.instance.driver.quit()
request.addfinalizer(cleanup)
def test_series(self):
s = self.driver.execute_script('return chart.series;')
print(s)
@salunkhe-ravi
Copy link

How bout this?:

#conftest.py

@pytest.fixture(scope="session")
def setup(request):
print("initiating chrome driver")
driver = webdriver.Chrome(ChromeDriverManager().install())
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj, "driver", driver)
yield driver
driver.quit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment