Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental selenium driver #198

Merged
merged 9 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: elixir
elixir: 1.4.2
otp_release: 19.2
elixir:
- 1.4.2
- 1.3.4
otp_release:
- 19.2
- 18.2.1
# Run in bigger container so we don't run out of memory generating the plt
sudo: required
cache:
Expand All @@ -9,16 +13,25 @@ cache:
- deps
before_script:
- MIX_ENV=test mix compile --warnings-as-errors
- travis_wait mix dialyzer --plt
- "if [ -z ${WALLABY_DRIVER} ]; then travis_wait mix dialyzer --plt; fi"
- bash $TRAVIS_BUILD_DIR/test/tools/start_webdriver.sh

script:
- mix coveralls.travis
- mix dialyzer --halt-exit-status
- mix test
- "if [ -z ${WALLABY_DRIVER} ]; then mix dialyzer --halt-exit-status; fi"

matrix:
include:
- elixir: 1.3.4
exclude:
- elixir: 1.4.2
otp_release: 18.2.1
- elixir: 1.3.4
otp_release: 19.2

env:
- ""
- WALLABY_DRIVER=phantom
- WALLABY_DRIVER=selenium WALLABY_SELENIUM_VERSION=3
- WALLABY_DRIVER=selenium WALLABY_SELENIUM_VERSION=2

before_install:
- "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ config :wallaby,
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"

import_config "#{Mix.env}.exs"
1 change: 1 addition & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use Mix.Config
1 change: 1 addition & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use Mix.Config
4 changes: 4 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use Mix.Config

# Prevents timeouts in ExUnit
config :wallaby, hackney_options: [timeout: 10_000, recv_timeout: 10_000]
4 changes: 2 additions & 2 deletions integration_test/cases/browser/attr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Wallaby.Integration.Browser.AttrTest do
|> find(Query.css("body"))
|> attr("class")

assert class == "bootstrap"
assert class =~ "bootstrap"
end

test "can get the attributes of a query", %{session: session} do
Expand All @@ -17,6 +17,6 @@ defmodule Wallaby.Integration.Browser.AttrTest do
|> visit("/")
|> attr(Query.css("body"), "class")

assert class == "bootstrap"
assert class =~ "bootstrap"
end
end
35 changes: 24 additions & 11 deletions integration_test/cases/browser/click_button_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Wallaby.Integration.Browser.Actions.ClickButtonTest do
use Wallaby.Integration.SessionCase, async: true

alias Wallaby.Integration.Pages.IndexPage

setup %{session: session} do
page =
session
Expand All @@ -13,54 +15,60 @@ defmodule Wallaby.Integration.Browser.Actions.ClickButtonTest do
current_url =
page
|> click_button("Submit button")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking button with no type via name (submits form)", %{page: page} do
current_url =
page
|> click_button("button-no-type")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking button with no type via id (submits form)", %{page: page} do
current_url =
page
|> click_button("button-no-type-id")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking button type[submit] via button text (submits form)", %{page: page} do
current_url =
page
|> click_button("Submit button")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking button type[submit] via name (submits form)", %{page: page} do
current_url =
page
|> click_button("button-submit")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking button type[submit] via id (submits form)", %{page: page} do
current_url =
page
|> click_button("button-submit-id")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking button type[button] via button text (resets input via JS)", %{page: page} do
Expand Down Expand Up @@ -133,27 +141,30 @@ defmodule Wallaby.Integration.Browser.Actions.ClickButtonTest do
current_url =
page
|> click_button("Submit input")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking input type[submit] via name submits form", %{page: page} do
current_url =
page
|> click_button("input-submit")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking input type[submit] via id submits form", %{page: page} do
current_url =
page
|> click_button("input-submit-id")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking input type[button] via button text resets input via JS", %{page: page} do
Expand Down Expand Up @@ -226,18 +237,20 @@ defmodule Wallaby.Integration.Browser.Actions.ClickButtonTest do
current_url =
page
|> click_button("input-image")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "clicking input type[image] via id submits form", %{page: page} do
current_url =
page
|> click_button("input-image-id")
|> IndexPage.ensure_page_loaded
|> current_url

assert current_url == "http://localhost:#{URI.parse(current_url).port}/index.html"
assert current_url =~ "http://localhost:#{URI.parse(current_url).port}/index.html"
end

test "waits until the button appears", %{page: page} do
Expand Down
14 changes: 9 additions & 5 deletions integration_test/cases/browser/current_path_test.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
defmodule Wallaby.Integration.Browser.CurrentPathTest do
use Wallaby.Integration.SessionCase, async: true

alias Wallaby.Integration.Pages.{IndexPage, Page1}

test "gets the current_url of the session", %{session: session} do
url =
session
|> visit("")
|> click_link("Page 1")
|> IndexPage.visit()
|> IndexPage.click_page_1_link()
|> Page1.ensure_page_loaded()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love seeing all of these! Using best practices in our own tests is awesome!

|> current_url()

assert url == "http://localhost:#{URI.parse(url).port}/page_1.html"
Expand All @@ -14,9 +17,10 @@ defmodule Wallaby.Integration.Browser.CurrentPathTest do
test "gets the current_path of the session", %{session: session} do
path =
session
|> visit("")
|> click_link("Page 1")
|> current_path
|> IndexPage.visit()
|> IndexPage.click_page_1_link()
|> Page1.ensure_page_loaded()
|> current_path()

assert path == "/page_1.html"
end
Expand Down
3 changes: 2 additions & 1 deletion integration_test/cases/browser/page_source_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule Wallaby.Integration.Browser.PageSourceTest do
|> File.read!
|> clean_up_html

assert source == actual_html
# Firefox inserts a <!doctype html> so you can't do an exact comparison
assert actual_html =~ source
end

def clean_up_html(string) do
Expand Down
10 changes: 0 additions & 10 deletions integration_test/cases/browser/send_text_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ defmodule Wallaby.Integration.Browser.SendTextTest do
{:ok, %{page: page}}
end

test "sending key presses", %{session: session} do
session
|> visit("/")

session
|> send_keys([:tab, :enter])

assert find(session, ".blue")
end

describe "send_keys/3" do
test "accepts a query", %{page: page} do
page
Expand Down
4 changes: 2 additions & 2 deletions integration_test/cases/browser/window_size_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ defmodule Wallaby.Integration.Browser.WindowSizeTest do
window_size =
session
|> visit("/")
|> resize_window(1234, 1234)
|> resize_window(600, 400)
|> window_size

assert window_size == %{"height" => 1234, "width" => 1234}
assert %{"height" => 400, "width" => 600} = window_size
end
end
5 changes: 5 additions & 0 deletions integration_test/phantom/all_test.exs
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Code.require_file "../tests.exs", __DIR__

# Additional test cases supported by phantom
Code.require_file "../cases/browser/dialog_test.exs", __DIR__
Code.require_file "../cases/browser/file_test.exs", __DIR__
Code.require_file "../cases/browser/screenshot_test.exs", __DIR__
12 changes: 12 additions & 0 deletions integration_test/phantom/send_keys.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Wallaby.Integration.Phantom.SendKeys do
use Wallaby.Integration.SessionCase, async: true

alias Wallaby.Phantom.Driver

test "navigating with key presses", %{session: session} do
session
|> IndexPage.visit
|> send_keys([:tab, :enter])
|> Page1.ensure_page_loaded
end
end
2 changes: 2 additions & 0 deletions integration_test/phantom/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ExUnit.start()

# Load support files
Code.require_file "../support/test_server.ex", __DIR__
Code.require_file "../support/pages/index_page.ex", __DIR__
Code.require_file "../support/pages/page_1.ex", __DIR__
Code.require_file "../support/session_case.ex", __DIR__

{:ok, server} = Wallaby.Integration.TestServer.start
Expand Down
1 change: 1 addition & 0 deletions integration_test/selenium/all_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Code.require_file "../tests.exs", __DIR__
11 changes: 11 additions & 0 deletions integration_test/selenium/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ExUnit.configure(max_cases: 2, exclude: [pending: true])
ExUnit.start()

# Load support files
Code.require_file "../support/test_server.ex", __DIR__
Code.require_file "../support/pages/index_page.ex", __DIR__
Code.require_file "../support/pages/page_1.ex", __DIR__
Code.require_file "../support/session_case.ex", __DIR__

{:ok, server} = Wallaby.Integration.TestServer.start
Application.put_env(:wallaby, :base_url, server.base_url)
6 changes: 3 additions & 3 deletions integration_test/support/pages/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<body>
<h1>Forms</h1>
<form class="form" action="index.html" method="post">
<form class="form" action="index.html" method="get">
<label for="name_field">Name</label>
<input id="name_field" type="text" name="name" value="">
<input id="email_field" type="email" name="email" value="">
Expand Down Expand Up @@ -50,7 +50,7 @@ <h1>Forms</h1>
<input type="image" id="input-image-id" name="input-image" src="../images/button-image.png">
</form>

<form class="bad-form" action="index.html" method="post">
<form class="bad-form" action="index.html" method="get">
<div class="form-group">
<label>Input with bad label</label>
<input class="form-control" id="bad_label_input" name="user[name]" type="text">
Expand Down Expand Up @@ -79,7 +79,7 @@ <h1>Forms</h1>
</button>
</form>

<form class="wait-form" action="index.html" method="post">
<form class="wait-form" action="index.html" method="get">
<div class="js-hidden" style="display: none;">
<div class="form-group">
<label for="hidden-text-field-id">Hidden Text Field</label>
Expand Down
4 changes: 2 additions & 2 deletions integration_test/support/pages/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE HTML>
<html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Index</title>
</head>
<body class="bootstrap">
<body class="bootstrap index-page">
<h1 id="header">Test Index</h1>
<ul>
<li><a href="page_1.html">Page 1</a></li>
Expand Down
20 changes: 20 additions & 0 deletions integration_test/support/pages/index_page.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Wallaby.Integration.Pages.IndexPage do
use Wallaby.DSL

def visit(session) do
session
|> visit("")
end

def click_page_1_link(session) do
session
|> click(Query.link("Page 1"))
end

def ensure_page_loaded(session) do
session
|> Browser.find(Query.css(".index-page"))

session
end
end
15 changes: 15 additions & 0 deletions integration_test/support/pages/page_1.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Wallaby.Integration.Pages.Page1 do
use Wallaby.DSL

def visit(session) do
session
|> visit("page_1.html")
end

def ensure_page_loaded(session) do
session
|> Browser.find(Query.css(".page-1-page"))

session
end
end
Loading