Facing TypeError: unbound method setUpClass() must be called with HomePageTest instance as first argument (got nothing instead)

Multi tool use
Facing TypeError: unbound method setUpClass() must be called with HomePageTest instance as first argument (got nothing instead)
Here the below script which i have tried
import unittest
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
class HomePageTest (unittest.TestCase):
def setUpClass(self):
self.driver = webdriver.Firefox()
self.driver.get("http://magento-demo.lexiconn.com/")
self.driver.maximize_window()
def test_searchbox(self):
driver=self
driver.assertTrue (driver.is_element_present (By.ID,"search"))
driver.assertTrue (driver.driver.find_element_by_id("search").is_enabled())
def tearDownClass(self):
self.driver.quit()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
if __name__ == '__main__':
unittest.main(verbosity=2)
1 Answer
1
You need to make setUpClass - and tearDownClass - classmethods:
@classmethod
def setUpClass(cls):
...
@classmethod
def tearDownClass(cls):
...
See the unittest docs.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.