aidalgol

aidalgol

I am trying to add end-to-end testing with Hound and Selenium to my Phoenix application that is run under docker-compose, and I keep getting could not create a new session: timeout, check webdriver is running from Hound, even though I am invoking mix through a wrapper script that first waits until Selenium is ready. I cannot figure out why the Selenium status check passes and then Hound fails to connect, because they are both set to point to the same hostname and port.

docker-compose.yml

version: "3.3"
services:
  phoenix:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - 4000:4000
      - 4001:4001
      - 4002:4002
    depends_on:
      - db
      - selenium
    environment:
      - POSTGRES_HOST=db
    volumes:
      - .:/paddy

  db:
    image: postgres:11
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - "${DB_PORT}:5432"
    volumes:
      - "${HOME}/srv/paddy-db:/var/lib/postgresql/data"

  selenium:
    image: selenium/standalone-firefox:4
    ports:
      - 4444:4444
      - 7900:7900
    volumes:
      - /dev/shm:/dev/shm

Entrypoint script for the phoenix service:

#!/bin/bash

echo 'Waiting for database to be ready...'
while ! pg_isready -q -h "$POSTGRES_HOST" -p 5432 -U postgres; do
  sleep 2
done

echo 'Waiting for Selenium to be ready...'
while ! [ "$(curl -sSL http://selenium:4444/status | jq -r '.value.ready')" == "true" ]; do
  sleep 2
done

exec mix "$@"

Relevant parts of config/test.exs

config :paddy, PaddyWeb.Endpoint,
  http: [port: 4002],
  server: true

config :hound,
  driver: "selenium",
  host: "http://selenium",
  port: 4444,
  browser: "firefox",
  app_host: "http://phoenix",
  app_port: 4002

Hound error:

21:43:29.785 [error] GenServer Hound.SessionServer terminating
** (RuntimeError) could not create a new session: timeout, check webdriver is running
    (hound 1.1.1) lib/hound/session_server.ex:101: Hound.SessionServer.create_session/2
    (hound 1.1.1) lib/hound/session_server.ex:78: Hound.SessionServer.handle_call/3
    (stdlib 3.12.1) gen_server.erl:661: :gen_server.try_handle_call/4
    (stdlib 3.12.1) gen_server.erl:690: :gen_server.handle_msg/6
    (stdlib 3.12.1) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.853.0>): {:change_session, #PID<0.853.0>, :default, []}

Update:
This error seems to happen when I rerun docker-compose too soon after the previous run. If I wait a little bit longer, it gives me this instead:

     ** (RuntimeError) Reached error page: about:neterror?e=dnsNotFound&u=http%3A//phoenix%3A4002/&c=UTF-8&d=We%20can%E2%80%99t%20connect%20to%20the%20server%20at%20phoenix.
     Build info: version: '4.0.0-beta-4', revision: 'a51085a604'
     System info: host: '254bef88f074', ip: '172.18.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.0-0.bpo.5-amd64', java.version: '11.0.11'
     Driver info: driver.version: unknown

So it looks like Firefox is unable to resolve the hostname of the phoenix service/container.

Showing Posts 1 to 1

antondomratchev

antondomratchev

Hello,

I have the same issue. I am only able to make it work if I explicitly specify the ip address of the container.

test.exs

config :hound,
  driver: "selenium",
  host: "http://selenium",
  port: 4444,
  browser: "chrome",
  app_host: "http://172.18.0.5",
  app_port: 4001

docker-compose.yml

web:
    build: ./docker/web
    depends_on:
      - db
      - redis
      - selenium
    environment:
      MIX_ENV: dev
    env_file:
      - .env
    ports:
      - '4000:4000'
    volumes:
      - .:/app
  selenium:
    image: 'selenium/standalone-chrome:4.1.2-20220131'
    ports:
      - 4444:4444
      - 7900:7900
    shm_size: 2g
    cap_add:
      - 'SYS_ADMIN'
    volumes:
      - '.:/home/seluser/files'

Have you been able to resolve this issue with hostname resolution on selenium ?

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews