I have just been using Python and there are some things that I still confuse, my question is in this code:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
Why in " if __name__ == "__main__":
" he did not instantiate the class PythonOrgSearch
and why putting the " unittest.main()
" command executed the actions of the PythonOrgSearch class? This way you will not get confused? Can anyone explain why he did it this way?