Python, не отрабатывает скрипт автотеста

Рейтинг: 1Ответов: 0Опубликовано: 06.04.2023

Итак, имеется скрипт на заполнение данных в поле ввода:

from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By


class TestInput:
    def test_send_keys(self, set_up_browser):
        driver = set_up_browser
        driver.get('https://l6nm9r.csb.app/demo/InputTextDemo.html')
        driver.find_element(By.ID, 'username').send_keys('basic text')
        pass

browser.py

import pytest
from selenium.webdriver import Remote


@pytest.fixture()
def set_up_browser():
    driver = Remote(desired_capabilities={
        "browserName": "chrome",
        "browserVersion": "latest"
    }, command_executor="http://127.0.0.1:4444/wd/hub")
    yield driver
    driver.quit()

и conftest.py

pytest_plugins = [
    "src.browser"
]

Обновил pycharm, почистил конфиги, теперь ругается вот так

Launching pytest with arguments C:\Users\aleks\Practice44\test_input.py --no-header --no-summary -q in C:\Users\aleks\Practice44

============================= test session starts =============================
collecting ... collected 1 item
run-last-failure: rerun previous 1 failure first

test_input.py::TestInput::test_send_keys 

========================= 1 warning, 1 error in 1.15s =========================
ERROR                           [100%]
test setup failed
@pytest.fixture()
    def set_up_browser():
>       driver = Remote(desired_capabilities={
            "browserName": "chrome",
            "browserVersion": "latest"
        }, command_executor="http://127.0.0.1:4444/wd/hub")

src\browser.py:7:

Селеноид запущен в minoconda, но никак не реагирует Полный вывод:

C:\Users\aleks\miniconda3\python.exe "C:/Program Files/JetBrains/PyCharm Community Edition 2022.3.2/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" --path C:\Users\aleks\Practice44\test_input.py 
Testing started at 11:14 ...
Launching pytest with arguments C:\Users\aleks\Practice44\test_input.py --no-header --no-summary -q in C:\Users\aleks\Practice44

============================= test session starts =============================
collecting ... collected 1 item
run-last-failure: rerun previous 1 failure first

test_input.py::TestInput::test_send_keys 

========================= 1 warning, 1 error in 1.13s =========================
ERROR                           [100%]
test setup failed
@pytest.fixture()
    def set_up_browser():
>       driver = Remote(desired_capabilities={
            "browserName": "chrome",
            "browserVersion": "latest"
        }, command_executor="http://127.0.0.1:4444/wd/hub")

src\browser.py:7: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\miniconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py:286: in __init__
    self.start_session(capabilities, browser_profile)
..\miniconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py:378: in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
..\miniconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py:440: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x0000020DF7CB84C0>
response = {'status': 500, 'value': '{"value":{"error":"session not created","message":"session not created: This version of Chro...unk [0x74CE6BD9+25]\\n\\tRtlGetFullPathName_UEx [0x76FB8FD2+1218]\\n\\tRtlGetFullPathName_UEx [0x76FB8F9D+1165]\\n"}}'}

    def check_response(self, response: Dict[str, Any]) -> None:
        """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 not status or status == ErrorCode.SUCCESS:
            return
        value = None
        message = response.get("message", "")
        screen: str = response.get("screen", "")
        stacktrace = None
        if isinstance(status, int):
            value_json = response.get("value", None)
            if value_json and isinstance(value_json, str):
                import json
    
                try:
                    value = json.loads(value_json)
                    if len(value.keys()) == 1:
                        value = value["value"]
                    status = value.get("error", None)
                    if not status:
                        status = value.get("status", ErrorCode.UNKNOWN_ERROR)
                        message = value.get("value") or value.get("message")
                        if not isinstance(message, str):
                            value = message
                            message = message.get("message")
                    else:
                        message = value.get("message", None)
                except ValueError:
                    pass
    
        exception_class: Type[WebDriverException]
        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_SHADOW_ROOT:
            exception_class = NoSuchShadowRootException
        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 not value:
            value = response["value"]
        if isinstance(value, str):
            raise exception_class(value)
        if message == "" and "message" in value:
            message = value["message"]
    
        screen = None  # type: ignore[assignment]
        if "screen" in value:
            screen = value["screen"]
    
        stacktrace = None
        st_value = value.get("stackTrace") or value.get("stacktrace")
        if st_value:
            if isinstance(st_value, str):
                stacktrace = st_value.split("\n")
            else:
                stacktrace = []
                try:
                    for frame in st_value:
                        line = frame.get("lineNumber", "")
                        file = frame.get("fileName", "<anonymous>")
                        if line:
                            file = f"{file}:{line}"
                        meth = frame.get("methodName", "<anonymous>")
                        if "className" in frame:
                            meth = f"{frame['className']}.{meth}"
                        msg = "    at %s (%s)"
                        msg = msg % (meth, file)
                        stacktrace.append(msg)
                except TypeError:
                    pass
        if 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)  # type: ignore[call-arg]  # mypy is not smart enough here
>       raise exception_class(message, screen, stacktrace)
E       selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 110
E       Current browser version is 112.0.5615.50 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
E       Stacktrace:
E       Backtrace:
E           (No symbol) [0x010C37D3]
E           (No symbol) [0x01058B81]
E           (No symbol) [0x00F5B36D]
E           (No symbol) [0x00F7ED6D]
E           (No symbol) [0x00F79B90]
E           (No symbol) [0x00F76FC9]
E           (No symbol) [0x00FB1ED5]
E           (No symbol) [0x00FB1B2C]
E           (No symbol) [0x00FAB216]
E           (No symbol) [0x00F80D97]
E           (No symbol) [0x00F8253D]
E           GetHandleVerifier [0x0133ABF2+2510930]
E           GetHandleVerifier [0x01368EC1+2700065]
E           GetHandleVerifier [0x0136C86C+2714828]
E           GetHandleVerifier [0x01173480+645344]
E           (No symbol) [0x01060FD2]
E           (No symbol) [0x01066C68]
E           (No symbol) [0x01066D4B]
E           (No symbol) [0x01070D6B]
E           BaseThreadInitThunk [0x74CE6BD9+25]
E           RtlGetFullPathName_UEx [0x76FB8FD2+1218]
E           RtlGetFullPathName_UEx [0x76FB8F9D+1165]

..\miniconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py:245: SessionNotCreatedException

Process finished with exit code 1

и отработка селеноида при запуске скрипта

2023/04/07 12:54:45 [-] [NEW_REQUEST] [unknown] [127.0.0.1]
2023/04/07 12:54:45 [-] [NEW_REQUEST_ACCEPTED] [unknown] [127.0.0.1]
2023/04/07 12:54:45 [4] [LOCATING_SERVICE] [chrome] [latest]
2023/04/07 12:54:45 [4] [USING_DRIVER] [chrome] [latest]
2023/04/07 12:54:45 [4] [ALLOCATING_PORT]
2023/04/07 12:54:45 [4] [ALLOCATED_PORT] [57050]
2023/04/07 12:54:45 [4] [STARTING_PROCESS] [[/Users/aleks/Practice4/chromedriver.exe --port=57050]]
2023/04/07 12:54:46 [4] [PROCESS_STARTED] [1780] [0.58s]
2023/04/07 12:54:46 [4] [PROXY_TO] [http://127.0.0.1:57050]
2023/04/07 12:54:46 [4] [SESSION_ATTEMPTED] [http://127.0.0.1:57050] [1]

DevTools listening on ws://127.0.0.1:57053/devtools/browser/0fac4af6-9534-4fd7-b988-8da4b81c2a5c
2023/04/07 12:54:46 [4] [SESSION_FAILED] [http://127.0.0.1:57050] [500 Internal Server Error]
2023/04/07 12:54:46 [4] [TERMINATING_PROCESS] [1780]
2023/04/07 12:54:46 [4] [TERMINATED_PROCESS] [1780] [0.01s]

Ответы

Ответов пока нет.