When defining a Test Case variable with Katalon Studio, how can I set his default value to be a Global Variable value?
So if you have GlobalVariable.test set to "something", the following code will print "something" to console:
def a = GlobalVariable.test
println a
Related
Is there a way how to check if value exists in R environment and if == TRUE, assign this existing value otherwise assign something else?
In other words, I have nothing in my R right now and I created this if else statement.
test <- if_else(exists("my_value"), my_value, "my value missing, assigning this string")
Result of
exists("my_value")
is:
exists("my_value")
[1] FALSE
But once I run whole code I get this
Error in if_else(exists("my_value"), my_value, "my value missing, assigning this string") :
object 'my_value' not found
if() {} else {} is more suitable for this case:
if(exists("my_value")){
test <- my_value } else {
test <- "my value missing, assigning this string"}
Using dplyr::if_else(condition, true, false, missing = NULL) won't work as it is checking the values for true and false are of the same length, class, type, hence the error.
I am guessing it could be done with if_else, if we manage to make values for true and false of the same class somehow.
I've previously used a list as parameter to take in a variable/optional number of arguments to a keyword, and this has worked perfectly:
Keyword Name
[Arguments] ${otherVariable} #{args}
....
My question is how do I set up a default value for this, if the user omits any more values?
i.e. something like
Keyword Name
[Arguments] ${otherVariable} #{args}=['0']
....
Check is ${args} empty, and if so - set the default value to it:
Keyword Name
[Arguments] ${otherVariable} #{args}
${args}= Run Keyword If not $args Create List 0
... ELSE Set Variable ${args} # varags were passed, leave it as is
This is analogous to this python code (RF is based on it, so a lot of approaches / recipes are the same/pretty close):
def keword(otherVariable, *args):
if not args: args = [0]
file.robot
Keyword1
log this is keyword1
${some_value} = Set Variable Hello, world!
[Return] ${some_value}
file2.robot
Some_name
Run keyword If 'True' == 'True Run Keyword and return Status Keyword1
I want to use this way. How do i access the return value in file2.robot
Above, 'Some_name' in file2.robot calls the 'Keyword1', the return value 'some_value' to be printed in 'Some_name' of file2.robot.
How can it be achieved in one-liner as stated above ?
You cannot use a "Run keyword..." command and both get a return value and a pass/fail value. However, if all you need is the return value, Run keyword if will return the result of the keyword that it runs.
For example:
*** Test Cases ***
Example
${the_value}= run keyword if 'True' == 'True' keyword 1
With the above, keyword 1 will only run if the expression evaluates to true. ${the_value} will be set to the result of keyword 1.
If you need both the status and the returned value, you can use Run keyword and return status to run the keyword, but you'll have to modify the keyword to set a suite or global variable that your test can get after the keyword returns.
I want to see if a variable exists - i.e. that I have created in.
if(exists(this.mydict))
{ //append my dict
}else
{
// initialize dict
}
Trouble is this fails on
Error in exists(this.mydict)
What am I doing wrong?
How can I extend the exists function to work with the following:
Any ideas how I would extend to this to looking at seeing whether a nested dictionary would also exist. I.e. for example: if(exists("mylists[[index]]['TSI']")), where the mylists object is a dictionary look up that also wants to contain a nested dictionary.
exists() function takes a character argument with the variable name:
if(exists("this.mydict")){
# you can use this.mydict here
}else{
# initialize this.mydict
# e.g. this.mydict <- "some value here"
}
I am trying to replace a specific string (hostname), inside a main string, with a variable value using the following command,
set newVar [string map {`hostname` $theHost} 'lsnrctl status listener_`hostname`']
However, instead of replacing hostname with the variable value, it replaces it using the variable identifier, i.e. "$theHost".
The newVar reads like this,
lsnrctl status listener_$theHost
I want it to be this,
lsnrctl status listener_theHostName
where "theHostName" is the value of the variable "$theHost".
How can I achieve this?
Build the replace list with the listcommand:
set newVar [string map [list `hostname` $theHost] "lsnrctl status listener_`hostname`"
or you could just use
set newVar "lsnrctl status listener_${theHost}"
' has no special meaning in Tcl, so your snippet will throw an error.
use " if you want command, variable and backslash substitution, { if you don't want this. (\ before the end of a line will be still substituted).
So using {`hostname` $theHost} will be substituted to `hostname` $theHost, not the thing you want. So better build a list with list, "`hostname` $theHost" might work if $theHost is a valid list element (does not contain spaces, etc), but will fail if the value of $theHost is foo bar (string map will throw an error)
Can't you just do
set newVar 'lsnrctl status listener_'
append newVar $theHost