Reputation: 103
I tries below unit test case and it doesnt open web browser and print directly "done" message.
from selenium import webdriver
import unittest
class GoogleSearch(unittest.TestCase):
# driver = None
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome(executable_path='../Drivers/chromedriver')
cls.driver.maximize_window()
def test_search(self):
self.driver.get('https://www.google.com')
self.driver.find_element_by_name("q").send_keys("facebook")
self.driver.implicitly_wait(10)
self.driver.find_element_by_name("btnI").click()
# driver.find_element_by_name("btnI").send_keys(Keys.ENTER)
@classmethod
def tearDownClass(cls):
# driver.implicitly_wait(5)
cls.driver.quit()
cls.print("test completed")
print("done")
Upvotes: 0
Views: 256
Reputation: 1045
After defining your unittest, you have to call it. Call the test with unittest.main()
.
from selenium import webdriver import unittest
class GoogleSearch(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome(executable_path='../Drivers/chromedriver')
cls.driver.maximize_window()
def test_search(self):
self.driver.get('https://www.google.com')
self.driver.find_element_by_name("q").send_keys("facebook")
self.driver.implicitly_wait(10)
self.driver.find_element_by_name("btnI").click()
# driver.find_element_by_name("btnI").send_keys(Keys.ENTER)
@classmethod
def tearDownClass(cls):
# driver.implicitly_wait(5)
cls.driver.quit()
cls.print("test completed")
if __name__ == '__main__':
unittest.main() # <- runs your unittest
print("done")
Upvotes: 1