1

I am working through a Selenium/Python book and when I run the below code as is, it runs fine and returns the results of the single test. When I uncomment out the 2nd test however (commented out below), it returns an error:

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

I can't figure out the issue, the code looks identical to what is in the book. Any ideas?

from selenium import webdriver
import unittest


class SearchTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # create a new Chrome session
        cls.driver = webdriver.Chrome()
        cls.driver.implicitly_wait(30)
        cls.driver.maximize_window()

        # navigate to the application home page
        cls.driver.get('http://demo-store.seleniumacademy.com/')
        cls.driver.title

    def test_search_by_category(self):

        # get the search textbox
        self.search_field = self.driver.find_element_by_name("q")
        self.search_field.clear()

        # enter search keyword and submit
        self.search_field.send_keys('phones')
        self.search_field.submit()

        # get all the anchor elements which have product names displayed
        # currently on result page using find_elements_by_xpath method
        products = self.driver.find_elements_by_xpath("//h2[@class='product-name']/a")
        self.assertEqual(3, len(products))

    # def test_search_by_name(self):
    #     # get the search textbox
    #     self.search_field = self.driver.find_element_by_name("q")
    #     self.search_field.clear()
    #
    #     # enter search keyword and submit
    #     self.search_field.send_keys('salt shaker')
    #     self.search_field.submit()
    #
    #     # get all the anchor elements which have product names displayed
    #     # currently on result page using find_elements_by_xpath method
    #     products = self.driver.find_elements_by_xpath("//h2[@class='product-name']/a")
    #     self.assertEqual(1, len(products))

    @classmethod
    def tearDown(cls):

        # close the browser window
        cls.driver.quit()


if __name__ == '__main__':
    unittest.main()

EDIT: I have confirmed that when I comment out the first test and run the second test only, that runs fine as well. So it's something about having both tests running that is throwing the error...

JD2775
  • 3,658
  • 7
  • 30
  • 52

0 Answers0