When I launch a build with parameters, I have this 'choice parameter' named "modeDebug"; the choice can be "true" or "false" (I did not choose the boolean type because I'll add more options some day). I need to use this parameter in my Java code but, for some reason, it's not retrieved.
I have this step in my Jenkinsfile in order to run the tests with parameters:
sh 'mvn -gs "$MAVEN_SETTINGS" -Dta.test.suite="{\\"filter\\":\\"'+newTestList+'\\",\\"param\\":{\\"env.devEnv\\":\\"${environnement}\\",\\"env.browser\\":\\"${browser}\\",\\"env.modeDebug\\":\\"${modeDebug}\\"}}"
-Denv.devEnv="${environnement}"
-Denv.browser="${browser}"
-Denv.modeDebug="${modeDebug}"
-Dlog4j.configurationFile="${log4j2ConfigurationFile}"
-Dstatus.update.events.url="${notificationURL}"
-Dsquash.ta.external.id="${externalJobId}" -Djobname="${JOB_NAME}"
-Dhostname="${HOSTNAME}" -Dsquash.ta.conf.file="taLinkConf.properties"
-Dta.tmcallback.reportbaseurl="${JENKINS_URL}job"
-Dta.tmcallback.jobexecutionid="${BUILD_NUMBER}"
-Dta.tmcallback.reportname=Squash_TA_HTML_Report
-Dta.delete.json.file=true squash-ta:"${operation}"'
Then, in my code, I call some of these Maven parameters...
protected String getScreenshotIfFail = java.lang.System.getProperty("env.modeDebug");
protected String devEnv = java.lang.System.getProperty("env.devEnv");
protected String browser = java.lang.System.getProperty("env.browser");
String devEnv and browser get populated but not ggetScreenshotIfFail!
Notes: In my Jenkinsfile, echo "${modeDebug}" outputs "true" or "false". This part is working.
In my code when the tests are run via Jenkins, System.out.println(getScreenshotIfFail); outputs "null".
In my IDE, I run the following command with success (getScreenshotIfFail is correctly populated):
-Denv.modeDebug=true -Denv.devEnv=qualif -Denv.browser=chrome -Dlog4j.configurationFile=src/log4j2.xml -Dta.test.suite=squash/**.ta squash-ta:run
Any idea?
Thanks!
RTM - String interpolation.
sh 'mvn ...'
^
that single quote should be double quote.
And of course you'll have to change many other quotes in your string.
Related
I have an abstract class that has a value of workingDirectory (variable)
I extended this in a new class (BaseClass). I want to override this by providing a value at runtime, and this is not happening. It is taking the default value.
I am using Gradle to run that file, it has test cases
The command in the code (BaseClass)
private static final String workingDirectory = System.getenv("infrastructurePath")==null?"./infrastructure":System.getenv("infrastructurePath");
The command I used to run from cmd
.\gradlew --info :testModule:testInfrastructure -DinfrastructurePath='./infrastructure-localtests'
But, it is taking ./infrastructure every time and not ./infrastructure-localtests when I try to pass the value from the command prompt. Where do I make the change?
I faced a similar situation long back. I was using IntelliJ for the same.
Try making the following changes:
In your base class, change the name of your workingDirectory variable. It should not be the same as you have in the abstract class.
Use the new variable name everywhere.
Use System.getproperty("name of the path / or path variable");
Do not use System.getenv() with a ternary operator. It didn't work for me.
Now, go to your build.gradle.
As you told you are running the test cases. you would be having a task created in tasks.register('YourTestName', Test)
Inside that, add a new line of
systemProperty "YourPath", System.getProperty("YourPath", "./TheDefaultPathIfNoConditionMatches");
Now, at run time, if you simply run the tests, the control will go to the default path. If you want it to go to a new path, add an -D argument like this
-DinfrastructurePath="./WhateverPath"
This should work for you. Thanks.
I have a Gradle build script that uses the Application plugin, and I want to pass as JVM argument a string that contains the $ character, but I can't because it always is converted to the \$ sequence of characters...
Here is my configuration:
application {
mainClass = 'example.Main'
application.applicationDefaultJvmArgs = ['-javaagent:$APP_HOME/lib/agent.jar']
}
But then in the start script I get:
DEFAULT_JVM_OPTS='"-javaagent:\$APP_HOME/lib/agent.jar"'
And because of that \ it doesn't work, I need the value to be -javaagent:$APP_HOME/lib/agent.jar. All ways I tried get the same result (using interpolation, passing the $ as \u0024, etc.).
I've found a workaround in this answer for a related question. The code in question is the following:
startScripts {
doLast {
unixScript.text = unixScript.text.replace('\\$APP_HOME', '\$APP_HOME')
//do something like this for Windows scripts if needed too
}
}
I'm trying to execute bash script using karate. I'm able to execute the script from karate-config.js and also from .feature file. I'm also able to pass the arguments to the script.
The problem is, that if the script fails (exits with something else than 0) the test execution continues and finishes as succesfull.
I found out that when the script echo-es something then i can access it as a result of the script so I could possibly echo the exit value and do assertion on it (in some re-usable feature), but this seems like a workaround rather than a valid clean solution. Is there some clean way of accessing the exit code without echo-ing it? Am I missing on something?
script
#!/bin/bash
#possible solution
#echo 3
exit 3;
karate-config.js
var result = karate.exec('script.sh arg1')
feture file
def result = karate.exec('script.sh arg1')
Great timing. We very recently did some work for CLI testing which I am sure you can use effectively. Here is a thread on Twitter: https://twitter.com/maxandersen/status/1276431309276151814
And we have just released version 0.9.6.RC4 and new we have a new karate.fork() option that returns an instance of Command on which you can call exitCode
Here's an example:
* def proc = karate.fork('script.sh arg1')
* proc.waitSync()
* match proc.exitCode == 0
You can get more ideas here: https://github.com/intuit/karate/issues/1191#issuecomment-650087023
Note that the argument to karate.fork() can take multiple forms. If you are using karate.exec() (which will block until the process completes) the same arguments work.
string - full command line as seen above
string array - e.g. ['script.sh', 'arg1']
json where the keys can be
line - string (OR)
args - string array
env - optional environment properties (as JSON)
redirectErrorStream - boolean, true by default which means Sys.err appears in Sys.out
workingDir - working directory
useShell - default false, auto-prepend cmd /c or sh -c depending on OS
And since karate.fork() is async, you need to call waitSync() if needed as in the example above.
Do provide feedback and we can tweak further if needed.
EDIT: here's a very advanced example that shows how to listen to the process output / log, collect the log, and conditionally exit: fork-listener.feature
Another answer which can be a useful reference: Conditional match based on OS
And here's how to use cURL for advanced HTTP tests ! https://stackoverflow.com/a/73230200/143475
In case you need to do a lot of local file manipulation, you can use the karate.toJavaFile() utility so you can convert a relative path or a "prefixed" path to an absolute path.
* def file = karate.toJavaFile('classpath:some/file.txt')
* def path = file.getPath()
Hello I am trying to pass arguments to my ImageJ PlugIn. However it seems no matter what I pass, argument string will be considered as empty by the program. I couldn't find any documentation on the internet about THAT issue.
My Java plugIn looks like this, and compiles fine.
import ij.plugin.PlugIn;
public class Test implements PlugIn {
public void run(String args) {
IJ.log("Starting plugin Test");
IJ.log("args: ." + args + ".");
}
}
I compile, make a .jar file and put it into the ImageJ plugins folder.
I can call it with the ImageJ userInterface (Plugin>Segmentation>Test) and the macro recorder will put the command used:
run("Test");
Then my code is executed, the log window pops-up as expected:
Starting plugin Test
args: ..
I can manually run the same command in a .ijm file, and get the same result.
However, when I run the following macro command:
run("Test", "my_string");
I get the same results in the log window:
Starting plugin Test
args: .. // <- I would like to get "my_string" passed there
Where it should have displayed (at least what I expect it to do)
Starting plugin Test
args: .my_string.
So my question is: how can I pass parameters to PlugIn and especially how to access them?
Many thanks
EDIT
Hey I found a way to bypass that:
Using the Macro.getOptions() : this method will retrieve the string passed in argument to the plugin.
However, I still can't find a way to pass more than 1 string argument. I tried overloading the PlugIn.run() method but it doesn't work at all.
My quick fix is to put all my arguments in 1 string, and separating them by a space. Then I split this string:
String [] arguments = Macro.getOptions().split(" ");
I don't see a more convenient way to get around that. I can't believe how stupid this situation is.
Please, if you have a better solution, feel free to share! Thanks
You are confusing the run(String arg) method in ij.plugin.Plugin with the ImageJ macro command run("command"\[, "options"\]), which calls IJ.run(String command, String options).
In the documentation for ij.plugin.Plugin#run(String arg), it says:
This method is called when the plugin is loaded. 'arg', which may be blank, is the argument specified for this plugin in IJ_Props.txt.
So, arg is an optional argument that you can use in IJ_Props.txt or in the plugins.config file of your plugin to assign different menu commands to different functions of your plugin (see also the excellent documentation on the Fiji wiki).
To make use of the options parameter when running your plugin from macro code, you should use a GenericDialog to get the options, or (as you apparently learned the hard way) use the helper function Macro.getOptions().
I saw the fallowing command for starting Selenium:
java -Xmx256m -Dauto=1 -jar selenium-server-standalone-2.25.0.jar -log /home/test/selenium.log -trustAllSSLCertificates
I googled to find what -Dauto=1 means but failed.
I'm pretty sure auto is no valid parameter in a current version of Selenium server. It might have been in the past or it was just used by some custom implementation.
java -jar selenium-server-standalone-2.25.0.jar -h
will list you all available parameters for Selenium, which you can set by adding
-D<variable>=<value>
to your start command.
-D is an important switch that allows you to set environment properties.
-Dproperty=value
Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes:
java -D<propertyName>=<propertyValue>
You can call the following from anywhere in the code to read it.
String value = System.getProperty("propertyName");
or
String value = System.getProperty("propertyName", "defaultValue");