I use latest Robot Framework. I need to assign a value to my variable depending on value of an argument. That's how it would be in JavaScript:
ITEM_SELECTOR = RECENT_ITEM_SELECTOR + (
position === 'last' ? ':last-child' : ':nth-child' + '(' + position + ')'
)
This is how I try to write it in Robot Framework:
${ITEM_SELECTOR} = Run Keyword If ${position} == 'last' ${RECENT_ITEM_SELECTOR}:last-child
... ELSE ${RECENT_ITEM_SELECTOR}:nth-child(${position})
but this way ${RECENT_ITEM_SELECTOR}:nth-child(${position})
is considered a keyword, not assigned to ITEM_SELECTOR
.
Then I try to preprend it with No Operation
, but then my return value is considered its argument and I get Keyword 'BuiltIn.No Operation' expected 0 arguments, got 1.
How can I write it?
Since you are calling run keyword if, you have to give it a keyword to run. You can use set variable to make your code work:
${ITEM_SELECTOR} = Run Keyword If ${position} == 'last'
... Set variable ${RECENT_ITEM_SELECTOR}:last-child
... ELSE
... Set variable ${RECENT_ITEM_SELECTOR}:nth-child(${position})
However, you can also use set variable if for a slightly more compact and readable solution:
${ITEM_SELECTOR} = Set variable if ${position} == 'last'
... ${RECENT_ITEM_SELECTOR}:last-child
... ${RECENT_ITEM_SELECTOR}:nth-child(${position})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With