2

Here is my mix.exs

defmodule HelloPhoenix.Mixfile do
use Mix.Project

def project do
[app: :hello_phoenix,
 version: "0.0.1",
 elixir: "~> 1.0",
 elixirc_paths: elixirc_paths(Mix.env),
 compilers: [:phoenix, :gettext] ++ Mix.compilers,
 build_embedded: Mix.env == :prod,
 start_permanent: Mix.env == :prod,
 aliases: aliases,
 deps: deps]
end

# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
     [mod: {HelloPhoenix, []},
     applications: app_list(Mix.env) ]
 end

    def app_list do
    [:phoenix, :phoenix_html, :cowboy, :logger, :gettext, :phoenix_ecto, :postgrex]
end

    def app_list(:test), do: [:hound | app_list]
def app_list(_),     do: app_list


  # Specifies which paths to compile per environment.
      defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
  defp elixirc_paths(_),     do: ["lib", "web"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
[{:phoenix, "~> 1.1.4"},
 {:postgrex, ">= 0.0.0"},
 {:phoenix_ecto, "~> 2.0"},
 {:phoenix_html, "~> 2.4"},
 {:phoenix_live_reload, "~> 1.0", only: :dev},
 {:gettext, "~> 0.9"},
 {:cowboy, "~> 1.0"},
{:hound, "~> 0.8"}]
  end

  # Aliases are shortcut or tasks specific to the current project.
   # For example, to create, migrate and run the seeds file at once:
   #
   #     $ mix ecto.setup
   #
   # See the documentation for `Mix` for more info on aliases.
   defp aliases do
["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
 "ecto.reset": ["ecto.drop", "ecto.setup"]]
  end
 end

Here is my config/config.exs

# Define your application's host and port (defaults to "http://localhost:4001")
#config :hound, app_host: "http://localhost", app_port: 4000

# Start with selenium driver (default)
config :hound, driver: "selenium"

# Use Chrome with the default driver (selenium)
#config :hound, browser: "chrome"

# Start with default driver at port 1234 and use firefox
#config :hound, port: 1234, browser: "firefox"

# Start Hound for PhantomJs
#config :hound, driver: "phantomjs"

# Start Hound for ChromeDriver (default port 9515 assumed)
#config :hound, driver: "chrome_driver"

test/sample_test.exs

    defmodule HelloPhoenix.SampleTest do
  use HelloPhoenix.ConnCase

  # Import Hound helpers
  use Hound.Helpers

  # Start a Hound session
  hound_session
    IO.puts "hai"
  test "GET /" do
    navigate_to("http://localhost:4000")
    :timer.sleep(5000) # puts server to sleep
    assert page_source =~ "Welcome to Phoenix"
  end
end

config/test.exs

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

Starting a webdriver server (tried all these one at a time)

  1. java -jar selenium-server-standalone-2.48.2.jar

  2. java -jar selenium-server-standalone-2.49.0.jar

  3. java -jar selenium-server-standalone-2.52.0.jar

  4. docker run -it -p 4444:4444 danielfrg/selenium

  5. docker run --privileged -p 4444:4444 -p 5999:5999 -d vvoyer/docker-selenium-firefox-chrome

I get this error each time I run the app :

karthik@dkarnik2-Vostro-3558:~/5/hello_phoenix/hello_phoenix$ mix test
hai
....10:46:52.543 [error] GenServer Hound.SessionServer terminating
** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :econnrefused}}
    (hound) lib/hound/request_utils.ex:43:Hound.RequestUtils.send_req/4
    (hound) lib/hound/session_server.ex:67: Hound.SessionServer.handle_call/3
    (stdlib) gen_server.erl:629: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:661: :gen_server.handle_msg/5
    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3


  1) test GET / (HelloPhoenix.SampleTest)
     test/sample_test.exs:10
     ** (exit) exited in: GenServer.call(Hound.SessionServer, {:change_session, #PID<0.394.0>, :default, %{}}, 60000)
         ** (EXIT) an exception was raised:
             ** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :econnrefused}}
                 (hound) lib/hound/request_utils.ex:43: Hound.RequestUtils.send_req/4
                 (hound) lib/hound/session_server.ex:67: Hound.SessionServer.handle_call/3
                 (stdlib) gen_server.erl:629: :gen_server.try_handle_call/4
                 (stdlib) gen_server.erl:661: :gen_server.handle_msg/5
                 (stdlib) proc_lib.erl:240:     :proc_lib.init_p_do_apply/3
     stacktrace:
       (elixir) lib/gen_server.ex:544: GenServer.call/3
       test/sample_test.exs:8: HelloPhoenix.SampleTest.__ex_unit_setup_1/1
       test/sample_test.exs:1: HelloPhoenix.SampleTest.__ex_unit__/2



Finished in 0.7 seconds (0.5s on load, 0.1s on tests)
5 tests, 1 failure

Randomized with seed 332515
karthik@dkarnik2-Vostro-3558:~/5/hello_phoenix/hello_phoenix$
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Karthik
  • 315
  • 1
  • 4
  • 16
  • It looks like you have a closed port or the wrong IP address/host name. HTTPoison cannot connect to the server you're trying to reach. `:econnrefused` is usually the output of `erlang` when it cannot establish a TCP connection. – Alex de Sousa Feb 17 '16 at 15:55
  • 1
    @AlexanderDeSousa It works fine now. I just had to remove comment tag at : `#config :hound, browser: "chrome" ` in ***config/config.exs*** – Karthik Feb 18 '16 at 06:39
  • But it works fine only in googlechrome.. I want it to run with Firefox too.. To try running with Firefox, I commented `#config :hound, browser: "chrome"` and removed the comment tag from `config :hound, port: 1234, browser: "firefox"` in ***config/config.exs*** file, even then it doesn't work. i get the above error message. – Karthik Feb 18 '16 at 06:47
  • Are you using the port 1234? – Alex de Sousa Feb 18 '16 at 16:24
  • Selenium server default port is 4444 right..!! Should i change port 1234 to 4444 ?? – Karthik Feb 19 '16 at 03:33
  • I tried doing that @AlexanderDeSousa This time, `# Start with selenium driver (default)` `config :hound, driver: "selenium"` `# Use Chrome with the default driver (selenium)` `#config :hound, browser: "chrome"` `# Start with default driver at port 1234 and use firefox` `config :hound, port: 4444, browser: "firefox"` Yup this did work. Thanks a lot. – Karthik Feb 19 '16 at 03:36
  • @AlexanderDeSousa : Now I am trying to run the Selenium Server in Local Machine, and the above phoenix app in the VirtualBox Virtual Machine.. My local machine has Ubuntu 14.04. I am using docker-machine to ssh into the VM. How run the test cases being in VM ?? – Karthik Feb 19 '16 at 03:45
  • You should search in Stackoverflow for this, unless no one has asked this problem (in that case ask another question). Either way, maybe this will help: Attach the network adapter of your VM to a bridged adapter instead of NAT. NAT makes your guest machine unreachable from your host machine (unless you configure port forwarding). A bridged adapter will request an IP from the same network of your host machine (if DHCP is enable in your router/access point), hence they'll be visible to each other (unless you have a firewall, that's a more complex issue). – Alex de Sousa Feb 19 '16 at 09:56
  • Thank you @AlexandarDeSousa – Karthik Feb 21 '16 at 02:43
  • I will try it on VM tomorrow.. I will put up a question if I dont find the solution.. – Karthik Feb 21 '16 at 02:44
  • @AlexanderDeSousa : I have created a VM using **docker-machine**. Then I am **ssh** ing into it and running my elixir/phoenix app.. Obviously Selenium server is running beforehand, in local machine, with a small change this time. I am running a docker image containing selenium server (in local machine) and docker image containing elixir/phoenix app (in VM).. – Karthik Feb 23 '16 at 03:33
  • The IP address of my VM is 192.168.99.101 Now that the elixir/phoenix app runs within the container, its giving me the same above mentioned error (in the question) regarding econnrefused. Can you please brief me on how to establish a TCP connection.?? I am weak in Networking part. So.. – Karthik Feb 23 '16 at 03:40
  • It would be helpful if you explain it in detail. @AlexanderDeSousa – Karthik Feb 23 '16 at 03:41

1 Answers1

0

For the sake of completeness in case someone run into a similar problem, I'll make a summary:

When Erlang returns the :econnrefused error it means there is a problem with the connection. The following applies to any programming language, because it is a networking problem:

  • Your network interface is down. Solution: connect to the interface.
  • You are trying to connect to the wrong address and/or port. Solution: Look in your code or in your configuration to check the IP addresses and ports are correct. Also check if the remote host is actually in that IP address and listening for connections in that port.
  • You are being blocked by a firewall. Solution: This is a more complex issue because it depends on how you are deploying and testing your application.
  • The remote host is unreachable from the host where your application is running. Solution: Also it's a more complex issue, but, for starters, you may check if your remote host is in a private network:
    • Configure the appropriate port forwarding in the access point.
    • In case it's a VM, attach the virtual network interface of the guest OS to a bridged adapter instead of a NAT adapter and use the same network interface as your host OS. If you don't have DHCP enabled in your router/access point, then you should assign your guest machine a new IP address in the same network as your host machine. In Virtualbox, you can configure the adapter in Settings > Network.*
Alex de Sousa
  • 1,531
  • 12
  • 14