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

DIfferent :base_url for different sessions? #570

Open
peaceful-james opened this issue Sep 1, 2020 · 5 comments
Open

DIfferent :base_url for different sessions? #570

peaceful-james opened this issue Sep 1, 2020 · 5 comments

Comments

@peaceful-james
Copy link

Is it possible to use different :base_url for different sessions?

@mhanberg
Copy link
Member

Currently, no, but that could be a new feature.

What is your use case?

@peaceful-james
Copy link
Author

Currently, no, but that could be a new feature.

What is your use case?

My use case is a monorepo with two projects - an Elixir/Phoenix API and LiveView site running on localhost:4000 and a React SPA running on localhost:3000. I want to test full "user flows" where customers use the SPA on 3000 and staff/admin use the LiveView site on 4000. These two apps use Graphql Subscriptions and LiveView so an action by a customer may make staff view update (with no interaction).

Basically, i want to test full user stories spanning multiple realtime apps.

@mhanberg
Copy link
Member

mhanberg commented Dec 17, 2020

Gotcha, that makes sense.

Would something like this work for you?

defmodule MyAppWeb.TwoAppFeatureTest do
  use ExUnit.Case
  use Wallaby.Feature
  @spa_session [base_url: "http://localhost:3000"]
  @admin_session [base_url: "http://localhost:4000"]

  @sessions [@spa_session, @admin_session]
  feature "stuff happens", %{sessions: [spa, admin]} do
    spa |> login_user
    admin |> login_admin

    spa
    |> visit("/some-path")
    |> click(Query.button("Do Thing"))

    admin
    |> assert_text("some indicator that the user did a thing")
  end
end

@michallepicki
Copy link
Contributor

Hey @mhanberg @peaceful-james , until there's a nicer API, I know there are work-arounds. I think I had a test where I needed something like that, and I leveraged the fact that it is possible to use Browser.visit/2 with absolute paths. I had the :base_url set to an empty string, and to make it easier to visit appropriate base URL depending on context, I had helper functions. Something like spa |> visit(spa_path("/some_path")). Maybe you knew that already, but maybe this note will help someone else :)

@peaceful-james
Copy link
Author

Thanks for the information, both of you. The application I wanted to do this for has been finished for months now and I am knee-deep in a new project.
If I ever revisit this, i will be sure to try both of your techniques (although I think i have actually tried both of them). I always found that the main problem seems to be the length/duration of Wallaby tests. Small/short tests would pass but anything with extended bouts of interaction would randomly fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants