Tests from the custom Chrome profile

Google Chrome is always the preferable browser on which to run tests. The Firefox and Chrome browsers work with binary. However, Internet Explorer doesn't need a profile to be set up to run tests because they run on the server user. In Chrome, the user data directory contains all the data of the given user, which includes history, bookmarks, and cookies. Add the following snippet to run tests from a new profile:

System.setProperty ("webdriver.chrome.driver","C:\chromedriver.exe");
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);

Note

If you face an error such as org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally, then create a new Chrome profile and execute the tests.

To get more information on the user data location (for different OS platforms), refer to http://www.chromium.org/user-experience/user-data-directory.

The following are the steps to create a custom Chrome profile:

  1. Copy the User Data folder (located at C:/Users/user_name/AppData/Local/Google/Chrome/User Data) and paste it in the same folder with a different name (for example, New User).
  2. Open the New User folder.
  3. Rename the Default folder, so that after your test run, a new folder named Default is created.
  4. Now, replace the directory in your code with C:/Users/user_name/AppData/Local/Google/Chrome/New User.
  5. To verify the new profile, try to bookmark some of the websites and observe them in the next run.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.72