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:

First 2 of 2 Posts Switch mode

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

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
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
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
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
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
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement