Using globalvariable when setting DesiredCapabilities

  1. Set Remote Driver DesiredCapabilities

  2. Added on Listener :

    @BeforeTestCase
    def beforeTestCase(TestCaseContext testCaseContext) {
    String testName = "Test Name: " + testCaseContext.getTestCaseId();
    GlobalVariable.testCaseName=testName;

     println("*********************************"+ GlobalVariable.testCaseName);
    

    }

  3. And I saw on log Variable set testCaseName

ShowLogVariable

4 ) Checked Moon

Deep Note :
I know I can use the following code but I don’t want to create a new driver or check if this driver started as remote or local, I want to set DesiredCapabilities for the remote driver directly with this parameter.

import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.webui.driver.DriverFactory
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
import java.net.URL
@BeforeTestCase
def beforeTestCase(TestCaseContext testCaseContext) {
   String testName = "Test Name: " + testCaseContext.getTestCaseId()

   Map<String, Object> moonOptions = new HashMap<>()
   moonOptions.put("name", testName)

   DesiredCapabilities capabilities = new DesiredCapabilities()
   capabilities.setCapability("browserName", "chrome")
   capabilities.setCapability("moon:options", moonOptions)

   URL remoteUrl = new URL("http://moon.<domain>:4444/wd/hub")
   RemoteWebDriver driver = new RemoteWebDriver(remoteUrl, capabilities)
   DriverFactory.changeWebDriver(driver)
}
1 Like

Hi @rdcybaspinar

Welcome to our community. Thank you for raising your concern.

Actually, can you please help explain more what you want, what feature request you expect looks like, what the impacts, …? Thanks to those, we can better investigate it.

Thank you!

1 Like

which parameter are you referring?

Thank you for your return.
I am taking my caseName on test case before test listener and throwing it into globalvariable.

After the test
Project Settings > Desired Capabilities > Do this in Remote
moon:options` {name : {$Globalvariable.testCaseName}} and I want to run the test with this name on Moon.

First of all, you can follow the errors I got here and the code parts I added from the post.

When I look for a solution, I see that I need to create a remote driver again and send capability parameters, which increases the fragility of the project and I often get errors in the runs. Is it possible to send this parameter more efficiently to the driver selected for the run?

key : moon:options
value : “{$GlobalVariable.testCaseName}”

which error you are referring?