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()
编辑:我已经确认,当我注释掉第一个测试并只运行第二个测试时,它也运行良好。所以这是关于让两个测试都运行而引发错误的事情......
解决方案
推荐阅读
- python - 如何根据上传的带有 Flask 包的 csv 文件进行输出?
- r - 使用 R,如何获取传递给函数的所有参数及其值?
- angular - 多次运行 http.get 时出错 - 无法读取未定义的属性“get” - Angular
- python - 逐元素numpy矩阵乘法
- angular - IDB 的 Observable 不返回值
- android - 如何在小米设备中以编程方式允许通知声音
- javascript - 我正在更改状态,但未呈现订阅的组件
- python - 如何在 S3 上的每个文件夹中抓取下载链接
- typescript - 打字稿在界面上使用省略
- python - 根据来自 2nd DataFrame 的条件,从 1 DataFrame 中选择一个值,并将该值粘贴到第一个 DataFrame 中的新列