St Bernard is a simple series of webpages used to demonstrate the howling success of the Hound testing tool.
Whatever you call it, UI testing/End-to-End Testing/End-to-User Testing/Acceptance Testing--it is often an intensely manual and time-consuming process. Hound carries some of the load through browser automation. Browser automations means that I can automate my user interactions — clicks, fill inputs, file uploads, selecting options, radio buttons, etc. I use this app to demonstrate an overview of Hound and it’s helpers, as well as an example of how Hound tests saved me days of manual end-user testing.
Create a simple Phoenix called St Bernard.
$ mix phx.new stbernard --no-ecto
Add Hound as a dependency in mix.exs
.
{:hound, "~> 1.0"}
Hound requires a webdriver for browser automation. We will use selenium. Install and run:
$ brew install selenium-server-standalone
$ selenium-server
Start Hound in test/test_helpers.exs
. Add this above ExUnit.start()
Application.ensure_all_started(:hound)
In config/test.exs
add:
config :hound, browser: "chrome"
. . . and set server
to true:
config :stbernard, StbernardWeb.Endpoint,
http: [port: 4001],
server: true
Start the Phoenix server
- install dependencies with
mix deps.get
- install Node.js dependencies with
cd assets && npm install
- start interactive elixir:
iex -S mix phx.server
- visit
localhost:4000
from your browser.
Run tests (in this demo app, Hound is used as a part of ExUnit tests)
$ mix test
The acceptance tests live in test/stbernard_web/integration/
- test/
- stbernard_web/
- acceptance/
- form_test.exs
- charge_test.exs
- welcome_test.exs
- test_helper.exs
- navigate_to/2
- navigates to a url or relative path
- find_element/3
- accepts a strategy, selector, and optional retries value
- visible_text/1
- gets the visible text of an element
- page_title/0
- gets the title of the current page
- the
:xpath
strategy - click/1
- clicks on an element
- current_url/0
- gets url of the current page
- uses execute_script/2 to select value from a select list
- executes javascripts
- fill_field/2
- sets a field's value
- uses change_session_to/2 to use multiple browser sessions for permutations
- take_screenshot/1
- takes a screenshot of the current page
- slow down tests with
:timer.sleep()
- demonstrate how to select a value from an autocomplete input field with Awesomplete
- demonstrate Metadata in Hound session
- demonstrate change_session_to/2 to use multiple browser sessions for permutations
- Hound Helpers, in particular
- Hound Navigation Helpers
- Hound Element Helpers
- Hound Javascript Execution Helpers
- Hound Screenshot Helpers
- Configuring Hound: https://github.com/HashNuke/hound/blob/master/notes/configuring-hound.md
- Official website: http://www.phoenixframework.org/
- Guides: http://phoenixframework.org/docs/overview
- Docs: https://hexdocs.pm/phoenix
- Mailing list: http://groups.google.com/group/phoenix-talk
- Source: https://github.com/phoenixframework/phoenix