簡體   English   中英

嘗試閱讀Hound中的網頁時,我收到了Hound.start_session的編譯錯誤

[英]Trying to read a webpage in Hound, I get a compilation error for Hound.start_session

我開始了一個新項目,並按如下方式進行配置:

mix new example
cd example

我清空“ lib / example.ex”並在其中放置以下代碼:

Application.start :hound

defmodule Example do
  use Hound.Helpers

  def run do
    Hound.start_session

    navigate_to "http://akash.im"
    IO.inspect page_title()

    # Automatically invoked if the session owner process crashes
    Hound.end_session
  end
end

Example.run

這是https://github.com/HashNuke/hound/blob/master/notes/simple-browser-automation.md提供的示例代碼

然后我通過brew install selenium-server-standalone安裝了Selenium服務器(我在MacOS上),通過brew services start selenium-server-standalone了它。 brew services start selenium-server-standalone並向config/config.exs添加了config :hound, driver: "selenium"

我添加了Application.ensure_all_started(:hound)作為test/test_helper.exs的第一行。

最后,我將{:hound, "~> 1.0"}到mix.exs並運行mix test 那就是我收到以下編譯錯誤時:

localhost:example alex$ mix test
===> Compiling parse_trans
===> Compiling mimerl
===> Compiling metrics
===> Compiling unicode_util_compat
===> Compiling idna
==> jason
Compiling 8 files (.ex)
Generated jason app
==> ssl_verify_fun
Compiling 7 files (.erl)
Generated ssl_verify_fun app
===> Compiling certifi
===> Compiling hackney
==> hound
Compiling 37 files (.ex)
Generated hound app
==> example
Compiling 1 file (.ex)

== Compilation error in file lib/example.ex ==
** (ArgumentError) argument error
    (stdlib) :ets.lookup(Hound.SessionServer, #PID<0.592.0>)
    (hound) lib/hound/session_server.ex:19: Hound.SessionServer.current_session_id/1
    (hound) lib/hound/session_server.ex:13: Hound.SessionServer.session_for_pid/2
    lib/example.ex:7: Example.run/0
localhost:example alex$ mix test
Compiling 1 file (.ex)

== Compilation error in file lib/example.ex ==
** (ArgumentError) argument error
    (stdlib) :ets.lookup(Hound.SessionServer, #PID<0.160.0>)
    (hound) lib/hound/session_server.ex:19: Hound.SessionServer.current_session_id/1
    (hound) lib/hound/session_server.ex:13: Hound.SessionServer.session_for_pid/2
    lib/example.ex:7: Example.run/0

我忘記某個地方的步驟或配置錯誤嗎? 任何幫助,萬分感謝,謝謝!

我清空了lib/example.ex並在其中放置了以下代碼:

 defmodule Example do
   ...
 end

 Example.run

.ex文件和.exs文件之間有區別。 您決定將代碼放入應用程序的主.ex文件中。 擺脫這一行:

Example.run

然后,要執行Example.run()請執行以下操作:

.../example$ iex -S mix

iex(1)> Example.run
"Akash Manohar // @HashNuke"
:ok

或者,您可以將擴展名更改為.exs ,然后使用以下代碼運行代碼:

.../example$ mix run lib/example.exs

另一方面,如果要使用mix test來運行測試,則必須將測試放在測試目錄中。 例如:

defmodule ExampleTest do
  use ExUnit.Case

  use Hound.Helpers

  test "page title is correct" do
    Hound.start_session

    navigate_to "http://akash.im"
    #IO.inspect page_title()
    assert page_title() == "Akash Manohar // @HashNuke"  

    Hound.end_session 
  end


end

此處的獵犬exunit示例中, hound_session()調用對我造成了錯誤:

15:06:33.736 [錯誤]終止**(RuntimeError)的GenServer Hound.SessionServer無法創建新的會話:超時,檢查webdriver是否正在運行(獵犬)lib / hound / session_server.ex:101:Hound.SessionServer.create_session / 2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM