enoliglesias

enoliglesias

Hi everyone!

I’m trying to run my integration test suite with Docker. I’m using Hound. And I have configured it this way:

docker-compose.yml

version: '2'
services:
  db:
    image: postgres:9.5
  phantomjs:
    image: wernight/phantomjs:latest
    command: phantomjs --wd
  web:
    build: .
    command: mix phx.server
    volumes:
      - .:/app
    ports:
      - "4000:4000"
      - "4001:4001"
    depends_on:
      - db
    links:
      - phantomjs

test.exs:

config :app, App.Endpoint,
  http: [port: 4001],
  server: true

[...]

config :hound,
  driver: "phantomjs",
  host: "http://phantomjs",
  app_host: "http://web",
  app_port: 4001

Then I’ve this simple test, in order to check that it works:

test_hound.exs

defmodule App.TestHound do
  use App.IntegrationCase

  defp login_index do
    session_url(App.Endpoint, :new)
  end

  test "dummy test" do
    login_index() |> navigate_to()

    assert element?(:class, "site") == true
  end
end

Then I run the test:

$ docker-compose run web env MIX_ENV=test mix test test/integration/test_hound.exs

but it didn’t pass:

Assertion with == failed
 code:  element?(:class, "site") == true
 left:  false
 right: true

I inspected with IO.inspect current_url() after execute the login_index() |> navigate_to() and it returns about:blank.
So the problem, I think, it’s that the test can’t connect properly with the phantomjs container in order to visit the web. It’s like it doesn’t launch the server. I inspected the login_index() too, and it returns the login URL.

My integration case, look like this:

integration_case.ex

defmodule App.IntegrationCase do
  use Hound.Helpers
  use ExUnit.CaseTemplate

  using do
    quote do
      use Hound.Helpers

      import Ecto
      import Ecto.Query
      import App.Router.Helpers
      import App.Factory
      import App.IntegrationCase

      alias App.Repo

      # The default endpoint for testing
      @endpoint App.Endpoint

      hound_session()
    end
  end

  setup tags do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(App.Repo)

    unless tags[:async] do
    Ecto.Adapters.SQL.Sandbox.mode(App.Repo, {:shared, self()})
    end

    :ok
  end
end

I’ve tried with different ports in the hound config, just in case, but I can’t make it work.

Any help would be appreciated. Thanks in advance! :blush:

Showing Posts 1 to 2

enoliglesias

enoliglesias OP

Rubber ducking debugging here! :smile:

It’s a little bit embarrassing to me. But the error was in the test.exs file. In the Endpoint configuration, I needed to add url: [host: "web"]. In order to change the default localhost endpoint to point to the web container:

config :hcmex, Hcmex.Endpoint,
  http: [port: 4001],
  url: [host: "web"],
  server: true 

Now if I run the tests (there are some IO.inspects):

"http://web:4001/sign_in"
{:ok,
%{browser: "phantomjs", driver: "phantomjs", host: "http://phantomjs",
  path_prefix: nil, port: 8910}}
{:ok, %{host: "http://web", port: 4001}}
.

Finished in 2.4 seconds
1 test, 0 failures

Randomized with seed 427281

And It works! I feel a little bit dumb right now. But I hope this post can help other people.

Cheers!

opinxit

opinxit

This helped a lot – thank you!

Though I’m finding I get CSRF errors when I post a form with a similar configuration – I can verify that the csrf token is included in the form, and if I run the test server manually I can post said form successfully, but hound/phantomjs does not like it. Any ideas?

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews