Created
April 27, 2015 19:32
-
-
Save poliarush/50398925888827306b0e to your computer and use it in GitHub Desktop.
manage webdriver instance with pytest
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
import pytest | |
class BaseTest(object): | |
@pytest.fixture(scope="class", autouse=True) | |
def manage_driver(self, request, driver): | |
driver.start() | |
request.addfinalizer(driver.stop) |
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
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() |
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 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') |
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 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