diff --git a/README.md b/README.md index ec27c84..ded7899 100644 --- a/README.md +++ b/README.md @@ -52,24 +52,20 @@ Hound requires Elixir 1.0.2 or higher. * Add dependency to your mix project - ```elixir - # If you are using hex - { :hound, "~> 0.7.4" } - - # If you are not using hex - { :hound, github: "HashNuke/hound", tag: "v0.7.4" } - ``` +```elixir +# If you are using hex +{ :hound, "~> 0.7.4" } -* Add Hound to the list of applications to start in your `mix.exs`. Recommended to start Hound in test environment only. +# If you are not using hex +{ :hound, github: "HashNuke/hound", tag: "v0.7.4" } +``` - ```elixir - def application do - [ applications: app_list(Mix.env) ] - end +* Start Hound in your `test/test_helper.exs` file **before** the `ExUnit.start()` line: - defp app_list(:test), do: [:hound | app_list] - defp app_list(_), do: app_list - ``` +```elixir +Application.ensure_all_started(:hound) +ExUnit.start() +``` When you run `mix tests`, Hound is automatically started. __You'll need a webdriver server__ running, like Selenium Server or Chrome Driver. If you aren't sure what it is, then [read this](https://github.com/HashNuke/hound/wiki/Starting-a-webdriver-server). diff --git a/lib/hound/connection_server.ex b/lib/hound/connection_server.ex index 4d60749..88cf94b 100644 --- a/lib/hound/connection_server.ex +++ b/lib/hound/connection_server.ex @@ -39,22 +39,8 @@ defmodule Hound.ConnectionServer do :gen_server.start_link({:local, __MODULE__}, __MODULE__, state, []) end - defp start_browser("phantomjs") do - case System.cmd("pgrep", ["phantomjs"]) do - {"", _} -> - port = Port.open({:spawn, "phantomjs --webdriver=8910"}, []) - {:os_pid, os_pid} = Port.info(port, :os_pid) - - System.at_exit(fn _exit_status -> - System.cmd("kill", [to_string(os_pid)]) - end) - _ -> nil - end - end - defp start_browser(_), do: nil def init(state) do - start_browser(state[:driver_info][:driver]) {:ok, state} end diff --git a/lib/hound/helpers/navigation.ex b/lib/hound/helpers/navigation.ex index 8b01465..323409c 100644 --- a/lib/hound/helpers/navigation.ex +++ b/lib/hound/helpers/navigation.ex @@ -10,6 +10,10 @@ defmodule Hound.Helpers.Navigation do make_req(:get, "session/#{session_id}/url") end + @doc "Gets the path of the current page." + def current_path do + URI.parse(current_url).path + end @doc """ Navigates to a url or relative path. diff --git a/test/helpers/navigation_test.exs b/test/helpers/navigation_test.exs index f1f8ef5..f6d10e3 100644 --- a/test/helpers/navigation_test.exs +++ b/test/helpers/navigation_test.exs @@ -10,6 +10,11 @@ defmodule NavigationTest do assert url == current_url end + test "should get current path" do + url = "http://localhost:9090/page1.html" + navigate_to(url) + assert current_path == "/page1.html" + end test "should navigate to a url" do url = "http://localhost:9090/page1.html"