Open Browser with Custom Profile

The new post by @ Brandon_Hein gave me a clue.

In my Chrome, I made a new proflile named Katalon. My problem was finding out which directory under the C:\Users\<MyOsUserName>\AppData\Local\Google\Chrome\User Data is linked to the new Katalon profile.

In the directory, I found 3 profile directores which contains Preferences file.

  • Default\Preferences
  • Profile 1\Preferences
  • Profile 2\Preferences

I look into all Preferences files, and found the Profile 2/Preferences file contains the following code:

{
    ...
    "profile": {
        ...
        "name": "Katalon",
        ...
    }
    ...
}

OK。Now I got it。All I need to do is as follows:

  1. locate the Chrome’s User Data directory: C:\Users\<MyOsUserName>\AppData\Local\Google\Chrome\User Data
  2. identify the name of Profile in question: Katalon
  3. search the User Data directory to look up subdirectories which contain a child Preferences file
  4. parse the Preferences file, select the value of /profile/name node in the json. If the value of /profile/name is equal to the Profile name in question (Katalon), then the directory is the one I want
  5. now I know the Profile directory I want is C:\Users\<MyOsUserName>\AppData\Local\Google\Chrome\User Data\<X>

This algorithm resolves the Profile name (Katalon) → the Directory name (X) deterministically.

I would implement this as a Custom Keyword.

4 Likes

Hi Thanh,

Thanks for this - it’s a big help. I’m able to launch chrome with the correct profile, but I’m running into an error caused by this line:
WebDriver driver = new ChromeDriver(chromeProfile);

Error:

Reason:
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /Applications/Google Chrome.app/Contents/MacOS/Google Chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Any insight into what might be causing this? Is it a versioning issue? The chrome profile I'm using is up to date (72.0.3626.121). I have noticed that I don't get this error if I kill all chrome processes before running (but of course that's not optimal). Any help would be greatly appreciated. 

Thanks, 

Will
1 Like

Hi @wil.fifer

It seems to be an issue with Selenium Web Driver itself according to this opened issue:

If you really want to get around it, then please try one of the suggestions there.

Regards !

Regards !

1 Like

As suggested by PascalGit1, the following approach worked for me.

ChromeOptions ChromeOptions = new ChromeOptions();
ChromeOptions.addArguments("--headless", "window-size=1024,768", "--no-sandbox");
driver = new ChromeDriver(ChromeOptions);

It seems that the option --headless is significant. When i removed --headless, the problem comes up.

Specifying --healeass makes my Chrome headless; I can not view the Chrome window any longer. This is not very much satisfactory. Still I want to find out a way to work around the “DevToolsActivePort file is missing” problem while keeping the Chrome window to be visible. I will continue researching a bit more.

1 Like

As for

this problem, in the selenium - WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser - Stack Overflow discussion, the following was mentioned.

this can be caused by using a Chromedriver which does not support the version of the installed Chrome. This can happen, for example, if chrome is upgraded without upgrading Chromedriver. – expz Nov 29 '18 at 21:12

It implies, that the chromedirver bundled in the Katalon Studio might be too old to work with the current version of Google Chrome.

OK, let me check it.


My Environment

OS: Windows 7
Katalon Studio version : 6.0.6 beta
chromedriver version: 2.43.600210
Chrome browser version: 72.0.3626.121

Required

Chrome Driver’s documentation ChromeDriver - WebDriver for Chrome - Downloads says

If you are using Chrome version 72, please download ChromeDriver 2.46 or ChromeDriver 72.0.3626.69"

Experiment

I downloaded the Chrome Driver 2.46 and installed into the Katalon Studio’s directory. I tried my test and found that the “DevToolsActivePort file doesn’t exist” problem disappeared.

Conclustion

The chromedrivers bundled in Katalon Studio 6.0.6 should be updated to the current releases.

1 Like

I could successfully developed a set of Groovy classes named webdriverfactory4ks. This library enables me to launch Groogle Chrome browser specifying a Custom Profile name. You can use it as follows:

import com.kazurayam.ksbackyard.webdriver.ChromeDriverFactory
...
	@Test
	void test_openChromeDriver() {
		ChromeDriverFactory cdFactory = new ChromeDriverFactory()
		WebDriver driver = cdFactory.openChromeDriverWithProfile('Katalon')   // Katalon is a Profile name
		assertThat(driver, is(notNullValue()))
		DriverFactory.changeWebDriver(driver)
		WebUI.navigateToUrl('http://demoaut.katalon.com/')
		WebUI.delay(3)
		WebUI.closeBrowser()
	}

This code set worked OK.

I would share the code later.

This code set involves a few Groovy classes, so it should be archived into a *.jar for sharing class files. The Katalon Plugin mechanism is still being developed, and would requires a few weeks to come.


edited 12/March/2019

I have published the webdriverfactory4ks-all.jar on GitHub.

2 Likes

Hi Thanh!
Thanks , It worked. But should we really need to provide the

// Here you specify the actual profile folder (Profile 2)
chromeProfile.addArguments("profile-directory=Profile 2");

above line . because in selenium with eclipse we can directly provide the profile directory like

String chromeProfilePath = “C:\Users\thanhto\AppData\Local\Google\Chrome\User Data\Profile 2”;

wouldn’t that possible here?

1 Like

What if a custom profile created need to run via Chrome headless Browser.

I tried Running the same script its working fine for normal chrome, when i used the same with Profile its opening the chrome.

1 Like

Hey ThanhTo, thanks much for this code, although I’m able to successfully launch the Chrome browser with a new custom profile, Katalon is displaying the following failure:
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.

The only change I made to your code was the pathToChromeDriver, I’m using my chrome executalbe at C: Program Files …, but that shouldn’t be causing this error, right??

1 Like

I keep getting this from the above code - please be gentle with me I am very very new to this and in the process of teaching myself.

Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/deric/Katalon%20Studio/TN/TrueNorth/Scripts/TrueNorth/TNGTCLogin/Script1636153465987.groovy: 26: unable to resolve class ChromeOptions
@ line 26, column 15.
ChromeOptions chromeProfile = new ChromeOptions();
^

file:/C:/Users/deric/Katalon%20Studio/TN/TrueNorth/Scripts/TrueNorth/TNGTCLogin/Script1636153465987.groovy: 26: unable to resolve class ChromeOptions
@ line 26, column 31.
ChromeOptions chromeProfile = new ChromeOptions();
^

file:/C:/Users/deric/Katalon%20Studio/TN/TrueNorth/Scripts/TrueNorth/TNGTCLogin/Script1636153465987.groovy: 31: unable to resolve class WebDriver
@ line 31, column 11.
WebDriver driver = new ChromeDriver(chromeProfile);
^

file:/C:/Users/deric/Katalon%20Studio/TN/TrueNorth/Scripts/TrueNorth/TNGTCLogin/Script1636153465987.groovy: 31: unable to resolve class ChromeDriver
@ line 31, column 20.
WebDriver driver = new ChromeDriver(chromeProfile);

Please can you help - all I want is to open chrome with the default profile.
there is an option to launch Chrome (with profile) but it is only available in the web recorder for some reason. and it does not work - it does not open chrome with my normal profile and settings and extensions , still just opens a blank chrome in dark mode with no profile or extensions

1 Like

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.html

you need to add two import statements:

import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.WebDriver
1 Like

Thanks @ThanhTo It worked. Although am able to open the browser with a custom profile, its showing below error
Reason:
com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened

Looks like am getting error in the below code :
WebDriver webDriver = DriverFactory.changeWebDriver(driver)

1 Like

Its underlined

How to use several browsers with different profiles simultaneously?

1 Like

Please read the doc of my “chromedriverfactory” project.

In this document, please find a sample code titled " Launch Chrome browser with UserProfile specified". Please look at a @Test method named void test_launch_browser_with_profile_TO_GO() . This method opens a single Chrome browser using a profile named “Picasso”. Just in the same way using any profile names, you can open 2 or more chrome browsers simultatiously.

In the code, the following fragment is important.

                ChromeDriverFactory.UserDataAccess.TO_GO)

please read the doc what this fragment means.

1 Like

You can download the latest version of the jar of “chromedriverfactory” here

1 Like

See also this:

This shows a Katalon Studio project that opens 2 chrome browsers while specifiying 2 difference profiles and perform test simultaneously.

WARNING This sample project used the artifact of my “WebDriverFactory4ks” project. But I have already abondoned the “WebDriverFactory4ks” project because there were bugs due to poor design failures. I would not maintain “WebDriverFactory4ks” project anylonger.

I have created another project “chromedriverfactory” project where I fixed problems as far as I could. If you are willing to try, please use the “chromedriverfactory” in favour of “WebDriverFactory4ks”

1 Like

Hello kazurayam,

We’ve been using code copied from an old contribution of yours, as a Chrome Profile Factory, for almost two years, since Autumn 21. This has been very helpful to us. Merci encore !!

It does work very well, but recently, I’ve hit a limitation, which we had seen in Winter 22, which I haven’t had the time to investigate further.

We use Microsoft Windows.

We are in the situation of getting Katalon working on a copied profile (what you now call the “TO_GO” option).

The original profile is:
AppData\Local\Google\Chrome\User Data\Profile 21
It does contain the cookies (SQLite database file) as:
AppData\Local\Google\Chrome\User Data\Profile 21\Network\Cookies

The profile factory creates a copy of the entire profile directory, like:
AppData\Local\Temp\User Data8672441348483056915
When the initial copy is done, if you get Katalon to stop, we can control that the copy was successful. The cookies are in:
AppData\Local\Temp\User Data8672441348483056915\Network\Cookies

But, after the browser has been instantiated, when Katalon can move to the next step after WebDriver myBrowser = WebDriverFactory.newWebDriver(DriverFactory.getExecutedBrowser(), “my profile name)” … we observe that the file has been modified. And the precious cookies are gone. Re-opening the Cookies file with our favorite SQLite tool shows it’s just empty!

Why would Chrome delete the cookies upon starting a profile in this situation (operating on a copy, started by ChromeDriver, etc)? For some sort of “security” reason?

Whatever the reason, my issue is to keep my cookies!

I’ve spent a few hours looking for a clue, typically musing about a possible ChromeDriver command-line switch that would allow to skip this behavior (List of Chromium Command Line Switches « Peter Beverloo), but I’ve not found. I’m still looking for a way to get the Chrome profile copy started with the cookies of the original profile.

If you have any idea, or suggestion or guess or question or whatever, I would greatly appreciate it.

Thanks in advance,
– Michel

1 Like

I have 2 GitHub repositories that concern opening browser with custom profile.

The #1 is an old project, which I have already abandoned maintenance. You seem to be using the #1 project.

The #2 is the successor of the #1 which I am willing to maintain for issues.

@michel.g

I would not maintain the #1 project any longer. Please consider switching to the #2 project.

I am reluctant to look into your question about the #1 project.

1 Like

I renamed the project “WebDriverFactory4ks” to “chromedriverfactory”. Why I abandoned the #1? I had 2 reasons.

  1. I wanted my library to have no dependency on the com.kms.katalon.** packages. It should be independent from Katalon Studio so that I could use it in a pure Gradle projects (non Katalon projects). See issue13;

  2. I gave up working on multiple types of browsers. I worked only on Chrome. Firefox and Edge are not supported. Why? I found that Firefox has a completely different architecture of custom profile from the one of Chome. I could not support Firefox and Chrome by a single codeset. Therefore I changed (shrinked) the project name: “WebDriverFactory” → “chromedriverfactory”. What about Edge Chromium? — Well, I don’t use Edge, so I am not interested in working on it. I learned that it is a difficult and tiring task to develop a single library that claims support for multiple types of browsers.

1 Like