HashNuke / hound

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

current_url throws Poision.SyntaxError #146

Open kennedc opened 7 years ago

kennedc commented 7 years ago

I'm trying to get the current_url of a page with phantomjs

but calling current_url throws the error:

** (Poison.SyntaxError) Unexpected token at position 0: E
            lib/poison/parser.ex:57: Poison.Parser.parse!/2
            lib/poison.ex:83: Poison.decode!/2
    (hound) lib/hound/response_parsers/phantom_js.ex:4: Hound.ResponseParsers.PhantomJs.parse/2
    (hound) lib/hound/request_utils.ex:54: Hound.RequestUtils.handle_response/3
iex(1)> 

I'm running the following versions:

{:httpoison, "~> 0.10.0"},
{:floki, "~> 0.1.1"},
{:hound, "~> 1.0"}
 elixir: "~> 1.1-dev",
phantomjs -> 2.1.1

And i'm using config :hound, driver: "phantomjs"

page_source works as expected. any ideas?

Kenneth

denispeplin commented 7 years ago

Same error. phantomjs 2.1.1, Poison 2.2.0, Elixir 1.3.4.

Tried to install Hound from master branch, didn't help.

2) test guest survey (Portal.SurveyTest)
     test/integration/survey_test.exs:191
     ** (Poison.SyntaxError) Unexpected token: E
     stacktrace:
       (poison) lib/poison/parser.ex:56: Poison.Parser.parse!/2
       (poison) lib/poison.ex:83: Poison.decode!/2
       (hound) lib/hound/response_parser.ex:29: Hound.ResponseParser.parse/5
       (hound) lib/hound/request_utils.ex:48: Hound.RequestUtils.handle_response/3
       test/integration/survey_test.exs:220: (test)
danhper commented 7 years ago

Hi, thanks for reporting. I could not reproduce the issue. Could someone please provide a minimum code sample to reproduce this?

kylethebaker commented 7 years ago

I'm running into the same issue and I'm able to reproduce on a clean phoenix application running phantomjs 2.1.1.

Steps To Reproduce

Clean phoenix setup

mix phx.new testing_hound

In mix.deps

defp deps do
  [{:phoenix, "~> 1.3.0-rc"},
   {:phoenix_pubsub, "~> 1.0"},
   {:phoenix_ecto, "~> 3.2"},
   {:postgrex, ">= 0.0.0"},
   {:phoenix_html, "~> 2.6"},
   {:phoenix_live_reload, "~> 1.0", only: :dev},
   {:gettext, "~> 0.11"},
   {:hound, "~> 1.0"},
   {:cowboy, "~> 1.0"}]
end

In config/tests.ex

config :hound, driver: "phantomjs"

In test/testing_hound/web/acceptance/test_homepage.exs

defmodule TestingHound.HoundTest do
  use ExUnit.Case
  use Hound.Helpers

  hound_session()

  test "works" do
    navigate_to("/")
    assert page_source() =~ "<h2>Welcome to Phoenix!</h2>"
  end

  test "doesn't work" do
    navigate_to("/")
    title = find_element(:css, "h2") |> visible_text()
    assert title == "Welcome to Phoenix!"
  end
end

Hound Output

  1) test doesn't work (TestingHound.HoundTest)
     test/testing_hound/web/acceptance/test_homepage.exs:12
     ** (Poison.SyntaxError) Unexpected token at position 0: E
     stacktrace:
       (poison) lib/poison/parser.ex:57: Poison.Parser.parse!/2
       (poison) lib/poison.ex:83: Poison.decode!/2
       (hound) lib/hound/response_parser.ex:29: Hound.ResponseParser.parse/5
       (hound) lib/hound/request_utils.ex:48: Hound.RequestUtils.handle_response/3
       (hound) lib/hound/helpers/page.ex:65: Hound.Helpers.Page.search_element/3
       (hound) lib/hound/helpers/page.ex:48: Hound.Helpers.Page.find_element/3
       test/testing_hound/web/acceptance/test_homepage.exs:14: (test)

Finished in 3.1 seconds
2 tests, 1 failure

phantomjs Output

[INFO  - 2017-07-24T07:49:00.369Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 8e2f48c0-7044-11e7-89e8-431541cfc1a9
[ERROR - 2017-07-24T07:49:00.478Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:00.781Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:01.035Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:01.288Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:01.542Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:01.795Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:02.049Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:02.304Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:02.558Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:02.812Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}
[ERROR - 2017-07-24T07:49:03.065Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}

If I comment out the "doesn't work" test and leave the one using just page_source() then the test will pass.

kylethebaker commented 7 years ago

I've managed to reproduce without phoenix as well, which is quicker to get working, and I received the same outputs.

defp deps do
  [{:hound, "~> 1.0"}]
end
config :hound, driver: "phantomjs"
defmodule TestHound do
  use ExUnit.Case
  use Hound.Helpers

  hound_session()

  test "works" do
    navigate_to("https://elixir-lang.org/docs.html")
    assert page_source() =~ "<h2 id=\"documentation\">Documentation</h2>"
  end

  test "doesn't work" do
    navigate_to("https://elixir-lang.org/docs.html")
    title = find_element(:css, "#documentation") |> visible_text()
    assert title == "Documentation"
  end
end
Jojoooo1 commented 7 years ago

Having exactly the same issue than @kylethebaker, find_element/2 function seems to be the problem