Skip to content

kazurayam/OpenChromeOnBehalfOfKatalonStudio

Repository files navigation

Open Chrome browser and let Katalon Studio use it

What is this?

This is a simple Katalon Studio project for demonstration purpose. You can check it out onto your PC and execute it with you Katalon Studio.

This project presents a work-around to the problem I raised in a discussion in the Katalon Forum "google chrome crashed on my pc ---- 2 reasons found"

How to run the example

Once cloned the project on your PC, you want to open the project in Katalon Studio.

This project is developed with Katalon Studio ver5.4.1.

At first, check the Execution Profile. In the default profile you will find 2 global variables: KATALONSTUDIO_HOME, DRIVERLOG_OUTPUT_DIRECTORY. Please change the value to fit to your environment.

Select one of test cases and run it.

Test Case name What it does expected result
TC1_defaultWayOfOpeningBrowser calls WebUI.openBrowser() as usual will succeed
TC2_openOrdinaryChrome instantiates ChromeDriver without additional options, and let Katalon Studio use it will succeed
TC3_openChromeWithSwitches instantiates ChromeDriver with an additional option, and let Katalon Studio use it. will fail

Description

My problem to solve

As "google chrome crashed on my pc ---- 2 reasons found" describes, Katalon Studio on my PC always fails to open Google Chrome browser. The reason I found out was as follows.

  1. Katalon Studio wants to start chrome.exe with --disable-extensions switch. This is proved by looking at the chromedriver.log file.
  2. On the other hand, on my PC, there is a Force-Installed-Extension installed in the Chrome browser. A Force-Installed-Extension can not be disabled.

This contradiction brings the Google Chrome crazy; it crashes.

What is 'Force-Installed-Extension'? --- Please refer to https://getadmx.com/?Category=Chrome&Policy=Google.Policies.Chrome::ExtensionInstallForcelist

Way of working-around

By looking at the log file of chromedriver.exe, I found that the Katalon Studio is telling chromedriver to generate a command to start chrome.exe with --disable-extensions switch. This switch causes problem with ForceInstalledExtensions. Therefore I want to start the Chrome somehow without --disable-extension switch.

After many searches in the Katalon Forum I got an idea:

  1. I won't rely on Katalon Studio for opening Chrome browser.
  2. Rather, my test case should instantiate org.selenium.org.openqa.selenium.chrome.ChromeDriver. Here I will NOT specify --disable-extensions switch.
  3. My test case should let Katalon Studio use the ChromeDriver instance for running tests. This can be done by calling com.kms.katalon.core.webui.driver.DriverFactory#changeWebDriver() method.

See the following snippet of TC2_openOrdinaryChrome:

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory

System.setProperty('webdriver.chrome.driver', "C:/Katalon_Studio_Windows_64-5.4.1/configuration/resources/drivers/chromedriver_win32/chromedriver.exe")
System.setProperty('webdriver.chrome.logfile', "C:/temp/chromedriver_TC2.log")


// open Chrome browser and let Katalon Studio to use it
WebDriver driver = new ChromeDriver()
DriverFactory.changeWebDriver(driver)

// execute some steps
WebUI.navigateToUrl('http://demoaut.katalon.com')
WebUI.verifyElementPresent(findTestObject("Page_CURA Healthcare Service/a_Make Appointment"), 20)

// close the browser
WebUI.closeBrowser()

I learned about DriverFactory#changeWebDriver() in the discussion at https://forum.katalon.com/discussion/comment/15164#Comment_15164

Result

As TC2_openOrdinaryChrome shows, I have managed to open the Chrome browser on my PC with ForceInstalledExtensions installed, and execute tests with Chrome. I am glad about it.

Now I can explain to my collegues at work: "You can run Katalon Studio tests with Google Chrome on our well-administrated PC, though a bit of tricks required".

How commandline switches should be

When I execute TC1_defaultWayOfOpeningBrowser, I found the following command is generated by chromedriver.exe. Note that --disable-extention switch is set.

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome.switches --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-extensions-except="C:\Users\username\AppData\Local\Temp\scoped_dir9548_2256\internal" --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --proxy-server=ftp=172.24.2.10:8080;http=172.24.2.10:8080;https=172.24.2.10:8080 --remote-debugging-port=12705 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\username\AppData\Local\Temp\scoped_dir9548_25002" data:, |

When I execute TC2_openOrdinaryChrome, I found the following command is generated by chromedriver.exe. Note that no --disable-extension switch appears.

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --load-extension="C:\Users\username\AppData\Local\Temp\scoped_dir8660_29138\internal" --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12555 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\username\AppData\Local\Temp\scoped_dir8660_21653" data:,

Here I compare these two commands. They are similar but not identical.

TC1 command TC2 command
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
--chrome.switches
--disable-background-networking --disable-background-networking
--disable-client-side-phishing-detection --disable-client-side-phishing-detection
--disable-default-apps --disable-default-apps
--disable-extensions
--disable-extensions-except="C:\Users\username\AppData\Local\Temp\scoped_dir9548_2256\internal"
--disable-hang-monitor --disable-hang-monitor
--disable-popup-blocking --disable-popup-blocking
--disable-prompt-on-repost --disable-prompt-on-report
--disable-sync --disable-sync
--disable-web-resources --disable-web-resources
--enable-logging --enable-logging
--force-fieldtrials=SiteIsolationExtensions/Control --force-fieldtrials=SiteIsolationExtensions/Control
--ignore-certificate-errors --ignore-certificate-errors
--log-level=0 --log-level=0
--metrics-recording-only --metrics-recording-only
--no-first-run --no-first-run
--password-store=basic --password-store=basic
--proxy-server=ftp=172.24.2.10:8080;http=172.24.2.10:8080;https=172.24.2.10:8080
--remote-debugging-port=12705 --remote-debugging-port=12555
--test-type=webdriver --test-type=webdriver
--use-mock-keychain --use-mock-keychain
--user-data-dir="C:\Users\username\AppData\Local\Temp\scoped_dir9548_25002" --user-data-dir="C:\Users\username\AppData\Local\Temp\scoped_dir8660_21653"
data:, data:,

Here I picked up discrepancies between the TC1 command and TC2 command.

I refered to a blog List of Chromium Command Line Switches to find the meaning of switches ... you need to wait over 10 seconds for response

switch, which has difference note
--chrome.switches This is not listed in the above blog page. It is likely that this switch is just ignored by Chrome; might be a mistake of Katalon Studio.
--disable-extensions Disable extensions.
--disable-extensions-except=... Disable extensions except those specified in a comma-separated list.
--proxy-server=...;http=172.24.2.10:8080;... Uses a specified proxy server, overrides system settings. This switch only affects HTTP and HTTPS requests.
--remote-debugging-port=12705 *Enables remote debug over HTTP on the specified port.
--user-data-dir=... Directory where the browser stores the user profile.

As for --proxyserver=xxxx switch, I thought it is not meaningful. Because my Chrome browser is already configured with Proxy info. It does not need to be instructed by Katalon Studio of Proxy info.

As for --remote-debugging-port=12705 switch, I found a description at https://blog.chromium.org/2011/05/remote-debugging-with-chrome-developer.html. I made one more test case TC3_openChromeWithSwitches and ran it to see what happens. The result was interesting. TC3 succeeded to open the Chrome browser but Katalon Studio failed to communicate with the Chrome. Katalon Studio emitted the following message:

Test Cases/TC3_openChromeWithSwitches FAILED because (of) org.openqa.selenium.WebDriverException: chrome not reachable
 (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
 Command duration or timeout: 60.68 seconds

I repeated executing TC1 and TC2 and found that the port number seems to be dynamically chosen: 12705, 12033, 12452, 12504, 12067, 12986, ...

OK, I should NOT explicitly specify --remote-debugging-port=xxxxx. I should leave as default.

My conclusion

The Chrome browser on my corporate PC has a ForceInstalledExtensions installed. I can not remove it. So I would apply the trick TC2_openOrdinaryChrome to run my tests on Katalon Studio with Chrome.