Reputation: 21
I've got a Robot Framework test case that I'm running where elements are fed into the case through a CSV file. Some of those elements open into a new browser tab, some of them do not. I've got some logic written up to handle those scenarios, and it was running just fine until recently. I tried to add some more defined logic around the scenarios. Now, when I run it, I get an error that says: Keyword 'BuiltIn.Run Keyword If' expected at least 2 arguments, got 0.
I've gone round and round with this and can't find out where my issue is. Here is my code with the offending keyword, please let me know what I"m doing wrong. Thanks so much!
Student Tab Scraper
[Arguments] ${csv_file}
${locator_list}= Read Locators From File ${csv_file}
FOR ${locator} IN @{locator_list}
Wait For And Click Element ${locator}
${handles}= Get Window Handles
${num_handles}= Get Length ${handles}
${opened_in_new_tab}= Run Keyword If ${num_handles} > 1 Set Variable ${True} ${False}
Run Keywords
... Run Keyword If '${opened_in_new_tab}' == 'True'
... Log To Console Opening link in new tab
... Select Window ${handles}[1]
... Close Window
... Select Window ${handles}[0]
... ELSE
... Log To Console Opening link in same tab
... Wait For And Click Element ${iunderstand}
END
END
Upvotes: 0
Views: 193
Reputation: 20077
You have a syntax mistake in here:
${opened_in_new_tab}= Run Keyword If ${num_handles} > 1 Set Variable ${True} ${False}
A couple, in fact; you probably meant to set the variable to True when the condition is met, False otherwise.
The first mistake is you didn't use ELSE
to delimit the second block - it should be present if you want to have "condition not met" block.
The other is - even if it was present, there is no keyword to be executed, just the boolean False passed. When the framework runs it, it sees "when the condition is met run Set Variable ${True}
", but when not - "just False". What to do with it? It's also not a keyword, just a value, how to run a value?
Thus, syntax mistake.
The fixed version looks like this:
${opened_in_new_tab}= Run Keyword If ${num_handles} > 1 Set Variable ${True} ELSE Set Variable ${False}
For precisely this case - just setting a variable, there is a better keyword to be used, Set Variable If
, and it doesn't even use the ELSE keyword for the fallback block.
With it, it looks like this:
${opened_in_new_tab}= Set Variable If ${num_handles} > 1 ${True} ${False}
And semi-unrelated, Run Keyword If
is being deprecated, you might want to swith using IF
in its place (it's a drop-in replacement in this case).
Upvotes: 0