python - I am using unittest.TestCase if i have more than 1 test case it will not run. Only 1 test case runs -
i automating our website. using python, webdriver, unittest.testcase
.
i had 1 test method defined in login page class test valid user log in. works fine.
now adding 2nd test method called test_login_invalid_user test invalid user log in. browsing log in page start see if 2nd test method gets called when run test.
when run code following error:
traceback (most recent call last): file "c:\users\riaz.ladhani\pycharmprojects\selenium webdriver\clearcore \loginpage_testcase.py", line 40, in test_login_invalid_user login_page = page.login(self.driver) attributeerror: 'module' object has no attribute 'login'
can not have more 1 test method in unit test? doing wrong way?
my unit test class code snippet follows:
import unittest selenium import webdriver import page import time class loginpage_testcase(unittest.testcase): def setup(self): self.driver = webdriver.ie("c:\qa\automation\python_projects\selenium webdriver\iedriverserver_win32_2.45.0\iedriverserver.exe") self.driver.get("http://riaz-pc.company.local:8080/clearcore") def test_login_valid_user(self): login_page = page.loginpage(self.driver) login_page.userlogin_valid() login_page.isadministration_present() assert login_page.isadministration_present(), "administration not found" if login_page.isadministration_present() == "true": print "test login valid user passed" else: print "test login valid user failed" def test_login_invalid_user(self): print "test_login_invalid_user" login_page = page.login(self.driver) def teardown(self): self.driver.close() if __name__ == "__main__": unittest.main()
from understand, meant define new loginpage
page object instance instead:
def test_login_invalid_user(self): print "test_login_invalid_user" login_page = page.loginpage(self.driver)
if case, avoid violating "dry" principle , improve readability, instantiate loginpage
in setup()
:
class loginpage_testcase(unittest.testcase): def setup(self): self.driver = webdriver.ie("c:\qa\automation\python_projects\selenium webdriver\iedriverserver_win32_2.45.0\iedriverserver.exe") self.driver.get("http://riaz-pc.company.local:8080/clearcore") self.login_page = page.loginpage(self.driver) def test_login_valid_user(self): self.login_page.userlogin_valid() self.login_page.isadministration_present() assert self.login_page.isadministration_present(), "administration not found" if self.login_page.isadministration_present() == "true": print "test login valid user passed" else: print "test login valid user failed" def test_login_invalid_user(self): print "test_login_invalid_user" # use self.login_page here
Comments
Post a Comment