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

Only spawn a browser when using the feature macro, not normal tests #795

Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
- name: Run Tests
run: mix test || mix test --failed || mix test --failed

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: always()
with:
name: Selenium Logs
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
- name: Run Tests
run: mix test || mix test --failed || mix test --failed

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: always()
with:
name: Selenium Logs
Expand Down Expand Up @@ -250,7 +250,7 @@ jobs:
- name: Run Tests
run: mix test || mix test --failed || mix test --failed

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: always()
with:
name: Selenium Logs
Expand Down
4 changes: 4 additions & 0 deletions integration_test/cases/feature/use_feature_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Wallaby.Feature

@sessions 2
feature "multi session", %{sessions: [session_1, session_2]} do

Check failure on line 6 in integration_test/cases/feature/use_feature_test.exs

View workflow job for this annotation

GitHub Actions / Selenium V4 (27.x, 1.17.0-rc.1)

feature multi session (Wallaby.Integration.Browser.UseFeatureTest)
session_1
|> visit("/page_1.html")
|> find(Query.css("body > h1"), fn el ->
Expand All @@ -17,7 +17,7 @@
end)
end

feature "single session", %{session: only_session} do

Check failure on line 20 in integration_test/cases/feature/use_feature_test.exs

View workflow job for this annotation

GitHub Actions / Selenium V4 (27.x, 1.17.0-rc.1)

feature single session (Wallaby.Integration.Browser.UseFeatureTest)
only_session
|> visit("/page_1.html")
|> find(Query.css("body > h1"), fn el ->
Expand All @@ -31,7 +31,11 @@
"I'm a capability"
)
@sessions [[capabilities: @expected_capabilities]]
feature "reads capabilities from session attribute", %{session: %{capabilities: capabilities}} do

Check failure on line 34 in integration_test/cases/feature/use_feature_test.exs

View workflow job for this annotation

GitHub Actions / Selenium V4 (27.x, 1.17.0-rc.1)

feature reads capabilities from session attribute (Wallaby.Integration.Browser.UseFeatureTest)
assert capabilities.test == @expected_capabilities.test
end

test "does not set up a session for non-feature tests", context do
refute is_map_key(context, :session)
end
end
36 changes: 20 additions & 16 deletions lib/wallaby/feature.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ defmodule Wallaby.Feature do
import Wallaby.Feature

setup context do
metadata = unquote(__MODULE__).Utils.maybe_checkout_repos(context[:async])

start_session_opts =
[metadata: metadata]
|> unquote(__MODULE__).Utils.put_create_session_fn(context[:create_session_fn])

get_in(context, [:registered, :sessions])
|> unquote(__MODULE__).Utils.sessions_iterable()
|> Enum.map(fn
opts when is_list(opts) ->
unquote(__MODULE__).Utils.start_session(opts, start_session_opts)

i when is_number(i) ->
unquote(__MODULE__).Utils.start_session([], start_session_opts)
end)
|> unquote(__MODULE__).Utils.build_setup_return()
if context[:test_type] == :feature do
metadata = unquote(__MODULE__).Utils.maybe_checkout_repos(context[:async])

start_session_opts =
[metadata: metadata]
|> unquote(__MODULE__).Utils.put_create_session_fn(context[:create_session_fn])

get_in(context, [:registered, :sessions])
|> unquote(__MODULE__).Utils.sessions_iterable()
|> Enum.map(fn
opts when is_list(opts) ->
unquote(__MODULE__).Utils.start_session(opts, start_session_opts)

i when is_number(i) ->
unquote(__MODULE__).Utils.start_session([], start_session_opts)
end)
|> unquote(__MODULE__).Utils.build_setup_return()
else
:ok
end
end
end
end
Expand Down
Loading