SeleniumHQ / docker-selenium

Provides a simple way to run Selenium Grid with Chrome, Firefox, and Edge using Docker, making it easier to perform browser automation
http://www.selenium.dev/docker-selenium/
Other
7.74k stars 2.5k forks source link

[🐛 Bug]: selenium.common.exceptions.WebDriverException: Message: <empty> #2285

Open tamis-laan opened 2 weeks ago

tamis-laan commented 2 weeks ago

What happened?

I'm trying to run the selenium helm chart and connecting using python:

hub:
  image:
    repository: selenium/hub
    tag: 4.22.0
  service:
    type: LoadBalancer

videoRecorder:
  enabled: true

chromeNode:
  replicas: 2
  image:
    repository: selenium/node-chrome
    tag: 4.22.0

firefoxNode:
  enabled: false

edgeNode:
  enabled: false

ingress:
  enabled: false
# Configure Chrome options for headless mode
chrome_options = Options()
# chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--disable-features=Notification")

# Allow microphone and webcam
chrome_options.add_experimental_option("prefs", {
    "profile.default_content_setting_values.media_stream_mic": 2,
    "profile.default_content_setting_values.media_stream_camera": 2,
    "profile.default_content_setting_values.geolocation": 2,
    "profile.default_content_setting_values.notifications": 2,
    "profile.default_content_setting_values.popups": 2,
    "profile.default_content_setting_values.automatic_downloads": 2
})

# Create a new instance of the Chrome driver
# driver = webdriver.Chrome(options=chrome_options)
driver = webdriver.Remote(
    command_executor="http://selenium-grid-selenium-hub.default.svc.cluster.local:4444/wd/hub",
    options=chrome_options
)

But I get the following error:

      > [test-6f444dfcc7-85wrl test] Traceback (most recent call last):
      > [test-6f444dfcc7-85wrl test]   File "/app/main.py", line 33, in <module>
      > [test-6f444dfcc7-85wrl test]     driver = webdriver.Remote(
      > [test-6f444dfcc7-85wrl test]              ^^^^^^^^^^^^^^^^^
      > [test-6f444dfcc7-85wrl test]   File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in __init__
      > [test-6f444dfcc7-85wrl test]     self.start_session(capabilities)
      > [test-6f444dfcc7-85wrl test]   File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session
      > [test-6f444dfcc7-85wrl test]     response = self.execute(Command.NEW_SESSION, caps)["value"]
      > [test-6f444dfcc7-85wrl test]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      > [test-6f444dfcc7-85wrl test]   File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
      > [test-6f444dfcc7-85wrl test]     self.error_handler.check_response(response)
      > [test-6f444dfcc7-85wrl test]   File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
      > [test-6f444dfcc7-85wrl test]     raise exception_class(value)
      > [test-6f444dfcc7-85wrl test] selenium.common.exceptions.WebDriverException: Message:

The error message non descriptive as the it's empty.

Command used to start Selenium Grid with Docker (or Kubernetes)

#! /bin/bash

# Add docker-selenium helm repository
helm repo add docker-selenium https://www.selenium.dev/docker-selenium

# Make sure system is running properly
kubectl wait --for=condition=Ready pods --all --namespace=kube-system --timeout=300s

# Install basic grid latest version
helm upgrade --install selenium-grid docker-selenium/selenium-grid \
    -f values.yaml

Relevant log output

No logs are produced by selenium hub

Operating System

Minikube

Docker Selenium version (image tag)

4.22.0

Selenium Grid chart version (chart version)

No response

github-actions[bot] commented 2 weeks ago

@tamis-laan, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

VietND96 commented 2 weeks ago

When helm install (upgrade) successfully, a note displays with the Hub URL that can be accessed from outside. What is it? Also, may I know if these values worked with the previous chart version?

tamis-laan commented 2 weeks ago

@VietND96

"docker-selenium" already exists with the same configuration, skipping
pod/etcd-minikube condition met
pod/kube-apiserver-minikube condition met
pod/kube-controller-manager-minikube condition met
pod/kube-scheduler-minikube condition met
pod/storage-provisioner condition met
Release "selenium-grid" does not exist. Installing it now.
NAME: selenium-grid
LAST DEPLOYED: Sat Jun 22 20:17:29 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Selenium Grid Server deployed successfully.
    export POD_NAME=$(kubectl get pods -n default -l "app.kubernetes.io/name=selenium-grid-selenium-hub,app.kubernetes.io/instance=selenium-grid" -o jsonpath="{.items[0].metadata.name}")
    echo "Point your WebDriver tests to http://localhost:4444/wd/hub"
    kubectl -n default port-forward $POD_NAME 4444:4444

2. Within Kubernetes cluster, you can use following Service endpoint:
        http://selenium-grid-selenium-hub.default.svc:4444

I changed the url to:

driver = webdriver.Remote(
    # command_executor="http://selenium-grid-selenium-hub.default.svc.cluster.local:4444/wd/hub",
    command_executor="http://selenium-grid-selenium-hub.default.svc:4444",
    options=chrome_options
)

I also tried http://selenium-grid-selenium-hub.default.svc:4444/wd/hub but in both cases same error.

BTW nothing is logged by the hub deployment when trying to connect.

VietND96 commented 2 weeks ago

When you running the script on host, I don't think host could reach the DNS selenium-grid-selenium-hub.default.svc Try to following steps to expose Hub to host port 4444

export POD_NAME=$(kubectl get pods -n default -l "app.kubernetes.io/name=selenium-grid-selenium-hub,app.kubernetes.io/instance=selenium-grid" -o jsonpath="{.items[0].metadata.name}")
kubectl -n default port-forward $POD_NAME 4444:4444

Then point your WebDriver tests to http://localhost:4444/wd/hub

tamis-laan commented 2 weeks ago

@VietND96 I'm stupid but not that stupid ;-)

No I'm running the script as a kubernetes deployment in the same default namespace. I also tested it using a port forward as you described and I get the same error message.

VietND96 commented 2 weeks ago

I am not sure how the service type LoadBalancer works in Minikube. I would suggest another config that you can try

hub:
  serviceType: NodePort

And in script connect to http://localhost:31444/wd/hub