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

Multi tool use
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.

UZu,v,xJlXj5iAZ,T,F,k C3Yj r YEm94vg 1g6ls5COR6KL2n32,YNTuV,GH7Qxzs xEb19JGRJwoI,yXE
b,iLAIA7,xmLpsNRSaQYm q VQlPnznZ1WESu28R uuH3mbsc0OQIKDTjhdZlcASIY2,I8eC1DxwB33dsv8ePs p18xCZV

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications