简体   繁体   English

如何使用 Plotly-Dash 测试解决连接被拒绝错误 - Selenium Grid/Selenium Standalone - Remote/Gitlab

[英]How to solve Connection refused error with Plotly- Dash Testing - Selenium Grid/Selenium Standalone - Remote/Gitlab

I had a problem running an integration test for a plotly-dash app I created.我在为我创建的 plotly-dash 应用程序运行集成测试时遇到问题。 I am trying to run an integration test with selenium remote using pytest and Dash Testing ( https://dash.plotly.com/testing ) 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.我能够使用 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.我在 Google Cloud Platform 上创建了一个 selenium 网格,可以运行一个简单的集成测试来查看是否加载了 Google.com。 This works fine and the following test passes.这工作正常,以下测试通过。

test_google.py 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 ). 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:但是,当我切换到测试仪表板应用程序时,我的集成测试以查看在本地运行时 h1 标签加载是否通过,但是当在 Gitlab 上运行或通过使用 --remote-url 连接到远程 selenium 网格时,我得到了以下错误:

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: 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 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

make sure you are using gitlab in headless mode so you don't get an error.确保您在无头模式下使用 gitlab,以免出现错误。 Gitlab does not in fact contain any graphic display. Gitlab 实际上不包含任何图形显示。

the following options are recommended for using selenium with gitlab.建议使用以下选项将 selenium 与 gitlab 一起使用。

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

If you haven't this options, gitlab can find error.如果你没有这个选项,gitlab 可以找到错误。 May be this can solve your error !也许这可以解决你的错误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM