首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图阅读“猎犬”的网页时,我得到了Hound.start_session的编译错误。

试图阅读“猎犬”的网页时,我得到了Hound.start_session的编译错误。
EN

Stack Overflow用户
提问于 2019-07-03 17:08:43
回答 1查看 341关注 0票数 0

我启动了一个新项目,并将其配置如下:

代码语言:javascript
复制
mix new example
cd example

我清空了lib/example.ex,并在其中放置了以下代码:

代码语言:javascript
复制
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启动了它,并将config :hound, driver: "selenium"添加到config/config.exs

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

最后,我将{:hound, "~> 1.0"}添加到mix.exs并运行mix test。当我收到以下编译错误时:

代码语言:javascript
复制
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

我是在某个地方忘记了一步,还是错误地配置了东西?任何帮助都非常感谢,谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-03 20:07:20

我清空了lib/example.ex,并将下面的代码放在那里:

代码语言:javascript
复制
 defmodule Example do
   ...
 end

 Example.run

.ex文件和.exs文件是有区别的。您决定将该代码放入应用程序的主.ex文件中。去掉这一行:

代码语言:javascript
复制
Example.run

然后,要执行Example.run(),您可以执行以下操作:

代码语言:javascript
复制
.../example$ iex -S mix

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

或者,您可以将扩展更改为.exs,然后使用以下代码运行代码:

代码语言:javascript
复制
.../example$ mix run lib/example.exs

另一方面,如果希望mix test运行测试,则必须将测试放在测试目录中。例如:

代码语言:javascript
复制
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

在猎犬实例这里中,hound_session()调用给我造成了一个错误:

15:06:33.736错误GenServer Hound.SessionServer终止** (RuntimeError)无法创建新会话:超时,检查webdriver正在运行(猎犬) lib/hound/session_server.ex:101: Hounds.essionServer.create_session/2

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56875042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档