hound

Elixir library for writing integration tests and browser automation

Subscribe to updates I use hound


Statistics on hound

Number of watchers on Github 935
Number of open issues 62
Average time to close an issue 15 days
Main language Elixir
Average time to merge a PR 9 days
Open pull requests 19+
Closed pull requests 8+
Last commit 9 months ago
Repo Created almost 5 years ago
Repo Last Updated 6 months ago
Size 446 KB
Homepage http://hexdocs.pm...
Organization / Authorhashnuke
Latest Releasev1.0.0
Contributors18
Page Updated
Do you use hound? Leave a review!
View open issues (62)
View hound activity
View on github
Latest Open Source Launches
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating hound for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Hound

For browser automation and writing integration tests in Elixir.

Source | Documentation

Build Status

Features

  • Can run multiple browser sessions simultaneously. See example.

  • Supports Selenium (Firefox, Chrome), ChromeDriver and PhantomJs.

  • Supports Javascript-heavy apps. Retries a few times before reporting error.

  • Implements the WebDriver Wire Protocol.

**Internet Explorer may work under Selenium, but hasn't been tested.

Example

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

  hound_session()

  test "the truth", meta do
    navigate_to("http://example.com/guestbook.html")

    element = find_element(:name, "message")
    fill_field(element, "Happy Birthday ~!")
    submit_element(element)

    assert page_title() == "Thank you"
  end

end

Here's another simple browser-automation example.

Setup

Hound requires Elixir 1.0.4 or higher.

  • Add dependency to your mix project

{:hound, "~> 1.0"}
  • Start Hound in your test/test_helper.exs file before the ExUnit.start() line:
Application.ensure_all_started(:hound)
ExUnit.start()

When you run mix test, 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.

If you're using Phoenix

Ensure the server is started when your tests are run. In config/test.exs change the server option of your endpoint config to true:

config :hello_world_web, HelloWorldWeb.Endpoint,
  http: [port: 4001],
  server: true

Configure

To configure Hound, use your config/config.exs file or equivalent.

Example:

config :hound, driver: "phantomjs"

More examples here.

Usage

Add the following lines to your ExUnit test files.

# Import helpers
use Hound.Helpers

# Start hound session and destroy when tests are run
hound_session()

If you prefer to manually start and end sessions, use Hound.start_session and Hound.end_session in the setup and teardown blocks of your tests.

Helpers

The documentation pages include examples under each function.

The docs are at http://hexdocs.pm/hound.

More examples? Checkout Hound's own test cases

FAQ

Can I run multiple browser sessions simultaneously

Oh yeah ~! Here is an example.

If you are running PhantomJs, take a look at the Caveats section below.

Can I run tests async?

Yes.

The number of tests you can run async at any point in time, depends on the number of sessions that your webdriver can maintain at a time. For Selenium Standalone, there seems to be a default limit of 15 sessions. You can set ExUnit's async option to limit the number of tests to run parallelly.

Will Hound guarantee an isolated session per test?

Yes. A separate session is started for each test process.

PhantomJs caveats

PhantomJs is extremely fast, but there are certain caveats. It uses Ghostdriver for its webdriver server, which currently has unimplemented features or open issues.

Running tests

You need a webdriver in order to run tests. We recommend phantomjs but any can be used by setting the WEBDRIVER environment variable as shown below:

$ phantomjs --wd
$ WEBDRIVER=phantomjs mix test

Maintainers

Customary proclamation...

Copyright © 2013-2015, Akash Manohar J, under the MIT License (basically, do whatever you want)

hound open issues Ask a question     (View All Issues)
  • almost 2 years Allow for more relax timeout on on GenServer.call in session_server.ex
  • almost 2 years Tests fail randomly on start
  • almost 2 years Use headless chrome
  • almost 2 years Document the `cannot find ownership process for #PID<>` error
  • almost 2 years PDF content helpers
  • almost 2 years Similar function to capybara's save_and_open_page?
  • almost 2 years visible on page issue
  • about 2 years set_cookie with PhantomJS 2.1.*
  • about 2 years Possibly useful helpers?
  • about 2 years send_key inline documentation contains less atoms than key_codes_json can handle
  • about 2 years How to sideload PhantomJS Polyfills?
  • about 2 years find_element with :link_text does not work with phantomjs
  • about 2 years Cannot Reconnect to Active Webdriver Session
  • over 2 years Find element when there are multiple matching elements
  • over 2 years select option
  • over 2 years Session issue when working with PhantomJS
hound open pull requests (View All Pulls)
  • Added ability to fetch the console log
  • set_cookie accepts Map, not Dict
  • If we don't know what happened, pass the error along
  • Changes to `in_browser_session`
  • Added a note in the docs outlining difference b/w element?/2 and element_displayed?/1
  • Fix Unreliable Hound.Helpers.Session API
  • Execute phantomjs configuration scripts
  • Fix typo.
  • Utilize map_join over mapping and then joining
  • Bump Travis OTP version
  • Set screenshot dir
  • Retry session
  • 301, 302, 303 (only POST), 307 redirections
  • Describe local server launch in README.md
  • Uploading files
  • Allow to define a custom directory for screenshots/pages
  • deep merge options passed to hound_session
  • consider the browser as well as the driver in selecting the responseparser
  • Add outer_html/1 to the Elements helper
hound questions on Stackoverflow (View All Questions)
  • Elixir & hound headless browser
  • How Shazam or Sound Hound works?
hound list of languages used
hound latest release notes
v1.0.0 1.0 release

Breaking changes

  • find_element now returns a Hound.Element instead of a string
  • Driver capabilities cannot longer be passed directly to Hound.start_session and need to be passed in the :driver key: Hound.start_session(driver: %{my: "capability"})

New features

  • Support changing user agent: Hound.start_session(user_agent: :iphone)
  • Support metadata: Hound.start_session(metadata: %{my: :metadata})
  • Add search_element/2 and search_element_within/3, which are non raising version of find_element/2 and find_element_within/2
  • Add fetch_log/0 and fetch_errors/0 to get JS console output.
  • Add Firefox profile

Improvements

  • Timeouts now return a normal error instead of failing with a MatchError
v0.7.6 0.7.6
  • Remove starting phantomjs automatically
  • @scrogson: Simplify setup instructions
  • Update to use httpoison 0.8 to fix hackney header handling
v0.7.2 Changes to mix.exs for better docs

Docs now link to function's source in the github repo

Other projects in Elixir