Reputation: 93
I have a class with few tests, for example:
class Example(Environment)
def test1(self):
def test2(self):
def test3(self):
def test4(self):
and class environment with setup and teardown methods
class Environment(unittest.TestCase):
def setUp(self):
options_for_console_log = DesiredCapabilities.CHROME
options_for_console_log['loggingPrefs'] = {'browser': 'ALL'}
self.driver = webdriver.Chrome(desired_capabilities=options_for_console_log)
self.driver.maximize_window()
def tearDown(self):
driver = self.driver
driver.close()
After every test chrome reopens, but i want to run it in one session. How can i do it?
Upvotes: 1
Views: 1243
Reputation: 81684
setUp
and tearDown
are called before and after every test method. If you want driver
to persist between tests move the relevant code to setUpClass
and tearDownClass
:
@classmethod
def setUpClass(cls):
options_for_console_log = DesiredCapabilities.CHROME
options_for_console_log['loggingPrefs'] = {'browser': 'ALL'}
cls.driver = webdriver.Chrome(desired_capabilities=options_for_console_log)
cls.driver.maximize_window()
@classmethod
def tearDownClass(cls):
cls.driver.close()
Just make sure that all the test cases are independent and standalone.
Upvotes: 3