How to ignore None value from list? - robotframework

I am testing BE and when getting json path for some values I get None. I want to ignore them.
Remove values from list did not work for me.
Remove values from list ${list} None/${empty}/null
Are there any other ways to ignore None value?
I also tried to get from json values without null but did not work either. Showed an error
JsonPathLexerError: Error on line 1, col 41: Unexpected character: ?
${TARGET_TEXT}= Get Json Path ${RESPONSE} $.pipelines..filter.children..targetText[?!#.None]

You're close. You need to remove ${NONE} rather than ${EMPTY}
Remove values from list ${TARGET_TEXT} ${NONE}

Try this :
${list} = Evaluate [i for i in ${list} if i]

Related

How to put a variable value with semicolons and forwardslashes inside a list and get read by it

Here's my list
#{referentiel} N1(exemple)/N2(exemple) N2(exemple)/exemple
where i use it
Visca barca
[Arguments] ${index}
Click Element Using Javascript //div[#id='mat-select-value-5']
Click element of long page //span[#class='mat-option-text'][contains(.,'#{referentiel}[${index}]')]
And my testcase
we are the best
Visca barca 1
Error :
Value of variable '#{referentiel}[${index}]' is not list or list-like.
The issue you are describing here has nothing to do with the semicolons or slashes. The issue is actually that you are attempting to return the list item with wrong decorator.
To get a single item from a list you should use $ instead of #. When you use # Robot will attempt to return you a list which it cannot since the item on ${index} is a string.
See below:
#{referentiel} # == ['N1(exemple)/N2(exemple)', 'N2(exemple)/exemple']
or
${referentiel[0]} # == N1(exemple)/N2(exemple)

Can't Assign Value of Excel cell To variable in Robot Framework [duplicate]

I'm writing a test case in robot framework. I'm getting the response in below json string:
{"responseTimeStamp":"1970-01-01T05:30:00",
"statusCode":"200",
"statusMsg":"200",
"_object":{"id":"TS82",
"name":"newgroup",
"desc":"ttesteste",
"parentGroups":[],
"childGroups":[],
"devices":null,
"mos":null,
"groupConfigRules" {
"version":null,
"ruleContents":null
},
"applications":null,"type":0
}
}
From that I want to take "_object" using:
${reqresstr} = ${response['_object']}
... but am getting the error "No keyword with name '=' found" error
If I try the following:
${reqresstr}= ${response['_object']}
... I'm getting the error "Keyword name cannot be empty." I tried removing the '=' but still get the same error.
How can I extract '_object' from that json string?
When using the "=" for variable assignment with the space-separated format, you must make sure you have no more than a single space before the "=". Your first example shows that you've got more than one space on either side of the "=". You must have only a single space before the = and two or more after, or robot will think the spaces are a separator between a keyword and argument.
For the "keyword must not be empty" error, the first cell after a variable name must be a keyword. Unlike traditional programming languages, you cannot directly assign a string to a variable.
To set a variable to a string you need to use the Set Variable keyword (or one of the variations such as Set Test Variable). For example:
${reqresstr}= Set variable ${response['_object']}
${reqresstr}= '${response["_object"]}'
wrap it inside quotes and two spaces after =
There is a syntax error in your command. Make sure there is a space between ${reqresstr} and =.
Using your example above:
${reqresstr} = ${response['_object']}

TypeError: Expected argument 1 to be a list or list-like, got string instead. robot frame work

When I tried to add the string value to the list in the robot frame work. I am getting below error. Can anyone help me here?
Error:Expected argument 1 to be a list or list-like, got string instead.
${a}= 'H'
Append_to_list ${Elementlist2} ${a}
That error is telling you that ${Elementlist2} is a string, not a list. It must be a list if you are using Append to list

How to find open and closing braces present in a string (a list converted into string)?

My requirement is to check whether the input is list or not using robot framework.
I tried using type(${temp}).name with evaluate function, which works in case of list and fails for string type.
Below is the error message -
Evaluating expression 'type(testdata).name' failed: SyntaxError: invalid token (, line 1)
Tried to use regex, but no luck.:(
Code :-
testRegEx
${match} Run Keyword Should Match Regexp ["swerwv","sfsdfdsf","edsfdf"] \[\s\S\]
Log To Console ${match}
output:-
FAIL : '["swerwv","sfsdfdsf","edsfdf"]' does not match '[\s\S]'
I'm new to robotframework. Any help would be appreciated.
My requirement is to check whether the input is list or not using robot framework.
You can use robot's special syntax for evaluate and the various keywords which accept expressions, where you omit the brackets in the variable reference to pass the actual variable to the expression (versus passing the value of the variable).
Example:
*** Variables ***
#{a_list} one two three
*** Test Cases ***
Test that variable is a list
run keyword unless type(a_list) == list
... Fail not a list
This feature is mentioned in the Evaluating expressions section of the built-in library.

Remove all objects from R environment whose names DO NOT contain a specific string

I'd like to remove all objects from my RStudio environment where the object names DO NOT contain a given string.
rm(list=ls(pattern!="may19"))
Yet this gives me an error message
Error in as.environment(pos) : no item called "pattern != "may19"" on
the search list
Is there another way I can approach this? Thanks
You can do:
rm(list= names(Filter(function(x) !any(names(x) == "may19"),
mget(ls(),envir = .GlobalEnv))))
Or simply(as suggested by #nicola):
rm(list=grep("may19",ls(),value=TRUE,invert=TRUE))

Resources