Run Chrome with a different user than the one who started Katalon

chrome

#12

As said before, my code to launch an external application ( from Katalon ) wasn’t really working due to the security policy of my company. I solved my problem by adding Katalon to the white list of my company and now I can launch it with a normal user then Chrome is started by the same way.

BTW if you’re looking for some Java code allowing you to start a process :

import java.io.*;
Process process = new ProcessBuilder("C:\\PathToExe\\MyExe.exe","param1","param2").start();

#13

Hi, Does anyone has any solution to run chrome as different user? If so how can we communicate that driver to user specific profile before opening the browser itself. Please suggest.


#14

Have a look at this post:


#15

Thanks for giving me reference to look at but still i’m facing some issues. Please have a look at below and correct me if i’m doing anything wrong.

Note: I’m working on Client machine where network access and permissions are very restricted.

Steps followed as per my requirement:

  1. I did run as different user on Chrome browser and logged in using profile with username as ‘test01’ and password as ‘xxxxx’
  2. It opened a new instance and once i hit the testing url again it opens a alert box to enter the profile credentials so after i enter them i can access the site with that specific profile.
  3. Below is the profile path displayed and required admin permission to access the folder ‘test01’
  4. Profile path mentioned in chrome://version: “C:\Users\test01\AppData\Local\Google\Chrome\User Data\Default”

Code written to use profile
// Copy the path to chromedriver.exe
String pathToChromeDriver = “C:\Automation\Katalon_Studio_Windows_64-5.9.1\configuration\resources\drivers\chromedriver_win32\chromedriver.exe”

System.setProperty(“webdriver.chrome.driver”, pathToChromeDriver)

//The below profile path is the one that got created when i did run as different user
String chromeProfilePath = “C:\Users\test01\AppData\Local\Google\Chrome\User Data\”;

//String chromeProfilePath = “C:\Users\myuser\AppData\Local\Google\Chrome\User Data\”; -->> I can only access profiles for default user ‘myuser’ folder

ChromeOptions chromeProfile = new ChromeOptions();

chromeProfile.addArguments("–no-sandbox");
chromeProfile.addArguments("–disable-extensions");
chromeProfile.addArguments(“start-maximized”);

chromeProfile.addArguments("–disable-popup-blocking");
chromeProfile.addArguments("–disable-dev-shm-usage")
chromeProfile.setExperimentalOption(“useAutomationExtension”, false)

chromeProfile.addArguments(“user-data-dir=” + chromeProfilePath);
// Here you specify the actual profile folder (Profile 2)
chromeProfile.addArguments(“profile-directory=Default”);

WebDriver driver = new ChromeDriver(chromeProfile);
driver.get(“https://xxxxxxx/lightning/page/home”);
DriverFactory.changeWebDriver(driver)

Below is the error which i’m facing:
2019-05-03 17:52:39.341 [1;31mERROR[0;39m [36mc.k.katalon.core.main.TestCaseExecutor -[0;39m [31m❌ driver = new org.openqa.selenium.chrome.ChromeDriver(chromeProfile) FAILED.[0;39m
[31mReason:[0;39m
[31morg.openqa.selenium.WebDriverException: unknown error: cannot create default profile directory[0;39m


#16

Sorry, I do not follow you. I do not see what you want to achieve.

Do you use Windows OS user named “test01” not not?

Have you created a Chrome profile named “myuser” or not?

Please distinguish Windows OS user and Chrome Profile. It seems you do not distinguish these 2 different concepts.


#17

If you have created Chrome profile “myuser” and logged into Chome with it, then you want to retrieve chrome://version page. The page will show you the path of the Profile. That would look something like the following screenshot
profile_path
The Profile Path would be something like

D:\Users\test01\AppData\Local\Google\Chrome\User Data\Profile N

where N would be 1, 2, 3, 4,… it is allocated by Chrome when “myuser” profile is created.

You need to find which “Profile N” is allocated for the Profile “myuser” by Chrome. — see the following post, where I explained how I solved the problem.


#18

@kazurayam
i think is opposite, his win user is ‘myuser’ and ‘test01’ the profile created :slight_smile: … but i can be wrong, it is not very clear where the OP is blocked
@Madhuri on short, the new chrome profile created should be found under the windows user path and have a name like ‘Profile N’, don’t use the Default one.


#19

Hi @kazurayam and @Ibus, sry for the confusion
Yes my window user is ‘myuser’ so if I create any profile its been under ‘myuser’ with ‘Profile N’. But I’m unable to use this for my scenario as its little different.

Scenario 1: Client has given access for QA environment for my window user i.e., ‘myuser’ but can test only few scenarios. Its just a login with SSO option hence its logs in automatically without any user credentials.

Scenario 2: Client has provided few user profiles which we should do run as different user in chrome and then access the QA for testing other scenarios

Here the problem is even if I create profiles and hit the QA url the login with different profile doesn’t work, it just has login with SSO button so it automatically logs me as ‘myuser’

I can login with different profile only when I do run as different user in chrome and detailed steps followed is mentioned in my previous post

When I run as different user with username ‘test01’ and observed the profile path as below:
“C:\Users\test01\AppData\Local\Google\Chrome\User Data\Default”
I saw the folder test01 created as per above path but i cannot access the folder items

Please suggest how to achieve the second scenario in this case.

Thanks!!


#21

mhm … for me looks like the ‘test01’ is also a windows user provided.
i have a strong feeling that your client make your life complicated because he feels that he must be in control.
for such cross user/profile/browser automated testing, in order to be relevant (aka repeatable results), imho browserstack is the right solution, not a single reused phisical machine
relevant testing implies certain abstractization. at this moment you are enforced to test using ‘another winuser credentials’ but without permissions on that account. this is a no go, virtualization to the rescue


#22

this is a common problem created by dumbass product owners, they cannot understand that the tester must have full controll of the testing environment in order to produce accurate test results
othwrwise,as a last resort,we can do ‘extensive blind testing’. and god have mercy on them sorting the bug reports
@Madhuri i had once a similar issue. i just made a story defect, sort of ‘feature failed testing due to no relevant access for testing team to the environment’.
2nd day i was granted with admin rights on whatever i need :smiley:


#23

@kazurayam
Yes. They do give me access for QA for user ‘test01’ with Default Profile but I dont have permission to check the items in profile path.

Steps followed as per my requirement:

  1. I have to run as different user on Chrome browser and logged in using profile with username as ‘test01’ and password as ‘xxxxx’
  2. It opened a new chrome instance and once i hit the testing url again it opens a alert box to enter the profile credentials so after i enter them i can access the site with that specific user profile.

I need some way to automate the above procedure to execute my scripts in Katalon otherwise the scripts will be of no use :frowning:


#24

So you want to somehow automate entering the credential into the alert box. The alert box is possiblly Chrome native, nothing to do with HTML.

I have never seen it. Really I do not have idea what. But I guess, it is out of the scope of Katalon/Selenium UI automation capability which is all about HTML DOM operation.

I remember, several months ago, @Russ_Thomas mentioned about a tool (sorry I forgot the name) which enables you to automate any UI operation on Windows, and possible useful for Madhuri. I would invite him to join us here.


#25

@kazurayam winium?
@Madhuri see https://github.com/2gis/Winium


#26

Any tool which supports windows UI operation is fine but are those scripts can be integrated with Katalon.

I have done all the scripting in Katalon so pls suggest a way to integrate with the Window operation and then execute the groovy scripts using the same browser session


#27

there are some topics on this forum on how to use winium with katalon
e.g


#28

No.

Possibly, AutoHotKey,
https://www.autohotkey.com/

Russ once said he uses AutoHotKey a lot

I don’t know AutoHotKey at all.


Do you want to execute AutoHotKey as a part of Katalon Test Case?

Once I posted a Test Case example which executes Windows dir command.

You can execute any commands by this method. Possible you can execute AutoHotKey script as well.


#29

Ok. Will give it a try though i’m also very new to this tool.


#30

You can, yes. But I think some explanation is in order.

AHK hooks into the windows subsytem to monitor keyboard and mouse operation. When it receives a specific key or set of keys or a string it recognizes, it executes a predefined operation. IOW, it’s a macro system.

Aside: My description makes AHK sound like a simplistic macro player. Not true. It’s *much more than that. It’s quite complex and extremely powerful in the right hands.

The problems I see are:

  1. It’s a lot to learn to solve the OP’s problem.
  2. AHK “just sits there waiting”. It’s not designed to be “called” like other subsystems/programs.

If we assume you have managed to start AHK from Groovy code, you would then need to trigger the right keys in Groovy which target the browser to trigger the right macro in AHK (because it’s waiting for those keys).

Sounds messy.

I’m not saying it won’t work. Just sounds tricky - and there are too many moving parts.


#31

https://autohotkey.com/docs/Program.htm


#32

Hi @kazurayam and @Russ_Thomas, Thanks for your guidance.
Actually my client doesn’t support installing other softwares except Katalon which i’m currently using for Test Automation. So i have been searching for the solution for the past few days and got it from the below source.

I’m able to to run chrome as different user using java code but as you see from the above source there is no driver initialization or such. So could you please let me know if there is any way as how to tell Katalon to use the browser opened by the Java code.

Thanks for the help!!