As others have pointed out, embedded arguments cannot have default values, but it is possible to construct a keyword that matches both Schedule a meeting
and Schedule a meeting at 15.2.2025 14:00
. In the former case the variable matching the time will contain an empty string, and you can replace it separately with the default value. The example below demonstrates this. It’s similar to earlier examples, but it has a separate variable matching at
(including surrounding spaces) so that there’s no need to strip that away later.
*** Test Cases ***
Example
Schedule a meeting
Schedule a meeting at 15.2.2025 14:00
*** Keywords ***
Schedule a meeting${at:( at )?}${time}
IF not $time VAR ${time} now
Log to console \n>${time}<
Although the above works, I believe we can make it better in the future. The most annoying part is the need to have the separate variable matching at
. It makes it possible to define part of the keyword as a regular expression (that’s the :( at )?
part) which is convenient, but it would be better if regexps could be used directly without a variable. Due to backwards compatibility reasons we cannot make the keyword name a regular expression by default, and due to the added complexity I’m not sure would it be a good idea in general. We could, however, support special markers like /<regexp>/
to indicate that we are using a regexp:
*** Keywords ***
/Schedule a meeting( at )?${time}/
IF not $time VAR ${time} now
Log to console \n>${time}<
The other problem is the need to separately specify the default value. To avoid that, we needed to add support for default values with embedded arguments. Using the =<default>
syntax like with “normal” arguments ought to work fine and be consistent, and I guess the semantics could be that the default value is used if the argument would otherwise get an empty string as its value. This enhancement combined with the earlier enhancement would allow us to write:
*** Keywords ***
/Schedule a meeting( at )?${time=now}/
Log to console \n>${time}<
The former enhancement to allow the whole keyword name to be a regexp has been discussed few times earlier, but I don’t think there’s an issue about that yet and there also hasn’t been agreement about the syntax. If you think this would be a nice addition, please submit an issue so we can continue discussing about the syntax alternatives there. If we decided to go with the /<regex>/
syntax, implementation shouldn’t be overly complicated, but there are some backwards compatibility concerns that need to be taken into account.
I don’t remember there being discussions about default values with embedded arguments earlier, but I consider that a convenient enhancement. If you agree, please submit an issue about it as well! There shouldn’t be need to discuss about the syntax and implementation ought to be easy as well, but also this enhancement has some backwards compatibility concerns to be taken into account.