3

I had a problem running an integration test for a plotly-dash app I created. I am trying to run an integration test with selenium remote using pytest and Dash Testing (https://dash.plotly.com/testing)

I was able to run an implementation test locally using the selenium chrome webdriver.

However, it does not work remotely. I created a selenium grid on Google Cloud Platform and can run a simple integration test to see if Google.com loads. This works fine and the following test passes.

test_google.py

def test_query_window_is_visible(browser):
    browser.get('https://google.com')
    query_window = browser.find_element_by_name('q')
    assert query_window.is_displayed()

I can also run the simple integration test using the selenium standalone service in Gitlab with the template produced by Aleksandr Kotlyar (https://gitlab.com/aleksandr-kotlyar/python-gitlabci-selenium/-/tree/1.0.0).

However, when I switch to test the dash app, my integration test to see if the h1 tag loads passes when run locally passes, but when run on Gitlab or by connecting to a remote selenium grid with --remote-url, I get the following errors:

FAILED test_functional.py::test_one - selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_CONNECTION_REFUSED
E       selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_CONNECTION_REFUSED
E         (Session info: chrome=x0.0.xxxx.xx)

Any advice to solve this error and run the test remotely would be helpful.

The code was run as follows:

pytest test_functional.py --log-cli-level DEBUG --webdriver Chrome --remote-url http://*selenium grid endpoint ip address hidden*/wd/hub 

test_functional.py:

import pytest
from selenium import webdriver
from selenium.webdriver import Remote

from selenium.webdriver.chrome.options import Options

from dash.testing.application_runners import import_app


def test_one(dash_duo):
    app = import_app("app")

    dash_duo.start_server(app)

    dash_duo.wait_for_text_to_equal(
        "h1", "Competitor Analysis", timeout=4)

    assert dash_duo.find_element(
        "h1").text == "Competitor Analysis"

conftest.py

import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.remote.webdriver import WebDriver


@pytest.fixture(scope='function')
def browser() -> WebDriver:
    driver = webdriver.Remote(
        command_executor='http://*selenium grid endpoint ip address hidden*/wd/hub',
        options=Options())
    return driver
filmroll22
  • 31
  • 2

1 Answers1

0

make sure you are using gitlab in headless mode so you don't get an error. Gitlab does not in fact contain any graphic display.

the following options are recommended for using selenium with gitlab.

['--no-sandbox', '--headless', '--disable-dev-shm-usage', '--disable-gpu', '--disable-extensions']

If you haven't this options, gitlab can find error. May be this can solve your error !

Sacha Durand
  • 473
  • 1
  • 5
  • 11