Skip to content

Instantly share code, notes, and snippets.

@poliarush
Created April 27, 2015 19:32
Show Gist options
  • Save poliarush/50398925888827306b0e to your computer and use it in GitHub Desktop.
Save poliarush/50398925888827306b0e to your computer and use it in GitHub Desktop.
manage webdriver instance with pytest
import pytest
class BaseTest(object):
@pytest.fixture(scope="class", autouse=True)
def manage_driver(self, request, driver):
driver.start()
request.addfinalizer(driver.stop)
import pytest
from selenium import webdriver
class DriverManager(object):
def __init__(self):
self._instance = None
def start(self, type='ff'):
# implement logic to create instance depends on condition
self._instance = webdriver.Firefox()
return self._instance
@property
def instance(self):
if not self._instance:
self.start()
return self._instance
def stop(self):
self._instance.close()
@pytest.fixture(scope="module")
def driver():
return DriverManager()
from common import BaseTest
class TestClass1(BaseTest):
def test_1_1(self, driver):
driver.instance.get('http://lessons2.ru/python-for-testers/')
def test_1_2(self, driver):
driver.instance.get('http://automated-testing.info')
class TestClass2(BaseTest):
def test_2_1(self, driver):
driver.instance.get('http://lessons2.ru/')
def test_2_2(self, driver):
# driver.instance.get('http://poliarush.com')
driver.instance.get('http://twitter.com/autotestinfo')
from common import BaseTest
class TestClass3(BaseTest):
def test_3_1(self, driver):
driver.instance.get('http://www.facebook.com/autotestinfo')
def test_3_2(self, driver):
driver.instance.get('http://vk.com/autotestinfo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment