Unable to test with a newly created firefox profile

Hi, i am currently exploring newly created profile in firefox.

The issue i am facing is that using the Custom Desired Capabilities, i wanted to execute some test scripts with the newly created firefox profile as named in screenshot, Chris_Hemsworth.

How can i do that?

I did tried something on my own and below is the code but not working:

{"FIREFOX_DRIVER":{"moz:firefoxOptions":{"args":["--profile\-p -no-remote ChrisHemsworth"]}}}

Here is a piece of log of error obtained:

2021-03-30 20:37:01.360 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2021-03-30 20:37:01.376 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/New Test Case
2021-03-30 20:37:03.687 DEBUG testcase.New Test Case                   - 1: open_browser.open_browser.openBrowser()
2021-03-30 20:37:04.243 INFO  c.k.k.core.webui.driver.DriverFactory    - Starting 'Firefox' driver
Mar 30, 2021 8:37:04 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
2021-03-30 20:37:04.418 INFO  c.k.k.c.w.util.WebDriverPropertyUtil     - User set preference: ['moz:firefoxOptions', '{args=[--profile=-p -no-remote ChrisHemsworth]}']
2021-03-30 20:37:04.419 INFO  c.k.k.core.webui.driver.DriverFactory    - Action delay is set to 0 milliseconds
1617122227342	geckodriver	INFO	Listening on 127.0.0.1:12051
1617122228354	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "--profile=-p -no-remote ChrisHemsworth" "-foreground" "-no-remote"
2021-03-30 20:38:09.652 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to open browser (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to open browser
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
	at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.openBrowser(OpenBrowserKeyword.groovy:81)
	at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.execute(OpenBrowserKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.openBrowser(WebUiBuiltInKeywords.groovy:63)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$openBrowser.call(Unknown Source)
	at open_browser.open_browser.openBrowser(open_browser.groovy:13)
	at open_browser.open_browser.invokeMethod(open_browser.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
	at New Test Case.run(New Test Case:21)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:398)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:389)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:368)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:360)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:255)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1617122216102.run(TempTestCase1617122216102.groovy:25)
Caused by: org.openqa.selenium.TimeoutException: No connection could be made because the target machine actively refused it. (os error 10061)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'MAEGL63P3', ip: '10.150.0.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: driver.version: CGeckoDriver
remote stacktrace: 
	at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
	at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
	at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
	at com.kms.katalon.selenium.driver.CFirefoxDriver.execute(CFirefoxDriver.java:27)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
	at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
	at com.kms.katalon.selenium.driver.CFirefoxDriver.<init>(CFirefoxDriver.java:21)
	at com.kms.katalon.core.webui.driver.firefox.CGeckoDriver.<init>(CGeckoDriver.java:12)
	at com.kms.katalon.core.webui.driver.firefox.CGeckoDriver.from(CGeckoDriver.java:17)
	at com.kms.katalon.core.webui.driver.DriverFactory.createNewFirefoxDriver(DriverFactory.java:678)
	at com.kms.katalon.core.webui.driver.DriverFactory.startNewBrowser(DriverFactory.java:349)
	at com.kms.katalon.core.webui.driver.DriverFactory.openWebDriver(DriverFactory.java:245)
	at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword$_openBrowser_closure1.doCall(OpenBrowserKeyword.groovy:74)
	at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword$_openBrowser_closure1.call(OpenBrowserKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.openBrowser(OpenBrowserKeyword.groovy:81)
	at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.execute(OpenBrowserKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.openBrowser(WebUiBuiltInKeywords.groovy:63)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$openBrowser.call(Unknown Source)
	at open_browser.open_browser.openBrowser(open_browser.groovy:13)
	at open_browser.open_browser.invokeMethod(open_browser.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
	at Script1617106143643.run(Script1617106143643.groovy:21)
	... 10 more
)

Awaiting for a solution guys. Thank you in advance.

@kazurayam, Can you please advise?

I do not know the way you mentioned above.

I made the following code and it worked.

import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.firefox.ProfilesIni

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

def WebDriver startFirefoxWithProfile(String profileName) {
		FirefoxProfile fp = new ProfilesIni().getProfile(profileName)
		FirefoxOptions options = new FirefoxOptions().setProfile(fp)
		// note: You HAVE TO choose Firefox in Katalon Studio GUI
		String geckoDriverPath = DriverFactory.getGeckoDriverPath()
		println geckoDriverPath
		System.setProperty('webdriver.gecko.driver', geckoDriverPath)
		WebDriver driver = new FirefoxDriver(options)
		assert driver != null
		return driver
}

String profile = 'kazurayam'
WebDriver firefoxDriver = startFirefoxWithProfile(profile)
DriverFactory.changeWebDriver(firefoxDriver)
WebUI.navigateToUrl("https://www.youtube.com/")

I am referring to configuration that we can made as shown in screenshot below:

Is there any means which we can configured here to launch execution with a specific firefox profile?

Sorry, I have no experience about it.

Nevermind…i have tried another way and i’ll explain.

I have created a global variable in the default profile, G_FFProfile = Chris Hemsworth and i have created a custom keyword :

 package firefox_profile
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.firefox.ProfilesIni
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.driver.WebUIDriverType
import internal.GlobalVariable as GlobalVariable

class startBrowserWithProfile {
	/**
	 * start specific firefox browser
	 */
	@keyword
	def void startBrowser() {

		WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
		switch(executedBrowser) {
			case WebUIDriverType.FIREFOX_DRIVER:
				ProfilesIni profile = new ProfilesIni()
				FirefoxProfile FF = profile.getProfile(GlobalVariable.G_FFProfile)
				FirefoxOptions options = new FirefoxOptions().setProfile(FF)
				System.setProperty('webdriver.gecko.driver', DriverFactory.getGeckoDriverPath())
				WebDriver driver = new FirefoxDriver(options)
				DriverFactory.changeWebDriver(driver)
				break
		}
	}
}

However, when i save the custom keyword, i got 2 errors as shown below:

Do you have any ideas? I tried also the Ctrl+Shift + O to import but still having the errors.

  1. @keyword -> @Keyword
  2. import statement is required
package my

import com.kms.katalon.core.annotation.Keyword

public class Sample {
	
	@Keyword
	static void greet(String name) {
		println "Hello, ${name}"
	}
}

I want to share the solution too:

  1. In Katalon Studio, create a global variable in the default profile ( G_FFProfile = Chris Hemsworth).

  2. Then create a custom keyword :

    package firefox_profile
    import org.openqa.selenium.WebDriver
    import org.openqa.selenium.firefox.FirefoxDriver
    import org.openqa.selenium.firefox.FirefoxOptions
    import org.openqa.selenium.firefox.FirefoxProfile
    import org.openqa.selenium.firefox.ProfilesIni
    import com.kms.katalon.core.webui.driver.DriverFactory
    import com.kms.katalon.core.webui.driver.WebUIDriverType
    import internal.GlobalVariable as GlobalVariable
    import com.kms.katalon.core.annotation.Keyword

    public class startBrowserWithProfile {
    /**
    * start specific firefox browser
    */
    @Keyword
    def void startBrowser() {

                 WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
                 switch(executedBrowser) {
                         case WebUIDriverType.FIREFOX_DRIVER:
                                 ProfilesIni profile = new ProfilesIni()
                                 FirefoxProfile FF = profile.getProfile(GlobalVariable.G_FFProfile)
                                 FirefoxOptions options = new FirefoxOptions().setProfile(FF)
                                 System.setProperty('webdriver.gecko.driver', DriverFactory.getGeckoDriverPath())
                                 WebDriver driver = new FirefoxDriver(options)
                                 DriverFactory.changeWebDriver(driver)
                                 break
                 }
         }}
    

In your script, call the custom keyword instead of the “open browser”

example:

CustomKeywords.‘firefox_profile.startBrowserWithProfile.startBrowser’()

@kazurayam Thank you :slight_smile: