-1

Sometimes client and server side caching, cookies, and other complicating factors can get tricky, and when they do, sometimes opening an app in the browser and inspecting can be a quick way to see what's going on.

However, for various reasons, sometimes it would be nice to open the app in a completely isolated instance of chrome (or other browser), without any need to alter current chrome instance(s) (e.g. the reference pages you may have open, or even other tabs with your app loaded - sometimes you just want a completely isolated environment to open your app in, just as though it were another computer altogether).

How can this be achieved?

What I know so far

  • Incognito - the downside here is only once instance can be opened because multiple incognito windows will share cookies/assets
  • Run chrome in docker? (I haven't tried this it's just an idea)
  • The only sure-fire way I have atm is to simply put the app into production and view/test it on another computer altogether (this is not sensible nor efficient, as I'd like to test in development i.e. localhost)
  • Open app in another browser is another possibility, however, suppose we want to test specifically in chrome
stevec
  • 41,291
  • 27
  • 223
  • 311
  • 1
    If you're in chrome, why not just open firefox or edge or whatever else? – jvillian Oct 06 '20 at 23:42
  • @jvillian actually I should have added that to the 'what I know so far' section. I like that idea. If possible I'd like to stick to chrome, if only because I've spent more time using it and know a lot of its quirks and subtle features – stevec Oct 06 '20 at 23:43
  • @jvillian Almost certainly it is, either through RSpec or a quick dockerfile. Super important question ether way. The framework seriously lacks available info on incredibly basic things like this, so I'm taking one for the team and asking despite the mud/downvotes that may come my way – stevec Oct 06 '20 at 23:47
  • If it's a super important question, it seems curious that it is not well covered already. Best of luck. – jvillian Oct 06 '20 at 23:48
  • @jvillian there are open issues in two of the major ruby libraries that require simple/fast testing, and people haven't solved these issues yet. It's staggering. (my subjective suspicion) is that this testing is so slow because testing has not been made as accessible as it could be. – stevec Oct 06 '20 at 23:51
  • 1
    In Selenium it's common to pass a certain profile parameter so the launched browser instance doesn't share the history of the regular browser session. You can also reuse the profile directory. Is that what you want? – Martheen Oct 06 '20 at 23:52
  • @Martheen would that share *anything* with other session(s), and if not then it's definitely along the lines of what I'm after. If the session is started by selenium, I presume the dev can simply take it over and operate it themselves (i.e via point and click rather than automation?) – stevec Oct 06 '20 at 23:53
  • 1
    It won't share anything, it's as if you're starting clean. It's just command line parameter really, so your don't even need Selenium for that. I believe Chromium and Firefox based browsers support them – Martheen Oct 06 '20 at 23:54
  • @Martheen that sounds like a great improvement on methods I'm currently using. Please make it an answer and I will attempt it – stevec Oct 06 '20 at 23:55

1 Answers1

2

Chrome and Firefox supports using multiple profiles that won't affect each other, reusable (unlike incognito) and can even have entirely different extension ecosystem.

By creating and using multiple profiles, you can do development — creating extensions, modifying the browser, or testing the browser — while still being able to use Google Chrome as your default browser.

How to do it:

From Chromium docs:

The details of how to create and use a profile vary by platform, but here's the basic process:

  • Create a folder to hold data for the new profile.
  • Create a shortcut or alias that launches the browser, using the --user-data-dir command-line argument to specify the profile's location.
  • Whenever you launch the browser, use the shortcut or alias that's associated with the profile. If the profile folder is empty, the browser creates initial data for it.

In other words, simply create an empty directory somewhere and run this to open a new instance of chrome that's completely separate from any current one:

open -n -a "Google Chrome" --args --user-data-dir=$(mktemp -d)

Related:

  • see here for how to open chrome on mac and pass it arguments
  • see here for how to create a random temp directory in bash
  • see here for more on 'How do I start Chrome using a specified “user profile”?'
stevec
  • 41,291
  • 27
  • 223
  • 311
Martheen
  • 5,198
  • 4
  • 32
  • 55