elixir-wallaby / wallaby

Concurrent browser tests for your Elixir web apps.
https://twitter.com/elixir_wallaby
MIT License
1.65k stars 197 forks source link

Interacting with opened windows/popups #360

Closed Papipo closed 5 years ago

Papipo commented 6 years ago

Hi!

I don't really know how to tackle an OAuth authentication step that happens on a popup. With Capybara, for example, you can access the driver and from there its windows. I haven't found a way to do that with Wallaby.

Apart from that, this is an awesome library, thanks!

keathley commented 6 years ago

@Papipo Thanks! Is the popup an alert or confirmation dialog? If so then you might look at these functions: https://github.com/keathley/wallaby/blob/v0.19.2/lib/wallaby/browser.ex#L760.

Let me know if I'm not understanding your specific use case correctly.

Papipo commented 6 years ago

I was talking about windows opened with things like window.open(). Although right now I am not entirely sure about this approach. I think that it could be better to use something like bypass and stub the result of the Oauth flow.

keathley commented 6 years ago

Are you using something like uberauth?

Papipo commented 6 years ago

Yes, that's what I plan to use, and I saw on their issue tracker a mention to bypass. I don't know if there is any other option.

keathley commented 6 years ago

Typically with uberauth I use the identity provider in development and test and have users log in through that.

Papipo commented 6 years ago

I don't think that fits my use case. I really want to use my ueberauth configuration for each provider. I still don't know how to mock this. Only if I could redirect /auth/provider to /auth/provider/callback on my tests...

keathley commented 6 years ago

So the core issue is that your trying to log in and it’s opening a new window instead of redirecting the page, and you need a way to interact with that new window?

Papipo commented 6 years ago

Yes, that was the original problem, how to interact with a new window with Wallaby.

For now, I have come up with a solution that I don't like in order to be able to redirect requests to /auth/provider to /auth/provider/callback:

  1. configure the ueberauth strategy host to be localhost + some port
  2. use Bypass on that port.
  3. Repeat with different ports for different strategies

The problem is that this setup won't work when I want to test with multiple sessions, I think.

keathley commented 6 years ago

This is theoretically possible to do with this functionality: https://www.w3.org/TR/webdriver/#dfn-switch-to-window. We already support getting window handles internally in chrome. We would just need to extend this functionality. This is NOT supported by phantom so I'm not sure how we should handle this from an api perspective.

michallepicki commented 5 years ago

This is what I've been using for switching windows with Selenium:

  import Wallaby.HTTPClient
  # ...
  def focus_window(session, window_handle) do
    {:ok, _} =
      request(:post, "#{session.url}/window", %{handle: window_handle, name: window_handle})
    session
  end