-
Notifications
You must be signed in to change notification settings - Fork 0
Pytest, selenium. Не правильно запускается тест (см. скриншот) #2
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
После закрытия браузера выдает, что ChromeDriver крашнулся.
Код из файла test_main.py:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
def setup_module():
global driver_path
driver_path = ChromeDriverManager().install()
def teardown_module():
pass
def setup_function():
global driver
driver = webdriver.Chrome(executable_path=driver_path)
def teardown_function():
driver.quit()
def test_ya_page_has_search_button():
driver.get('https://ya.ru')
wait = WebDriverWait(driver, 5)
element = wait.until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, '[type=submit]')))
text = element.text
assert text == 'Найти'
Код из терминала:
(venv) C:\Users\Enzo\PycharmProjects\selenium_test>pytest
============================= test session starts =============================
platform win32 -- Python 3.7.0, pytest-4.0.0, py-1.7.0, pluggy-0.8.0
rootdir: C:\Users\Enzo\PycharmProjects\selenium_test, inifile:
collected 1 item
test_main.py [8344:8864:1122/202653.950:ERROR:google_update_settings.cc(273)] Failed opening key Software\Google\Update\ClientStateMedium\{8A69D345-D564-463c-AFF1-A69D9E530F96} to set usagestats; result: 5
[8344:8572:1122/202653.953:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
DevTools listening on ws://127.0.0.1:53671/devtools/browser/d218908c-3f70-4dd9-aec6-bdd3bf69496d
[1122/202654.160:ERROR:gl_surface_egl.cc(777)] eglInitialize D3D11 failed with error EGL_NOT_INITIALIZED, trying next display type
[8344:3460:1122/202654.342:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:3460:1122/202654.361:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:3460:1122/202654.364:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:3460:1122/202654.371:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:3460:1122/202654.377:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.379:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.381:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.390:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.393:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.394:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.397:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.408:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.413:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.418:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.420:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.427:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.439:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.444:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.447:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.450:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
[8344:8268:1122/202654.453:ERROR:persistent_memory_allocator.cc(815)] Corruption detected in shared-memory segment.
E [100%]
=================================== ERRORS ====================================
______________ ERROR at setup of test_ya_page_has_search_button _______________
def setup_function():
global driver
> driver = webdriver.Chrome(executable_path=driver_path)
test_main.py:19:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py:81: in __init__
desired_capabilities=desired_capabilities)
venv\lib\site-packages\selenium\webdriver\remote\webdriver.py:157: in __init__
self.start_session(capabilities, browser_profile)
venv\lib\site-packages\selenium\webdriver\remote\webdriver.py:252: in start_session
response = self.execute(Command.NEW_SESSION, parameters)
venv\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x000000000381EB70>
response = {'sessionId': '3a879ee38da339498ccbf92809a62d6c', 'status': 13, 'value': {'message': 'unknown error: Chrome failed to ...r info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 6.1.7601 SP1 x86_64)'}}
def check_response(self, response):
"""
Checks that a JSON response from the WebDriver does not have an error.
:Args:
- response - The JSON response from the WebDriver server as a dictionary
object.
:Raises: If the response contains an error message.
"""
status = response.get('status', None)
if status is None or status == ErrorCode.SUCCESS:
return
value = None
message = response.get("message", "")
screen = response.get("screen", "")
stacktrace = None
if isinstance(status, int):
value_json = response.get('value', None)
if value_json and isinstance(value_json, basestring):
import json
try:
value = json.loads(value_json)
if len(value.keys()) == 1:
value = value['value']
status = value.get('error', None)
if status is None:
status = value["status"]
message = value["value"]
if not isinstance(message, basestring):
value = message
message = message.get('message')
else:
message = value.get('message', None)
except ValueError:
pass
exception_class = ErrorInResponseException
if status in ErrorCode.NO_SUCH_ELEMENT:
exception_class = NoSuchElementException
elif status in ErrorCode.NO_SUCH_FRAME:
exception_class = NoSuchFrameException
elif status in ErrorCode.NO_SUCH_WINDOW:
exception_class = NoSuchWindowException
elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
exception_class = StaleElementReferenceException
elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
exception_class = ElementNotVisibleException
elif status in ErrorCode.INVALID_ELEMENT_STATE:
exception_class = InvalidElementStateException
elif status in ErrorCode.INVALID_SELECTOR \
or status in ErrorCode.INVALID_XPATH_SELECTOR \
or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
exception_class = InvalidSelectorException
elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
exception_class = ElementNotSelectableException
elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
exception_class = ElementNotInteractableException
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
exception_class = InvalidCookieDomainException
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
exception_class = UnableToSetCookieException
elif status in ErrorCode.TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.SCRIPT_TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.UNKNOWN_ERROR:
exception_class = WebDriverException
elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
exception_class = UnexpectedAlertPresentException
elif status in ErrorCode.NO_ALERT_OPEN:
exception_class = NoAlertPresentException
elif status in ErrorCode.IME_NOT_AVAILABLE:
exception_class = ImeNotAvailableException
elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
exception_class = ImeActivationFailedException
elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
exception_class = MoveTargetOutOfBoundsException
elif status in ErrorCode.JAVASCRIPT_ERROR:
exception_class = JavascriptException
elif status in ErrorCode.SESSION_NOT_CREATED:
exception_class = SessionNotCreatedException
elif status in ErrorCode.INVALID_ARGUMENT:
exception_class = InvalidArgumentException
elif status in ErrorCode.NO_SUCH_COOKIE:
exception_class = NoSuchCookieException
elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
exception_class = ScreenshotException
elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
exception_class = ElementClickInterceptedException
elif status in ErrorCode.INSECURE_CERTIFICATE:
exception_class = InsecureCertificateException
elif status in ErrorCode.INVALID_COORDINATES:
exception_class = InvalidCoordinatesException
elif status in ErrorCode.INVALID_SESSION_ID:
exception_class = InvalidSessionIdException
elif status in ErrorCode.UNKNOWN_METHOD:
exception_class = UnknownMethodException
else:
exception_class = WebDriverException
if value == '' or value is None:
value = response['value']
if isinstance(value, basestring):
if exception_class == ErrorInResponseException:
raise exception_class(response, value)
raise exception_class(value)
if message == "" and 'message' in value:
message = value['message']
screen = None
if 'screen' in value:
screen = value['screen']
stacktrace = None
if 'stackTrace' in value and value['stackTrace']:
stacktrace = []
try:
for frame in value['stackTrace']:
line = self._value_or_default(frame, 'lineNumber', '')
file = self._value_or_default(frame, 'fileName', '<anonymous>')
if line:
file = "%s:%s" % (file, line)
meth = self._value_or_default(frame, 'methodName', '<anonymous>')
if 'className' in frame:
meth = "%s.%s" % (frame['className'], meth)
msg = " at %s (%s)"
msg = msg % (meth, file)
stacktrace.append(msg)
except TypeError:
pass
if exception_class == ErrorInResponseException:
raise exception_class(response, message)
elif exception_class == UnexpectedAlertPresentException:
alert_text = None
if 'data' in value:
alert_text = value['data'].get('text')
elif 'alert' in value:
alert_text = value['alert'].get('text')
raise exception_class(message, screen, stacktrace, alert_text)
> raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
E (chrome not reachable)
E (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
E (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 6.1.7601 SP1 x86_64)
venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: WebDriverException
---------------------------- Captured stdout setup ----------------------------
Checking for win32 chromedriver:2.44 in cache
Driver found in C:\Users\Enzo\.wdm\chromedriver\2.44\win32/chromedriver.exe
========================== 1 error in 14.57 seconds ===========================
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
