from selenium import webdriver
import unittest
driver=webdriver.Chrome()
class Test_selenium(unittest.TestCase):
def setUp(self) -> None:
driver.get('https://cn.bing.com/')
def tearDown(self) -> None:
driver.quit()
def test_add1(self):
pass
def test_add2(self):
pass
if __name__ == '__main__':
unittest.main()
(venv) E:\GitHub\Python_Study\20200221>python test1.py
DevTools listening on ws://127.0.0.1:5981/devtools/browser/dc81c2e7-ae0b-4208-85de-f8bd7c5c91b1
.E
======================================================================
ERROR: test_add2 (__main__.Test_selenium)
----------------------------------------------------------------------
Traceback (most recent call last):
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connection.py", line 158, in _new_conn
conn = connection.create_connection(
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection
raise err
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\util\connection.py", line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "E:\Program Files\Python\Python3.8\lib\http\client.py", line 1230, in request
self._send_request(method, url, body, headers, encode_chunked)
File "E:\Program Files\Python\Python3.8\lib\http\client.py", line 1276, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "E:\Program Files\Python\Python3.8\lib\http\client.py", line 1225, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "E:\Program Files\Python\Python3.8\lib\http\client.py", line 1004, in _send_output
self.send(msg)
File "E:\Program Files\Python\Python3.8\lib\http\client.py", line 944, in send
self.connect()
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connection.py", line 181, in connect
conn = self._new_conn()
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connection.py", line 167, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001DAB9233040>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无
法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test1.py", line 10, in setUp
driver.get('https://cn.bing.com/')
File "E:\Program Files\Python\Python3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "E:\Program Files\Python\Python3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "E:\Program Files\Python\Python3.8\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "E:\Program Files\Python\Python3.8\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\request.py", line 70, in request
return self.request_encode_body(method, url, fields=fields,
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\poolmanager.py", line 324, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connectionpool.py", line 663, in urlopen
return self.urlopen(method, url, body, headers, retries,
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connectionpool.py", line 663, in urlopen
return self.urlopen(method, url, body, headers, retries,
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connectionpool.py", line 663, in urlopen
return self.urlopen(method, url, body, headers, retries,
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "E:\Program Files\Python\Python3.8\lib\site-packages\urllib3\util\retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=5974): Max retries exceeded with url: /session/0f4e20d5dc94be1b143190602f73b21a/url (Caused by NewConnectionErr
or('<urllib3.connection.HTTPConnection object at 0x000001DAB9233040>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))
----------------------------------------------------------------------
Ran 2 tests in 11.946s
FAILED (errors=1)
(venv) E:\GitHub\Python_Study\20200221>