Karate Runner -> karate jar : Command line args settings issue

Viewed 991

I am using Visual Studio code and Karate Runner plugin is installed. Using karate-config.js with standalone jar (karate.jar). I have tried to configure in karate runner settings in VS code for Karate Runner -> karate jar : Command line args as "java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main" but it throws an exception like

Executing task: java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main "d:\GitHub\KarateTestFramework\test\features\script\all_users.feature:9" <

Error: Could not find or load main class .config.dir=test.resources. The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main "d:\GitHub\KarateTestFramework\test\features\script\all_users.feature:9"" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Also, I have tried full path for -Dkarate.config.dir=D:/GitHub/KarateTestFramework/test/resources but didn't work either.

Please guide me to resolve this issue.

3 Answers

@ChandramohanRamabadran, I tried to replicate the issue on my system. I believe it's not a bug!

It's happening because your VisualStudio is using PowerShell instead of CMD. I believe you might have missed the step to change the default shell of VisualStudio after installing Karate. Try updating the default shell from PowerShell to CMD; then you should be good.

However, if you still want to use PowerShell, then update the command

java -Dkarate.config.dir=test/resources/ -cp karate.jar com.intuit.karate.Main

to

java `-Dkarate.config.dir`=test/resources/ -cp karate.jar com.intuit.karate.Main

More context over the issue: PowerShell has a more standard rule to parse system-properties parameters which are different from CMD. In a PowerShell command, the parameter names always begin with a hyphen. The hyphen tells PowerShell that the item in the command is a parameter name.

Here, we are passing the parameter as -Dkarate.config.dir, PowerShell sights the parameter name-tag as -Dkarate and not -Dkarate.config.dir; hence the error.

This is a bug. Thanks for reporting it: https://github.com/intuit/karate/issues/1330

For now please find a workaround. Karate will look for karate-config.js in the current directory or the classpath. So if you change the command to something like this (please try variations) it should work

-cp 'karate.jar;test/resources/'

I have changed preferred terminal shell from Powershell to command as default for VS code and followed the below listed steps

  1. Press Ctrl + Shift + P to show all commands.
  2. Type shell in the displayed text box to filter the list.
  3. Select Terminal: Select Default Shell .
  4. You will be prompted to Select your preferred terminal shell, you can change this later in your settings or follow the same process as we do now.

I have changed the karate runner->karate jar:Command Line Args settings as java -Dkarate.config.dir=resources/ -cp karate.jar com.intuit.karate.Main

Now its working fine.

Related