Launch Browser with User Profile

What is User Profile
User profile stores your browser settings, bookmarks, extensions, apps, and saved passwords. This profile is stored in a separate folder on your computer, so if anything goes wrong with Chrome, your information is saved.

The location for browser’S user Profile folder differs depending on your platform and what browser is. Using Chrome as an example, the locations are:

* Windows 7, 8.1, and 10: C:\Users\\AppData\Local\Google\Chrome\User Data\Default
* Mac OS X El Capitan: Users//Library/Application Support/Google/Chrome/Default
* Linux: /home//.config/google-chrome/default

By default selenium launches a browser with no history, i.e with a new, clean profile. While this nice, but sometimes we want to run our tests against browser with specific profile, because some bugs only show when it runs against such kind of browser. I have seen some web features not working if ad-block is installed in the browser, or firefox in safe mode etc.

Launch FF with profile
ProfilesIni and FirefoxProfile are the classes to use

ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile(“path to your profile file”);
WebDriver driver = new FirefoxDriver(myprofile);

Launch Chrome with Profile
Add path to your chrome profile to ChromeOptions object, and it will do.

System.setProperty(“webdriver.chrome.driver”,”path to chromedriver”);
ChromeOptions options = new ChromeOptions();
options.addArguments(“user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data”);
options.addArguments(“–start-maximized”);
driver = new ChromeDriver(options);

For complete list of capabilities&options you can use to customize Chrome, see here:
https://sites.google.com/a/chromium.org/chromedriver/capabilities

Any new window opened by WebDriver is opened is also via the current profile. Once WebDriver is instantiated, it used the assigned profile. All cookies and sessions behave according to the profile settings

Leave a Reply

Your email address will not be published. Required fields are marked *