Добрый день! Очень нужна помощь начинающему автоматизатору
Достался в наследство репозиторий с автотестами для веб UI на python + selenium. Для анализа HTTP траффика используется Browsermob-Proxy.
Проблема в том, что автотесты падают на строке server.start()
======================================================== ERRORS ========================================================
________________________________ ERROR at setup of TestSearch.test_t50604_show_articles ________________________________
request = <SubRequest 'generate_test_report' for <Function test_t50604_show_articles>>
@pytest.fixture(autouse=True)
def generate_test_report(request):
> driver = driver_getter(request)
conftest.py:166:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
conftest.py:161: in driver_getter
return req.getfixturevalue('browser_with_har')
conftest.py:78: in get_har
server.start()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <browsermobproxy.server.Server object at 0x111546aa0>, options = {}
def start(self, options=None):
"""
This will start the browsermob proxy and then wait until it can
interact with it
:param dict options: Dictionary that can hold the path and filename
of the log file with resp. keys of `log_path` and `log_file`
"""
if options is None:
options = {}
log_path = options.get('log_path', os.getcwd())
log_file = options.get('log_file', 'server.log')
retry_sleep = options.get('retry_sleep', 0.5)
retry_count = options.get('retry_count', 60)
log_path_name = os.path.join(log_path, log_file)
self.log_file = open(log_path_name, 'w')
self.process = subprocess.Popen(self.command,
stdout=self.log_file,
stderr=subprocess.STDOUT)
count = 0
while not self._is_listening():
if self.process.poll():
message = (
"The Browsermob-Proxy server process failed to start. "
"Check {0}"
"for a helpful error message.".format(self.log_file))
raise ProxyServerError(message)
time.sleep(retry_sleep)
count += 1
if count == retry_count:
self.stop()
> raise ProxyServerError("Can't connect to Browsermob-Proxy")
E browsermobproxy.exceptions.ProxyServerError: Can't connect to Browsermob-Proxy
../venv/lib/python3.10/site-packages/browsermobproxy/server.py:127: ProxyServerError
=============================================== short test summary info ================================================
ERROR tests/search/test_search.py::TestSearch::test_t50604_show_articles - browsermobproxy.exceptions.ProxyServerError: Can't connect to Browsermob-Proxy
Вот часть кода, которая отвечает за запуск сервера:
@pytest.fixture(scope='function')
def browser_with_har(get_har):
browser_with_har = webdriver.Chrome(options=options_chrome)
browser_with_har.implicitly_wait(7)
browser_with_har.set_page_load_timeout(60)
yield browser_with_har
browser_with_har.quit()
@pytest.fixture
def get_har():
server = Server(os.getcwd() + '/proxy/bin/browsermob-proxy')
server.start()
proxyserver = server.create_proxy({'trustAllServers': 'true',
'port': 8085
})
options_chrome.add_argument(f'--proxy-server={proxyserver.selenium_proxy().httpProxy}')
proxyserver.new_har('page', options={'captureContent': True,
'captureHeaders': True,
'captureCookies': True})
yield proxyserver
proxyserver.close()
server.stop()
options_chrome.arguments.remove(f'--proxy-server={proxyserver.selenium_proxy().httpProxy}')
for p in psutil.process_iter():
if p.name().__contains__('java'):
p.terminate()
p.wait(10)