run_all.py文件
总是报错:
Traceback (most recent call last):
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connection.py”, line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\connection.py”, line 80, in create_connection
raise err
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\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 “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1026, in _send_output
self.send(msg)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 964, in send
self.connect()
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connection.py”, line 181, in connect
conn = self._new_conn()
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connection.py”, line 168, in _new_conn
self, “Failed to establish a new connection: %s” % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000000032FFBA8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “E:\appium_python\case\my_page\test_notice.py”, line 17, in setUpClass
cls.driver = base_driver.android_driver()
File “E:\appium_python\base\base_driver.py”, line 24, in android_driver
driver = webdriver.Remote(‘http://127.0.0.1:4790/wd/hub’, capabilities)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\appium\webdriver\webdriver.py”, line 140, in init
proxy
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 157, in init
self.start_session(capabilities, browser_profile)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\appium\webdriver\webdriver.py”, line 215, in start_session
response = self.execute(RemoteCommand.NEW_SESSION, parameters)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 319, in execute
response = self.command_executor.execute(driver_command, params)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 374, in execute
return self._request(command_info[0], url, body=data)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\request.py”, line 72, in request
**urlopen_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\request.py”, line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\poolmanager.py”, line 323, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 667, in urlopen
**response_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 667, in urlopen
**response_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 667, in urlopen
**response_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py”, line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=4790): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x00000000032FFBA8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。’,))
Traceback (most recent call last):
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connection.py”, line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\connection.py”, line 80, in create_connection
raise err
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\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 “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 1026, in _send_output
self.send(msg)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\http\client.py”, line 964, in send
self.connect()
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connection.py”, line 181, in connect
conn = self._new_conn()
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connection.py”, line 168, in _new_conn
self, “Failed to establish a new connection: %s” % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000000035A00B8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “E:\appium_python\case\my_page\test_user_info.py”, line 16, in setUpClass
cls.driver = base_driver.android_driver()
File “E:\appium_python\base\base_driver.py”, line 24, in android_driver
driver = webdriver.Remote(‘http://127.0.0.1:4790/wd/hub’, capabilities)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\appium\webdriver\webdriver.py”, line 140, in init
proxy
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 157, in init
self.start_session(capabilities, browser_profile)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\appium\webdriver\webdriver.py”, line 215, in start_session
response = self.execute(RemoteCommand.NEW_SESSION, parameters)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 319, in execute
response = self.command_executor.execute(driver_command, params)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 374, in execute
return self._request(command_info[0], url, body=data)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\request.py”, line 72, in request
**urlopen_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\request.py”, line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\poolmanager.py”, line 323, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 667, in urlopen
**response_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 667, in urlopen
**response_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 667, in urlopen
**response_kw)
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py”, line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File “C:\Users\Mtime\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py”, line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=4790): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x00000000035A00B8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。’,))
Ran 0 tests in 14.081s
FAILED (errors=2)
Process finished with exit code 0
case如下:test_notice.py
import unittest
import sys
sys.path.append(‘E:\appium_python’)
import time
from base.base_driver import BaseDriver
from util.server import Server
from handle.notice_handle import NoticeHandle
from handle.user_info import UserInfo
import HTMLTestRunner
class CaseTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
base_driver = BaseDriver()
cls.driver = base_driver.android_driver()
cls.notice_handle = NoticeHandle(cls.driver)
cls.user_info = UserInfo(cls.driver)
def setUp(self):
print('this is setup\n')
def test_notice_verify(self):
self.notice_handle.notice_list()
self.driver.quit()
def tearDown(self):
print('this is teardown')
# self.driver.quit()
@classmethod
def tearDownClass(cls):
print('this is teardownclass')
def appium_init():
server = Server()
server.main()
if name == ‘main’:
appium_init()
time.sleep(10)
suite = unittest.TestSuite()
test_cases = [CaseTest(“test_notice_verify”)]
suite.addTests(test_cases)
# html_file = ‘E:/appium_python/report/report.html’
# fp = open(html_file, ‘wb’)
# HTMLTestRunner.HTMLTestRunner(fp).run(suite)
unittest.TextTestRunner().run(suite)
test_user_info.py
import unittest
import sys
sys.path.append(‘E:\appium_python’)
import time
from base.base_driver import BaseDriver
from util.server import Server
from handle.user_info import UserInfo
import HTMLTestRunner
class CaseTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
base_driver = BaseDriver()
cls.driver = base_driver.android_driver()
cls.user_info = UserInfo(cls.driver)
def setUp(self):
print('this is setup\n')
def test_user_info_verify(self):
self.user_info.user_info_hanle()
self.driver.quit()
def tearDown(self):
print('this is teardown')
@classmethod
def tearDownClass(cls):
print('this is teardownclass')
def appium_init():
server = Server()
server.main()
if name == ‘main’:
appium_init()
time.sleep(10)
suite = unittest.TestSuite()
test_cases = [CaseTest("test_user_info_verify")]
suite.addTests(test_cases)
# html_file = 'E:/appium_python/report/report.html'
# fp = open(html_file, 'wb')
# HTMLTestRunner.HTMLTestRunner(fp).run(suite)
unittest.TextTestRunner().run(suite)
在网上搜索了各种方法都不行,换了多个端口号,依旧不行(应该不是端口号被占用的问题)
1、结束adb.exe进程
2、重启手机,重启pycharm、重启电脑,插拔数据线,卸载apk
3、添加 self.driver.quit()
以上方法都无法解决
请老师帮忙看下