Error While Testing Using Hound

Hello.
While I am testing with Hound library(using phantomjs). I have some error.

it is really simple integration test. something like.

test code is like this

hound_session()

  test "correct header title? " do
    navigate_to("/")
    h2_text = find_element(:tag, "h2") |> visible_text()
    assert h2_text == "Welcome to Phoenix!"
  end

and Error says like this.

  1. test correct header title? (MtextingWeb.Acceptance.HomePageTest)
    test/mtexting_web/acceptance/home_page_test.exs:7
    ** (RuntimeError) Webdriver call status code 404 for post request http://localhost:8910/session/94798eb0-902a-11e7-a87c-b3a11c5c7b73/element.
    Check if webdriver server is running. Make sure it supports the feature being requested.

    code: h2_text = find_element(:tag, “h2”) |> visible_text()
    stacktrace:
    (hound) lib/hound/request_utils.ex:50: 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/mtexting_web/acceptance/home_page_test.exs:10: (test)

Finished in 2.8 seconds
1 test, 1 failure

in phantomjs stack trace says,

[ERROR - 2017-09-02T22:03:41.378Z] RouterReqHand - _handle.error - {"line":40,"stack":"get\n_find\n_locateElement\n_handleLocateCommand\n_handle\n_reroute\n_handle"}

I have hound library installed.
I put
config :hound, driver: “phantomjs” in test.exs
Application.ensure_all_started(:hound) in test_helper.exs at the top.

Am I missing something?

All examples using hound I’ve found have used full urls. Please try that first.

Have you added server: true to you Endpoint config in in config/test.exs? I believe this is necessary to run hound.

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

config :hound, driver: "phantomjs"

hi!
I tried full urls like
http://localhost:4000/

but it still doesn’t work. :frowning:

Yes I did already

  1. Have you set server: true as @kylethebaker said?
  2. Is your test environment really listening on port 4000? Default for test is 4001 AFAIR, to not get in conflict with a running dev-server.
  3. Instead of hardcoding those URLs you should try to use the URL helpers to generate them… (which would avoid the confusion from 2 as well)
  1. Yes I did
  2. Yes I did also
    config :mtexting, MtextingWeb.Endpoint,
    http: [port: 4001],
    server: true
  3. Can you show me an example?

And strange thing is.

This test code work and pass

test "correct header title? " do
    navigate_to("/")
    assert page_source() =~ "Welcome to Phoenix!"
end

So, since it seems to work in a basic variant, we need to test something else…

Lets stepwise increase complexity:

First only find element:

test "correct header title? " do
  navigate_to("/")
  find_element(:tag, "h2")
  assert true
end

Second, try to get the visible stuff out of it:

test "correct header title? " do
  navigate_to("/")
  find_element(:tag, "h2") |> visible_text()
  assert true
end

Third, your original test.

Please report which one is the first to break… (Actually I omitted even one step, but you already confirmed a simple navigate with asserting truth as working)

Interesting, I’ve had my own issues in Hound where using find_element() causes an error but the regex matching with =~ works. It was a different error though so possibly not related.

Yes same here…

Ran into this while going through the Mastering Phoenix book.

Issue seems to be if you installed phantomjs via apt-get. See https://github.com/HashNuke/hound/issues/175 for more details.