Test a login and logout. I already instantiated a webdriver, when I logged in. I want to reference this driver. in the logout case. How can I refer to this driver?
Why should I refer to the driver, in the login case instead of instantiating another driver? in the logout case If I instantiate a driver, again when I log out, then I open another browser and the test appears discontinuous given a url,;
the code is as follows
class TestLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(10)
self.driver.get("https://www.some.com/aa/login.jsp")
def test_login(self):
username = "xxx"
password = "yyy!"
login_page = Login()
login_page.user_login(self.driver, username, password)
self.check_login()
def check_login(self):
current_url = self.driver.current_url
expected_url = "/aa/main/index.do"
self.assertIn(expected_url, current_url, msg="")
def tearDown(self):
self.driver.quit()
class TestLogout(unittest.TestCase):
-sharp casecase
def setUp(self, driver):
self.driver = driver
def test_logout(self):
logout_button = self.driver.find_element_by_xpath("//a[@onclick="exitLogin();"]")
logout_button.click()
logout_confirm = self.driver.find_element_by_css_selector(".exitLogin .btn-primary")
logout_confirm.click()
self.check_logout()
def check_logout(self):
current_url = self.driver.current_url
expected_url = "aa/login.jsp"
self.assertIn(expected_url, current_url, msg="")
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(TestLogin("test_login"))
suite.addTest(TestLogout("test_logout"))
runner = unittest.TextTestRunner()
runner.run(suite)