I have created some Test Cases in Selenium Python and I have put it in a Test Suite. Each time a Test Case runs it opens the browser and navigates to the URL. It then logs in, does some tests and then logs out and the browser closes.
Is there a way to run the tests to only open 1 instance of the browser, log in once and keep using that instance for the rest of the test cases?
I do not want to close the browser for every single test case and open a new browser and log in each time.
For e.g. Test Case 1 runs, opens the browser, navigate to URL, log in, run some tests. Log out and close the browser.
Test Case 2 runs, opens the browser, navigate to URL, log in, run some tests. Log out and close the browser.
Test Case 3 opens the browser, navigate to URL, log in, run some tests. Log out and close the browser.
and so on.
I would like to do it this way.
Test Case 1 runs, opens the browser, navigate to URL, log in, run some tests. Log out and close the browser.
Test Case 2 use the same browser from test case 1, you are still logged in, run some tests.
Test Case 3 use the same browser from test case 1, you are still logged in, run some tests.
The last test case use the same browser from test case 1, you are still logged in, run some tests. Log out, close the browser.
Opening a new browser for every single test case and logging in takes longer for the tests to complete.
My code snippet is as follows:
class BaseTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Ie(Globals.IEdriver_path)
cls.driver.get(Globals.URL_justin_pc)
cls.login_page = login.LoginPage(cls.driver)
cls.driver.implicitly_wait(120)
cls.driver.maximize_window()
@classmethod
def tearDownClass(cls):
cls.login_page.click_logout()
cls.driver.close()
Test Case 1
class AdministrationPage_TestCase(BaseTestCase):
def test_add_Project(self):
print "*** test_add_project ***"
self.login_page.userLogin_valid(Globals.login_username, Globals.login_password)
menu_bar = MenuBarPage(self.driver)
administration_page = menu_bar.select_menuBar_item("Administration")
administration_page.click_add_project_button()
administration_page.add_project(project_name, Globals.project_description)
administration_page.click_save_add_project()
# etc ...
def test_edit_Project(self):
...
Test Case 2
class DataObjectsPage_TestCase(BaseTestCase):
def testa_add_Data_Objects_Name(self):
print "*** test_add_Data_Objects - Name ***"
self.login_page.userLogin_valid(Globals.login_username, Globals.login_password)
menu_bar = MenuBarPage(self.driver)
data_configuration_page = menu_bar.select_menuBar_item("Data Configuration")
project_navigator = ProjectNavigatorPage(self.driver)
data_objects = project_navigator.select_projectNavigator_item("Data Objects")
data_objects.click_add_button_for_data_objects()
def testb_add_Data_Objects_Address(self):
print "*** test_add_Data_Objects - Address ***"
...
def testc_add_Data_Objects_Phone(self):
...
Test Case 3 and so on
My Test Suite is:
def suite():
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(TestCases.AdministrationPage_TestCase.AdministrationPage_TestCase))
test_suite.addTest(unittest.makeSuite(TestCases.DataObjectsPage_TestCase.DataObjectsPage_TestCase))
# etc...
Thanks,
Riaz