1
resposta

[Bug] Selenium não encontra o webdriver no Jenkins

Olá, estou com um problema no curso "Scripting: automação de tarefas com Python e criação de Pipelines no Jenkins", onde ao rodar o Selenium localmente, tudo funciona, mas ao rodar via Jenkins, mesmo com a aplicação rodando, fico recebendo erro de que não foi encontrado o webdriver, poderiam me auxiliar?

** Já pesquisei em inúmeros fóruns na internet, e não obtive êxito
** Ao rodar fora do python3 -m, ele nem sequer consegue encontrar o selenium, mesmo tendo instalado via apt install -y python3-pytest python3-selenium

1 resposta

Erro:

python3 -m pytest
============================= test session starts ==============================
[...]

==================================== ERRORS ====================================
_________________________ ERROR at setup of test_home __________________________

service = <selenium.webdriver.chrome.service.Service object at 0x7f277bad65a0>
options = <selenium.webdriver.chrome.options.Options object at 0x7f277bd45af0>

    @staticmethod
    def get_path(service: Service, options: BaseOptions) -> str:
        path = service.path
        try:
>           path = SeleniumManager().driver_location(options) if path is None else path

/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py:89: in driver_location
    args = [str(self.get_binary()), "--browser", browser]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    [...]

/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py:73: WebDriverException

The above exception was the direct cause of the following exception:

    @pytest.fixture(scope="module")
    
    def browser():
        # Configuração do webdriver
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--headless")
        chrome_options.add_argument("--disable-gpu")
>       driver = webdriver.Chrome(options=chrome_options)

conftest.py:12: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3/dist-packages/selenium/webdriver/chrome/webdriver.py:45: in __init__
    super().__init__(
/usr/lib/python3/dist-packages/selenium/webdriver/chromium/webdriver.py:49: in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

service = <selenium.webdriver.chrome.service.Service object at 0x7f277bad65a0>
options = <selenium.webdriver.chrome.options.Options object at 0x7f277bd45af0>

    @staticmethod
    def get_path(service: Service, options: BaseOptions) -> str:
        path = service.path
        try:
            path = SeleniumManager().driver_location(options) if path is None else path
        except Exception as err:
            msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
>           raise NoSuchDriverException(msg) from err
E           selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py:41: NoSuchDriverException
=========================== short test summary info ============================
ERROR tests/test_home.py::test_home - selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
=============================== 1 error in 0.04s ===============================
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

** Tive de remover parte do erro por conta do limite de caracteres aqui no post.