Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: I can't mount the volume in dynamic gird for browser node #2143

Closed
barkep opened this issue Feb 22, 2024 · 8 comments · Fixed by SeleniumHQ/selenium#13804
Closed

Comments

@barkep
Copy link

barkep commented Feb 22, 2024

What happened?

I am setting up an environment for selenium grid. I want to use selenium dynamic grid.

My test case is loading an attachment on a web page.

I tried to attach the volume in docker compose, but the attachments are only visible in node docker. Not in dynamically created browser containers.

I also tried using the configuration in config.toml and it still doesn't work:

[node]
max-sessions = 2
[docker]
configs = [
"selenium/standalone-chrome:4.18.0", "{"browserName": "chrome"}"
]
url = "http://127.0.0.1:2375"
video-image = "selenium/video:ffmpeg-6.1-20231219"
volumes = ["path_on_disk:/opt/selenium/attachments"]

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

version: "3"
services:
  node-docker:
    image: selenium/node-docker:4.18.0
    volumes:
      - ./assets:/opt/selenium/assets
      - ./attachments:/opt/selenium/attachments
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_VNC_NO_PASSWORD=1

  selenium-hub:
    image: selenium/hub:4.18.0
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

Relevant log output

.

Operating System

Windows 11

Docker Selenium version (image tag)

4.18.0

Selenium Grid chart version (chart version)

No response

Copy link

@barkep, 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!

@barkep barkep changed the title [🐛 Bug]: [🐛 Bug]: I can't mount the volume in dynamic gird for browser node Feb 22, 2024
@VietND96
Copy link
Member

Looks like this is the same as feat request #1642
@diemol, can you confirm?

@diemol
Copy link
Member

diemol commented Feb 22, 2024

Yes. It is the same.

Why do you need this?

@barkep
Copy link
Author

barkep commented Feb 23, 2024

I've already tried setting "devices" and "volumes" in toml and it doesn't work. Maybe I'm configuring something wrong. Below is an example of the code from the test and the stacktrace I get.

SeleniumHQ/selenium@0e75c30

WebElement fileInput = WebElementHelper.findElementByXpath(getDriver(), path);
if (fileInput != null) {
    fileInput.sendKeys(filePath);
}
org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : /opt/selenium/attachments/test.png
  (Session info: chrome=121.0.6167.184)
Build info: version: '4.18.1', revision: 'b1d3319b48'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.10'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [564021b60ae07881c236ec89b085df58, sendKeysToElement {value=[Ljava.lang.CharSequence;@32638dad, id=E0A806A130C04072BAEE21DD53E25307_element_111}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 121.0.6167.184, chrome: {chromedriverVersion: 121.0.6167.184 (057a8ae7deb..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:42563}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.22.0.3:4444/sessio..., se:cdpVersion: 121.0.6167.184, se:forwardCdp: ws://172.22.0.4:4444/sessio..., se:name: AddPhotoFileTest_4.1.49.0__..., se:recordVideo: false, se:screenResolution: 1920x1080, se:vnc: ws://172.22.0.3:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.22.0.4:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: ignore, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Element: [[RemoteWebDriver: chrome on linux (564021b60ae07881c236ec89b085df58)] -> xpath: //*[@id='tempFileInput']]
Session ID: 564021b60ae07881c236ec89b085df58
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:167)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:138)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:190)
	at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:519)
	at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:223)
	at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:110)
	at pl.simplesoftware.xprimer.testengine.components.fields.FileField.setValueFromFile(FileField.java:130)

@diemol
Copy link
Member

diemol commented Feb 23, 2024

I don't know if you had a look at the linked issue, but it is not possible to mount volumes to the child containers.

I would like to better understand your use case. There is probably an alternative way of doing it.

@VietND96
Copy link
Member

VietND96 commented Apr 12, 2024

This change is part of the upstream repo: SeleniumHQ/selenium#13804, a trick can help in this case, based on a generic way to share the node-docker container HostConfig with the browser containers is dynamically provisioned, and the config key Binds is used to copy volume mappings of node-docker to browser containers inside.

The configuration looks like

config.toml

[node]
max-sessions = 2

[docker]
configs = [
"selenium/standalone-chrome:nightly", '{"browserName": "chrome"}'
]
url = "http://127.0.0.1:2375/"
video-image = "selenium/video:ffmpeg-7.0-nightly"

host-config-keys = ["Binds"]

docker-compose.yml

version: "3"
services:
  node-docker:
    image: selenium/node-docker:nightly
    volumes:
      - ./assets:/opt/selenium/assets
      - ./attachments:/opt/selenium/attachments
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_VNC_NO_PASSWORD=1

  selenium-hub:
    image: selenium/hub:nightly
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

With that config, host path ./attachments can retrieve files from path /opt/selenium/attachments in container standalone-chrome or any browser containers provisioned.

@Leon358522
Copy link

This change is part of the upstream repo: SeleniumHQ/selenium#13804, a trick can help in this case, based on a generic way to share the node-docker container HostConfig with the browser containers is dynamically provisioned, and the config key Binds is used to copy volume mappings of node-docker to browser containers inside.

The configuration looks like

config.toml

[node]
max-sessions = 2

[docker]
configs = [
"selenium/standalone-chrome:nightly", '{"browserName": "chrome"}'
]
url = "http://127.0.0.1:2375/"
video-image = "selenium/video:ffmpeg-7.0-nightly"

host-config-keys = ["Binds"]

docker-compose.yml

version: "3"
services:
  node-docker:
    image: selenium/node-docker:nightly
    volumes:
      - ./assets:/opt/selenium/assets
      - ./attachments:/opt/selenium/attachments
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_VNC_NO_PASSWORD=1

  selenium-hub:
    image: selenium/hub:nightly
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

With that config, host path ./attachments can retrieve files from path /opt/selenium/attachments in container standalone-chrome or any browser containers provisioned.

When i use this configuration i get a WebDriverCurlException

Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["--window-size=2560,1440"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","goog:chromeOptions":{"prefs":{"download.prompt_for_download":false,"download.default_directory":"C:\\tmp\\","profile.default_content_setting_values.automatic_downloads":1},"args":["--window-size=2560,1440"]}}}

Prior to that it usually failed after 47 secs., because it can't find the file it's looking for.
Desired path is => /home/seluser/ImportDateinenSeleniumGrid/
I tried it with external volume and with local link
Here is my docker compose file and the config.toml:

docker-compose.yml

version: "3.7"

services:
  chrome:
    image: selenium/node-docker:latest
    volumes:
      - "/root/docker/ImportDateinenSeleniumGrid:/home/seluser/ImportDateinenSeleniumGrid"
      - sel-imp-dat:/home/seluser/
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    shm_size: '2gb'
    depends_on:
      - selenium-hub
    environment:
      - SE_VNC_NO_PASSWORD=1
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_MAX_SESSIONS=4
      - SE_START_VNC=true
    ports:
      - "7900:7900"
  selenium-hub:
    image: selenium/hub:latest
    container_name: selenium-hub
    environment:
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"
volumes:
  sel-imp-dat:
    external: true

config.toml

[node]
max-sessions = 4

[docker]
configs = [
"selenium/standalone-chrome:nightly", '{"browserName": "chrome"}'
]
url = "http://127.0.0.1:2375/"
video-image = "selenium/video:ffmpeg-7.0-nightly"

host-config-keys = ["Binds"]

Also interesting is => I started only one Test and there are 2 nodes created
At first is was only one but after 3-4 mins there is another instance created

grafik

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants