0

I am trying to run my feature test using Wallaby but I keep getting the localhost refused to connect error.

Here is my compose.yml:

version: '2'
services:
  app:
    image: hin101/phoenix:1.5.1
    build: .
    restart: always
    ports:
      - "4000:4000"
      - "4002:4002"
    volumes:
      - ./src:/app
    depends_on:
      - db
      - selenium
    hostname: app
  db:
    image: postgres:10
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=hinesh_blogs
    ports:
      - 5432:5432
    volumes:
      - database:/var/lib/postgresql/data

  selenium:
    build:
      context: .
      dockerfile: Dockerfile-selenium
    container_name: selenium
    image: selenium/standalone-chrome-debug:2.52.0
    restart: always
    ports:
      - "4444:4444"
      - "5900:5900"
    hostname: selenium

volumes:
  database:

test_helper.ex:

ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(HineshBlogs.Repo, :auto)
{:ok, _} = Application.ensure_all_started(:ex_machina)
Application.put_env(:wallaby, :base_url, HineshBlogsWeb.Endpoint.url)
Application.put_env(:wallaby, :screenshot_on_failure, true)
{:ok, _} = Application.ensure_all_started(:wallaby)

config/test.exs:

use Mix.Config

# Configure your database
#
# The MIX_TEST_PARTITION environment variable can be used
# to provide built-in test partitioning in CI environment.
# Run `mix help test` for more information.
config :hinesh_blogs, HineshBlogs.Repo,
  username: "postgres",
  password: "postgres",
  database: "hinesh_blogs_test#{System.get_env("MIX_TEST_PARTITION")}",
  hostname: "db",
  pool: Ecto.Adapters.SQL.Sandbox,
  pool_size: 10


# We don't run a server during test. If one is required,
# you can enable the server option below.
config :hinesh_blogs, HineshBlogsWeb.Endpoint,
  http: [port: 4002],
  server: true

config :hinesh_blogs, :sql_sandbox, true

# Print only warnings and errors during test
config :logger, level: :warn

# Selenium
config :wallaby, otp_app: :hinesh_blogs_web, base_url: "http://localhost:4002/", driver: Wallaby.Selenium, hackney_options: [timeout: :infinity, recv_timeout: :infinity]

I run the tests using the command: docker-compose run app mix test

Do I need to have any additional configurations to run these tests and if not, what is the best way to configure wallaby to use docker containers?

Hinesh Patel
  • 1,161
  • 2
  • 7
  • 15
  • What happens if you change the `:wallaby` config to use `base_url: "http://app:4002/"`? – Peaceful James Aug 22 '20 at 17:19
  • I get the `app refused to connect` error – Hinesh Patel Aug 24 '20 at 18:00
  • Today I got Wallaby running in docker but I am using default `Chrome` driver. I did not use a separate service (like your `selenium` service) and instead just installed `chrome-driver` on the `app` container. I don't know how you are trying to make Wallaby use the selenium container. Can you show me the part of the config where you are telling Wallaby to use the selenium container? – Peaceful James Aug 26 '20 at 18:06

0 Answers0