Set proxy and user agent with external libraries?

Hi, I’m in need to set up proxies and user agents for my test case.
I’ve read that that’s not possible by default from katalon, and seeing that I can import external libraries I was wondering if it will do the trick.

Thanks

Proxies can be configured under Window > Katalon Studio Preferences > Katalon > Proxy:

I’ve never messed with user agents, but it looks like it can be handled through desired capabilities:

Please have a look at the following comment:

Liam_B gave us the following code:

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.network.ProxyInformation
ProxyInformation proxyInfo = new ProxyInformation();
proxyInfo = RunConfiguration.getProxyInformation()
println proxyInfo.proxyServerType

RunConfiguration.getProxyInformation() will return the setup which Brandon_Hein described above.

1 Like

I cannot modify the proxyServerAddress and proxyServerPort parameters in the script of the test case?

i tried something like:

ProxyInformation proxyInfo = new ProxyInformation();
proxyInfo = RunConfiguration.getProxyInformation()
proxyInfo.proxyServerAddress = “100.100.100.100”

and a simple println after to see if there was a change.

After running it and going into settings to double check the changes i don’t see the proxy ip modified.

You can read the source code of com.kms.katalon.core.network.ProxyInformation here

Hi, thanks for the response, i’ve tried to run this befor the OpenBrowser command:

def proxy_ip = GlobalVariable.proxyip

def proxy_port = GlobalVariable.proxyport

ProxyInformation.setProxyServerAddress(proxy_ip)
ProxyInformation.setProxyServerPort(proxy_port)

But it gives me the following error:

01-30-2019 03:39:54 AM setProxyServerAddress(proxy_ip)

Elapsed time: 0,045s

setProxyServerAddress(proxy_ip) FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.network.ProxyInformation.setProxyServerAddress() is applicable for argument types: (java.lang.String) values: [100.100.100.100]
Possible solutions: setProxyServerAddress(java.lang.String), getProxyServerAddress()
at testing proxy.run(testing proxy:27)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1548815992298.run(TempTestCase1548815992298.groovy:22)

You did:

ProxyInformation.setProxyServerAddress(proxy_ip)

You are trying to invoke a static method named setProxyServerAddress of the class ProxyInformation. The method is simply not there. Therefore an Exception was thrown. Are you aware what you are doing? Do you differentiate ‘static method’ and ‘instance method’?

The following code will not cause Exception.

// instanciate a ProxyInformation 
ProxyInformation proxyInfo = new ProxyInformation()

def proxy_ip = GlobalVariable.proxyip
def proxy_port = GlobalVariable.proxyport
proxyInfo.setProxyServerAddress(proxy_ip)
proxyInfo.setProxyServerPort(proxy_port)

// use the proxyInfo variable for what ever
println proxyInfo

I realized that a minute ago and i ended up with the same code as yours:

def proxy_ip = GlobalVariable.proxyip

def proxy_port = GlobalVariable.proxyport

ProxyInformation proxyInfo = new ProxyInformation();

proxyInfo.setProxyServerAddress(proxy_ip)
proxyInfo.setProxyServerPort(proxy_port)

The problem is that the proxy that katalon uses doesn’t change, by visiting whatsmyip i see that the proxy i’ve put manually is used and not the one stored in the variables

EDIT: i just tried to use it in the Test Collection with no result:

@SetupTestCase(skipped = false) // Please change skipped to be false to activate this method.
def setupTestCase() {
def proxy_ip = GlobalVariable.proxyip

def proxy_port = GlobalVariable.proxyport

ProxyInformation proxyInfo = new ProxyInformation();

proxyInfo.setProxyServerAddress(proxy_ip)
proxyInfo.setProxyServerPort(proxy_port)

}

Katalon Studio does not allow you to change the Proxy setup by scripts.

If you want to use various setups of Proxy, you have 2 options:

  1. You to change the setup in the GUI. This must be done before you run your scripts.
  2. If you run KS in console mode, you can specify Proxy setups as command line arguments. See https://docs.katalon.com/katalon-studio/docs/console-mode-execution.html#katalon-command-line-options
1 Like

Thanks a lot for your help, i’ll try a workaround with the console mode

After implementing the test suite with other python scripts i got stuck and didn’t have it working.

The problem being that Katalon doesn’t pass the proxy user as a parameter to authenticate to the proxy server. I checked the logs and there’s no presence of that parameter, only proxy ip, port and password are passed to the test suide.

Do you ever encountered the problem yourself?

I can’t tell anything without enough information. Please have a look at the following post:

i’m sorry for not adding more details. This is a post where i’ve described the problem as detailed as possible:

can you help me with something, please?

can i modify to response or the body using Custom Capabilities?

@alalzabarga This topic is over 3 years old. Please post your question in a new topic so it will get more visibility.