0

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")

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

1 Comment

it works but the last statement "done" not printing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.