After following a couple of tutorials I can't figure out how to configure Selenium with:
- a rails app on debian wsl2
- the gem "Webdrivers"
- docker With my local application, Selenium worked properly with
require "webdrivers"
Since I have dockerized the app, everything works properly except Selenium.
When I run a js test I get
Webdrivers::NetworkError:
Net::HTTPServerException: 404 "Not Found" with https://github.com/mozilla/geckodriver/releases/download/v0/geckodriver-v0-linux64.tar.gz
It seems that the request url is not build correctly "v0"
When I hard code a version number in my config file like so
Webdrivers::Geckodriver.required_version = "0.32.0"
geckodriver is downloaded properly.
1- How can I configure webdriver to handle verssion automatically ?
Then I get this error message
Selenium::WebDriver::Error::SessionNotCreatedError:
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
What I understand is that it tries to reach for the firefox application. I have firefox installed on windows side and firefox-esr on wsl2/debian side.
2- How can I configure webdrivers and/or docker to run my tests with selenium ?
I have tried to hard code the firefox path.
Here is my webdrivers config, with many settings attempts.
Capybara.register_driver :remote_firefox do |app|
firefox_capabilities = ::Selenium::WebDriver::Remote::Capabilities.firefox
# (
# "moz:firefoxOptions": {
# "args": %w[headless window-size=1400,1400]
# },
# "binary": "/mnt/c/Users/Fz/AppData/Local/Microsoft/WindowsApps/firefox.exe"
# )
firefox_options = Selenium::WebDriver::Firefox::Options.new
firefox_options.binary = "/mnt/c/Users/Fz/AppData/Local/Microsoft/WindowsApps/firefox.exe"
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: "http://172.28.0.7:5555",
# desired_capabilities: firefox_capabilities,
options: firefox_options
)
end
RSpec.configure do |config|
config.before(:each) do
Capybara.current_driver = :remote_firefox
Capybara.javascript_driver = :remote_firefox
Capybara.app_host = "http://#{IPSocket.getaddress(Socket.gethostname)}:3000"
Capybara.server_host = IPSocket.getaddress(Socket.gethostname)
Capybara.server_port = 5555
end
end
###############################################
# Selenium::WebDriver::Firefox.path = "/mnt/c/Users/Fz/AppData/Local/Microsoft/WindowsApps/firefox.exe"
# Selenium::WebDriver::Firefox.path = "/usr/bin/firefox"
# Selenium::WebDriver::Firefox.path = "//wsl.localhost/Debian/usr/bin/firefox"
# options = Selenium::WebDriver::Firefox::Options.new
# options.binary = "/usr/bin/firefox"
#
# driver = Selenium::WebDriver.for :remote,
# url: "http://localhost:4444",
# desired_capabilities: :firefox,
# options: ""
#########################################
with 'desired_capabilities' I get
ArgumentError:
unknown keyword: :desired_capabilities
without I get
Selenium::WebDriver::Error::WebDriverError
unexpected response, code=404, content-type=""
{
"value": {
"error": "unknown command",
"message": "Unable to find handler for (POST) \u002fsession",
"stacktrace": ""
}
}
here is my docker-compose file
version: '3'
networks:
development:
test:
volumes:
db_data:
es_data:
gem_cache:
shared_data:
selenium_data:
services:
(...)
capoeiragem_dev:
build:
context: .
dockerfile: ./config/containers/Dockerfile.dev
container_name: capoeiragem_dev
volumes:
- .:/var/app
- shared_data:/usr/share
- gem_cache:/usr/local/bundle/gems
networks:
- development
ports:
- 3000:3000
stdin_open: true
tty: true
env_file: .env.development
entrypoint: entrypoint-dev.sh
command: [ 'bundle', 'exec', 'rails', 'server', '-p', '3000', '-b', '0.0.0.0' ]
environment:
RAILS_ENV: development
depends_on:
- capoeiragem_db
- capoeiragem_es
(...)
guard:
tty: true
stdin_open: true
build:
context: .
dockerfile: ./config/containers/Dockerfile.dev
volumes:
- .:/var/app
- gem_cache:/usr/local/bundle/gems
networks:
- development
environment:
RAILS_ENV: development
command: [ 'bundle', 'exec', 'guard', '--no-bundler-warning' ]
ports:
- 35729:35729
depends_on:
- capoeiragem_dev
- capoeiragem_selenium
(...)
capoeiragem_firefox:
image: selenium/node-firefox:dev
networks:
- development
shm_size: 2gb
depends_on:
- capoeiragem_selenium
environment:
- SE_EVENT_BUS_HOST=capoeiragem_selenium
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
capoeiragem_chrome:
image: selenium/node-chrome:dev
networks:
- development
shm_size: 2gb
depends_on:
- capoeiragem_selenium
environment:
- SE_EVENT_BUS_HOST=capoeiragem_selenium
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
capoeiragem_selenium:
image: selenium/hub:latest
volumes:
- selenium_data:/usr/share/selenium/data
networks:
- development
container_name: capoeiragem_selenium
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
I can see the firefox node at http://localhost:4444/ui