twalpole / apparition

Capybara driver for Chrome using CDP
MIT License
363 stars 46 forks source link

Feature request: use CDP to get mobile settings #41

Closed geoffharcourt closed 4 years ago

geoffharcourt commented 4 years ago

Chrome for a while has not allowed the user to shrink the window width narrower than a certain width (I think it's 500px on most displays). We had thought that our mobile tests were getting down to narrower widths, but it turns out they are blocked.

You can get narrower if you select a device to simulate from the developer tools.

It looks like CDP supports mobile device simulation, this would be a pretty awesome thing to be able to do in Apparition. It would probably require being able to pass mobile in as a parameter and then have it pass through to here: https://github.com/twalpole/apparition/blob/170a98529bb3d49ee1a4335b43c183ee2eb9de41/lib/capybara/apparition/page.rb

https://developers.google.com/web/tools/chrome-devtools/device-mode

Would you be open to a PR to do this?

twalpole commented 4 years ago

Yes

geoffharcourt commented 4 years ago

I've managed to get this working in Selenium with a Chrome argument, but I haven't been able to get this to work via CDP even by hard-coding the settings in an Apparition branch. We're trying to set mobile: true along with a lower resolution and Chrome doesn't open in the mobile emulation mode. This is quite important to us, so we're continuing to investigate what combination of settings we need in CDP to make this work.

twalpole commented 4 years ago

You can always register a second driver instance, for mobile, passing the required chrome argument if this isn't possible via CDP

geoffharcourt commented 4 years ago

Yeah, that's what we're doing now, firing up Chromedriver for a handful of sensitive mobile tests. We love Apparition and have had a lot of improvement in stability using it, so I think this is worth digging a bit further. I'll see what we can do on our next housekeeping day.

geoffharcourt commented 4 years ago

I've gotten it to work. For my PR, I'm unsure of what the ideal way to pass these options in is from your perspective:

  1. add a new optional argument to #resize to pass device emulation parameters on to #set_viewport
  2. add a new method that is similar to #resize to override device emulation parameters and pass them on to #set_viewport
  3. have these options be passed in at driver registration time (this is probably what we'd do in our case)

We'd prefer #3 because for mobile scenarios we'd rather mark those specs to use a mobile browser from the start. I'm happy to do whatever you think would be most generally useful.

twalpole commented 4 years ago

3 probably makes the most sense, I don't see any real advantage to be able to switch mid run.