连接异常终止问题-Selenium

时间:2018-12-19 23:51:30

标签: python selenium

我正在研究一本Selenium / Python书籍,当我按原样运行下面的代码时,它可以正常运行并返回单个测试的结果。但是,当我取消注释第二项测试(在下面注释)时,它将返回错误:

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

我无法弄清楚问题所在,代码看起来与书中的代码相同。有什么想法吗?

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

编辑:我已经确认,当我注释掉第一个测试并仅运行第二个测试时,也可以正常运行。因此,这是因为同时运行两个测试都会引发错误...

0 个答案:

没有答案
相关问题