enoliglesias

enoliglesias

Docker with phantomjs container and Hound testing

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:

Marked As Solved

enoliglesias

enoliglesias

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!

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement