Open Browser with Custom Profile

Hi @aguggella

I will discuss with the team about this possibility and will let you know.

Regards !

1 Like

I am seriously interested in this topic.

I tried the Thanh To’s approach, and found a difficulty.

In my Chrome, I created a User named Katalon with an avatar of white flower. I switched to the Katalon user, and retrieved chrome://version page. Please find the following screenshot.

I expected that the Profile path should ends with a directory named equal to the User name: Katalon. But actually it doesn’t. The actual profile path ends with a directory named Profile 2. The actual profile path seems automatically resolved by the Chrome browser, hence it can be environment dependent.

This runtime environment dependency causes a problem for writing test scripts. Say, I have 2 PCs. I want to run just the same Katalon project. I can code the Chrome profile name Katalon.

How can a test case code can not resolve a User Katalon to some Profile name: Profile 1 or Profile 2 or Profile 3?

Does anybody know how to resolve this relation by scripting? Or do I have to check chrome://version page everytime manually to find out the profile path of the Katalon user?

Or is it possible for me to force chromedriver to tell chrome browser to make a Profile ending with the user name I wanted Katalon.

1 Like

One idea has come up to me.

How about using the Default profile directory always? I can expect the Default profile is there always. I would not add new User at all. I would use an existing Chrome user (no matter how it is named I should not mind it) which is resolved to the Default profile directory.

1 Like

@kazurayam

I am not following. You need another Chrome profile if you want to test on different profiles right ?

1 Like

I want to execute my test on AWS EC2 with Jenkins. I want to terminate the EC2 instance once the test finished, and create another one next time. Therefore the Chrome profile directories will be empty at startup. My test suites will requires some cached resources (cookies especially). For that, I would prepare some cached resources and store it somewhere, and restore it into the EC2 instance by shell or Gradle script.

The problem is, the name of Chrome User (Katalon) and the name of Profile directory (‘Profile x’) is varying; I want to find how a method to find the Profile directory with Chrome User name as key by script, without human intervention. — I can not find the method yet.

So, a possible opposite approach is to always use the Chrome Profile directory Default on EC2 instance and dont mind User name. — But another problem occurs. if I run this test suite on my daly-use PC, the Default profile directory will be overwritten by test fixture; this causes my daily-use Chrome be uncomforable.

1 Like

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