# Opening Chrome Browser with a predefined custom Chrome Profile which stores the session information such as credentials and cookies

**URL:** <https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966>\
**Category:** Tips and Tricks\
**Tags:** tips-tricks, katalon-studio\
**Created:** [March 12, 2019, 9:21am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966 "2019-03-12T09:21:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [March 12, 2019, 9:21am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/1 "2019-03-12T09:21:57Z")

</div>

I have made a GitHub project to develop and distribute the **webdriverfactory-all.jar**

> **[GitHub - kazurayam/WebDriverFactory4ks: A plugin module for Katalon Studio, with which you...](https://github.com/kazurayam/webdriverfactory4ks)**
>
> A plugin module for Katalon Studio, with which you can open Chrome Browser + Chrome Headless Browser while specifying Chrome User Profile you prepared.

## Problem to solve

### Original question

A post in the Katalon Forum [Run Automation in the Active browser](http://forum.katalon.com/t/run-automation-in-the-active-browser/19237/4) raised an interesting question. The originator **aguggella** gave us a good explanation what his/her problem is. I would quote the paragraphs with a bit of rewording:

> I have Salesforce application which will send OTP (one time password) to the client’s browser on the following occasions: (1) first time of logging-in, (2) at the second logging-in and later when the browser does not present credential information associated with the original OTP because the browser’s cache is cleared or empty

> I need to open browser manually and login to the Salesforce application once. A new OTP will be issued and processed. I will do that anyway. As long as I use the same Profile of Browser without clearing cached data, the original OTP is retained in the cache. I will not be asked to repeat login operation.

> Problem arises here: I want to automate testing the Salesforce application using Katalon Studio, but I can not. Why? Whenever I start test script, Katalon opens a new browser with no cached data. Therefore Salesforce application sends a new OTP. New OTP requires my manual intervention. Automation broken.

Let me assume, I opened Chrome with a Profile ‘Katalon user’ and logged-in Salesforce applition. If I could somehow let Katalon Studio to start Chrome with the same Profile ‘Katalon user’, then the test will run without requiring manual intervention. But how can I achieve it?

### How to open Chrome with predefined profile

**Thanh To** , a Katalon Developer, replied to **aguggella** in another post [Open Browser with Custom Profile](http://forum.katalon.com/t/open-browser-with-custom-profile/19268). He described the following points:

1. In Chrome UI, you can create a new Profile with name `new_chrome_profile`
2. In Chrome UI, you can identify the Profile path, a folder, where all of cached data is stored. For example, the Profile `new_chrome_profile` is found associated with the `C:\users\osusername\AppData\Local\Google\Chrome\User Data\Profile 2` folder. The association of `new_chrome_profile` and `Profile 2` was determined by Chrome when `new_chrome_profile` was added.
3. In Katalon Studio, in test case script, you can write Groovy code to open Chrome browser as this:

```auto
ChromeOptions chromeProfile = new ChromeOptions();
chromeProfile.addArguments("user-data-dir=" + "C:\\Users\\thanhto\\AppData\\Local\\Google\\Chrome\\User Data\\");
chromeProfile.addArguments("profile-directory=Profile 2");

```

It’s great to know that I can write test code that can open Chrome with predefined Profile. But I find a itchy problem still remains.

I created a new Profile with name `new_chrome_profile` . It was associated with a new folder named `Profile 2` . This association is determined by Chrome. It’s OK for me to write the profile name `new_chrome_profile` as a constant string in test cases. But I do not like writing the folder name `Profile 2` as a constant string in my test case code. As Thanh To described, I can find it by checking the `chrome://version` page. But this manual preparation looks less stylish with respect to complete automation.

### What my ChromeDriverFactory class does?

I have developed a custom groovy class `com.kazurayam.webdriverfactory4ks.ChromeDriverFactory` . Let me show you a sample use case of it. The following script assumes you have Chrome browser installed in your PC, and in it you have pre-defined a Profile with name `Katalaon` . Before executing the script, you want open Chrome with `Katalon` profile and visit whatever URL. Then you want to execute this script. You will find the Chrome browser launched by the test script is using the `Katalon` profile.

[Test Cases/main/example\_openChromeDriverWithProfile](https://github.com/kazurayam/webdriverfactory4ks/blob/master/Scripts/main/example_openChromeDriverWithProfile/Script1552363369432.groovy)

```auto
import org.openqa.selenium.WebDriver

import com.kazurayam.webdriverfactory4ks.ChromeDriverFactory
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

ChromeDriverFactory cdFactory = new ChromeDriverFactory()
WebDriver driver = cdFactory.openChromeDriverWithProfile('Katalon') // THIS IS THE MAGIC!
assert driver != null
DriverFactory.changeWebDriver(driver)
WebUI.navigateToUrl('https://demoauto.katalon.com/')
WebUI.delay(3)
WebUI.closeBrowser()

```

## How to use webdriverfactory4ks in your Katalon project

1. Download the `webdriverfactory4ks-all.jar` from the GitHub project’s [Releases](https://github.com/kazurayam/webdriverfactory4ks/releases/tag/0.0) page.
2. Place the jar into the `Drivers` directory of you Katalon Studio project; just as documented in the doc [External libraries](https://docs.katalon.com/katalon-studio/docs/external-libraries.html)
3. Write your test case script which calls the `com.kazurayam.webdriverfactory4ks.ChromeDriverFactory` class.

## Examples

The following examples will show you how to utilize this.

1. [Test Cases/main/example\_openChromeDriverWithProfile](https://github.com/kazurayam/webdriverfactory4ks/blob/master/Scripts/main/example_openChromeDriverWithProfile/Script1552363369432.groovy) — opening Chrome specifying a predefined Profile name
2. [Test Cases/main/example\_openChromeDriverWithProfileDirectory](https://github.com/kazurayam/webdriverfactory4ks/blob/master/Scripts/main/example_openChromeDriverWithProfileDirectory/Script1552363390928.groovy) — opening Chrome specifying a name of Profile directory, for example `Default` directory.
3. [Test Cases/main/example\_startGmailWithoutLoginOperation](https://github.com/kazurayam/webdriverfactory4ks/blob/master/Scripts/main/example_startGmailWithoutLoginOperation/Script1552363984695.groovy) — this demonstrates that I can navigate into Gmail without login operation if I open Chrome with the `Default` directory.

---

<div class="post-metadata">

**Author:** ![hari.garlapati](https://avatars.discourse-cdn.com/v4/letter/h/7bcc69/32.png) [@hari.garlapati](https://forum.katalon.com/u/hari.garlapati)\
**Post date:** [May 10, 2019, 2:18am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/2 "2019-05-10T02:18:42Z")

</div>

Hi,

Not able to use above solution to open chrome browser with custom or default profile and observed below error:  
Reason:  
org.openqa.selenium.WebDriverException: unknown error: failed to write prefs file  
(Driver info: chromedriver=74.0.3729.6

Need your help to fix this issue ASAP. Appreciated your early response.

---

<div class="post-metadata">

**Author:** ![hari.garlapati](https://avatars.discourse-cdn.com/v4/letter/h/7bcc69/32.png) [@hari.garlapati](https://forum.katalon.com/u/hari.garlapati)\
**Post date:** [May 10, 2019, 2:18am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/3 "2019-05-10T02:18:49Z")

</div>

need help" code is failing: and Reason:  
org.openqa.selenium.WebDriverException: unknown error: failed to write prefs file  
(Driver info: chromedriver=74.0.3729.6

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 10, 2019, 9:19am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/4 "2019-05-10T09:19:47Z")

</div>

webdriverfactory4ks works for me.

My environment is

| software | version |
| --- | --- |
| Katalon Studio | 6.1.4 |
| chromedirver | 74.0.3729.6 |
| Chrome browser | 74.0.3729.131 |

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 10, 2019, 9:20am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/5 "2019-05-10T09:20:25Z")

</div>

`com.kazurayam.webdriverfactory4ks.ChromeDriverFactory` does NOT create a Chrome Profile for you.

You need to manually create a Chrome profile `XXXXXX` manually before calling `cdFactory.openChromeDriverWithProfile('XXXXXX')`.

How? — See [https://www.bettercloud.com/monitor/the-academy/how-to-create-switch-profiles-in-chrome/](https://www.bettercloud.com/monitor/the-academy/how-to-create-switch-profiles-in-chrome/)

Have you created a Chrome Profile with which you want to open?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 13, 2019, 1:18pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/6 "2019-05-13T13:18:06Z")

</div>

> [@hari.garlapati](#):
>
> Reason:  
> org.openqa.selenium.WebDriverException: unknown error: failed to write prefs file

Some stack overflow posts discusses some possible reasons which may cause this problem. For example,

- [c# - unknown error: failed to write prefs file for loading multiple chrome profile - Stack Overflow](https://stackoverflow.com/questions/34107651/unknown-error-failed-to-write-prefs-file-for-loading-multiple-chrome-profile) sais

```auto
Exception "unknown error: failed to write prefs file" is thrown when same 
user-data-dir and profile is used by two chrome instances in parallel.

```

In this case, you should stop ALL Chrome browser, and try again.

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/timo_kuisma1/32/16103_2.png) [@Timo\_Kuisma1](https://forum.katalon.com/u/Timo_Kuisma1)\
**Post date:** [February 7, 2020, 9:35pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/7 "2020-02-07T21:35:36Z")

</div>

hi,

please fix the paths in a document & testcases  
//import com.kazurayam.ks.thoughtful.ChromeDriverFactory  
import com.kazurayam.webdriverfactory4ks.ChromeDriverFactory  
//import com.kazurayam.ks.thoughtful.ChromeProfileFinder  
import com.kazurayam.webdriverfactory4ks.ChromeProfileFinder

---

<div class="post-metadata">

**Author:** ![Mark\_Daniel\_Magumcia](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mark\_Daniel\_Magumcia](https://forum.katalon.com/u/Mark_Daniel_Magumcia)\
**Post date:** [May 21, 2020, 11:43am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/8 "2020-05-21T11:43:07Z")

</div>

Hi @kazurayam, how were you able to handle this error

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/7/7b4e857a881537da90c2f308a10ae42fb2e03c90.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 21, 2020, 11:44am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/9 "2020-05-21T11:44:42Z")

</div>

Close all of Chrome Browser’s Window on your PC before you execute the test.

---

<div class="post-metadata">

**Author:** ![Mark\_Daniel\_Magumcia](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mark\_Daniel\_Magumcia](https://forum.katalon.com/u/Mark_Daniel_Magumcia)\
**Post date:** [May 21, 2020, 11:46am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/10 "2020-05-21T11:46:28Z")

</div>

Is there no other way for this to be handled? I’m not running my Automation on Virtual Machine or remotely

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 21, 2020, 11:49am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/11 "2020-05-21T11:49:46Z")

</div>

Vertual Machine? remotely? — I do not understand how these factors concern about “user data directory is already in use” problem.

---

<div class="post-metadata">

**Author:** ![Mark\_Daniel\_Magumcia](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mark\_Daniel\_Magumcia](https://forum.katalon.com/u/Mark_Daniel_Magumcia)\
**Post date:** [May 21, 2020, 11:57am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/12 "2020-05-21T11:57:14Z")

</div>

Since you mentioned that other open browsers should be closed, i figured that in order for me to run this safely without disrupting my other tasks, it would really need me to use some virtual machine so I can isolate my automation runs. Anyways, your code helped me figure out how to bypass Active Directory. Thank you very much for this! 😃

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 21, 2020, 11:58am UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/13 "2020-05-21T11:58:07Z")

</div>

The following post may help

> <https://stackoverflow.com/questions/50635087/how-to-open-a-chrome-profile-through-user-data-dir-argument-of-selenium>

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 21, 2020, 12:51pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/14 "2020-05-21T12:51:01Z")

</div>

> [@kazurayam](#):
>
> Let me assume, I opened Chrome with a Profile ‘Katalon user’ and logged-in Salesforce applition. If I could somehow let Katalon Studio to start Chrome with the same Profile ‘Katalon user’, then the test will run without requiring manual intervention.

This was my primary motivation why I researched how to start Chrome Browser with predefined custom Chrome Profile.

To tell you the truth, I was not successful for my issue. I have never succeeded to make Chrome Browser started retaining “already logged in status” of Web applications. I could not find out the detail but Chrome Browser is very well-engineered in terms of “Security”. I could not cheat Chrome at all.

I have got tired trying to cheat Chrome, and I am negative I could achieve it in future.

---

<div class="post-metadata">

**Author:** ![bogdan](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bogdan](https://forum.katalon.com/u/bogdan)\
**Post date:** [May 22, 2020, 1:06pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/15 "2020-05-22T13:06:31Z")

</div>

@kazurayam  
Man , you`ve solved one of my worst problems and i thank you so mush \<3 .  
But there is always the question, can we have the same thing for other browsers , Firefox , Opera,Safari maybe ?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 22, 2020, 1:11pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/16 "2020-05-22T13:11:24Z")

</div>

> [@bogdan](#):
>
> can we have the same thing for other browsers , Firefox , Opera,Safari

No, I am not willing to. Looking at one browser is heavy enough. No more, thanks.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 22, 2020, 1:18pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/17 "2020-05-22T13:18:13Z")

</div>

I have ever worked on Firefox:

> [@Opening Firefox with a Specific, non anonymous profile](http://forum.katalon.com/t/opening-firefox-with-a-specific-non-anonymous-profile/12012/7):
>
> I will describe what I have found. I made 2 Firefox profiles: usualProfile and seleniumProfile: [image] By clicking “start firefox” button with seleniumProfile selected, I got the following “about:profiles” page. Please note that a Green Extension icon is displayed. This Green icon indicates that Firefox is opened with seleniumProfile. [image] In the “firefox.exe -P” dialog I selected usualProfile. [image] Then, By clicking “start firefox” button with usualProfile selected, I got the foll…

but I forgot all about this.

---

<div class="post-metadata">

**Author:** ![Bojan\_Ognjenovic](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/bojan_ognjenovic/32/16974_2.png) [@Bojan\_Ognjenovic](https://forum.katalon.com/u/Bojan_Ognjenovic)\
**Post date:** [October 19, 2020, 12:50pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/18 "2020-10-19T12:50:42Z")

</div>

Hello! Any chance to do the same in incognito mode?  
Thanks for the aswer.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 19, 2020, 12:58pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/19 "2020-10-19T12:58:10Z")

</div>

> [@Bojan\_Ognjenovic](#):
>
> Any chance to do the same in incognito mode?

I don’t understand this. Chrome incognito mode and Chrome Profile — these 2 things seem not relevant at all to me.

---

<div class="post-metadata">

**Author:** ![Bojan\_Ognjenovic](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/bojan_ognjenovic/32/16974_2.png) [@Bojan\_Ognjenovic](https://forum.katalon.com/u/Bojan_Ognjenovic)\
**Post date:** [October 19, 2020, 1:12pm UTC](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966/20 "2020-10-19T13:12:05Z")

</div>

I’ve set up the profile, did all the steps, however, is it possible for that profile to open a chrome in incognito mode, always?

[Next page](https://forum.katalon.com/t/opening-chrome-browser-with-a-predefined-custom-chrome-profile-which-stores-the-session-information-such-as-credentials-and-cookies/20966.md?page=2)
