Created
October 20, 2012 02:22
-
-
Save adamgoucher/3921739 to your computer and use it in GitHub Desktop.
how to use webdriver with py.test fixtures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
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
Pretty clear and it works for me.