HashNuke / hound

Elixir library for writing integration tests and browser automation
http://hexdocs.pm/hound
MIT License
1.36k stars 144 forks source link

Hound chrome_driver timeout error #49

Closed praveenperera closed 8 years ago

praveenperera commented 8 years ago

I'm trying to get a simple hound test working with my app, I figured out its an error with chrome_driver. I got it works perfectly fine with selenium + firefox and even with selenium + chrome.

However when using with chromedriver as the driver instead of selenium, it opens a new chrome window with data:, in the address bar and then timesout.

19:45:11.959 [error] GenServer Hound.SessionServer terminating
** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :timeout}}
    (hound) lib/hound/request_utils.ex:43: Hound.RequestUtils.send_req/4
    (hound) lib/hound/session_server.ex:22: 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 the truth (MyApp.AuthenticationIntegrationTest)
     test/integrations/authentication_integration_test.exs:7
     ** (exit) exited in: :gen_server.call(Hound.SessionServer, {:find_or_create_session, #PID<0.563.0>}, 60000)
         ** (EXIT) an exception was raised:
             ** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :timeout}}
                 (hound) lib/hound/request_utils.ex:43: Hound.RequestUtils.send_req/4
                 (hound) lib/hound/session_server.ex:22: 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:
       (stdlib) gen_server.erl:212: :gen_server.call/3
       test/integrations/authentication_integration_test.exs:5: MyApp.AuthenticationIntegrationTest.__ex_unit_setup_0/1
       test/integrations/authentication_integration_test.exs:1: MyApp.AuthenticationIntegrationTest.__ex_unit__/2

Here is my test:

defmodule AuthenticationIntegrationTest do
  use ExUnit.Case
  use Hound.Helpers

  hound_session

  test "the truth" do
    navigate_to("http://localhost:4000")
    assert current_url == "http://localhost:4000"
  end

end

I'm using Hound 0.7.5, thanks

Additional information:

HashNuke commented 8 years ago

@praveenperera Issue with HTTPoison actually. chromedriver has no problems. I've filed an issue https://github.com/edgurgel/httpoison/issues/86. Will wait for the author to take a look.

HashNuke commented 8 years ago

Header handling was fixed in hackney. In v0.7.6, I've updated the dependency to the latest httpoison. The new release should fix this issue. If you still have problems please do re-open this issue and let me know.

stochastic-thread commented 8 years ago

Following this tutorial: https://lord.io/blog/2015/elixir-scraping/

And I'm getting this error:

:ok, []}
iex(2)> Scraper.start
Starting now...

23:11:03.991 [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:22: 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
Last message: {:find_or_create_session, #PID<0.168.0>}
State: #HashDict<[]>
** (exit) exited in: :gen_server.call(Hound.SessionServer, {:find_or_create_session, #PID<0.168.0>}, 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:22: 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
     (stdlib) gen_server.erl:212: :gen_server.call/3
    (scraper) lib/scraper.ex:6: Scraper.start/0

With this mix.exs:

defmodule Scraper.Mixfile do
  use Mix.Project

  def project do
    [app: :scraper,
     version: "0.0.1",
     elixir: "~> 1.1",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps]
  end

  # Configuration for the OTP application
  #
  # Type "mix help compile.app" for more information
  def application do
    [applications: [:logger, :httpoison, :hound]]
  end

  # Dependencies can be Hex packages:
  #
  #   {:mydep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
  #
  # Type "mix help deps" for more examples and options
  defp deps do
    [
      {:httpoison, "~> 0.8.0"},
      {:floki,  "~> 0.7.1"},
      {:hound, "~> 0.7.6"}
    ]
  end
end
luismackmack commented 8 years ago

Hello, i would like write an script for automation browser using hound. In the practice, i have the following issue:


** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :timeout}}

This is my code, it's very simple.

ghost commented 8 years ago

I am getting this error when I try to run the test below. There error happens but the browser still launches. It seems like a timing error? I have selenium server running and I can see the sessions it creates on the hub. 13:32:12.294 [error] GenServer Hound.SessionServer terminating ** (MatchError) no match of right hand side value: {:error, :timeout} (hound) lib/hound/session_server.ex:78: Hound.SessionServer.handle_call/3 (stdlib) gen_server.erl:615: :gen_server.try_handle_call/4 (stdlib) gen_server.erl:647: :gen_server.handle_msg/5 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 Last message: {:change_session, #PID<0.215.0>, :default, []} State: %{}

defmodule LearnHoundTest do
  use ExUnit.Case
  use Hound.Helpers

  hound_session

  test "the truth"  do
    navigate_to("http://example.com/guestbook.html")

    element = find_element(:name, "message")
    fill_field(element, "Happy Birthday ~!")
    submit_element(element)

    assert page_title() == "Thank you"
  end
end

I am pretty new to Elixir so there could be a problem between the chair and keyboard but at the moment I am at a loss.

danhper commented 8 years ago

@blackoperat Hi, I suspect this is not an issue with Hound directly, but with the version of Selenium and Firefox. Firefox seems to be moving to the geckodriver to communicate with Selenium, so give a try to Selenium 3.0.0-beta2 with geckodriver (0.10.0 is the latest as writing this), it works perfectly for me.