Repository navigation
Description
Split from #5846
Context
I was talking to a colleague that does not use Robot recently. Their OOP brain asked about a pattern that someone used in their tests, and if they could use a builder pattern instead. The builder pattern would work great in that particular situation, but Robot does not support it.
The situation that we talked about was related to building complex data objects. In this case, we needed ~10 highly specialized keywords after each other to build up a single data object. With that object, we can then test stuff. These highly specialized keywords use keywords of their own. It's a lot of code that is hard to understand in the best case scenario. But Robot forced us to make it harder to read than necessary in our opinion. I can't share the code itself because it's company code. Our discussion was about good ways of approaching this test requirement.
After this discussion, we briefly talked about what something like this could look like in Robot Framework. This issue is the outcome of that discussion.
Keyword piping
Inspired by Functional Programming and the pipeline pattern.
This approach is similar to the following F# pattern:
foo() |> bar() |> baz()Which is technically equivalent to the following Python:
baz(bar(foo()))I'm using |> based some informal proposals to add this idea to Python. Those proposals are based on F#. The syntax comes from functional programming languages. This can, of course, use a different syntax. It probably has to due to the history of | in robot.
In your test
What this could look like when you're writing a test.
GUI tests
Get Element //button
|> Get Text == Hello world
|> Get Attribute aria-enabled == true
|> ClickNote: These are all existing Browser keywords. This will not work fully without changes to Browser though. For example, Get Text returns the text it found. Because of this, Get Attribute gets the text as its first argument.
API tests
Allows you to define stuff in the 'correct' order. It's one of the main reasons I don't advise people to use Robot for pure API testing.
${request} = POST https://example.com
|> Add Header To Request Authorization Bearer 923u49ujjidashuihdc8923yh98rhjd2
|> Add Header To Request Foo Bar
|> Add Body To Request lorum=ipsum dolor=sit
${response} = ${request} |> Send Request
# Do something with the responseThis gives us the reading order: Method -> URL -> Headers -> Body. Which feels much more natural to me compared to the current best Headers -> Body -> Method -> URL.
In your resource file
How you can create these keywords in a resource file.
Click to open partial code example
*** Keywords ***
Get Element
[Arguments] ${selector}
# Truncated
RETURN ${resolved_selector}
Get Text
[Arguments] ${selector} ${assertion_operator} ${assertion_expected}
# Truncated
RETURN ${selector}
Get Attribute
[Arguments] ${selector} ${assertion_operator} ${assertion_expected}
# Truncated
RETURN ${selector}
Click
[Arguments] ${selector}
# Truncated
RETURN ${selector}Couple of things of note:
- All keywords have
${selector}as their first argument. - All keywords return a selector
These 2 are very much related. In a pipeline, the returned value of a keyword is the first argument of the next.
In your library
How you can create these keywords in a library.
This approach uses no classes due to the functional programming influence. Let's use the GUI one above as an example. For the purposes of this example, I'll assume that Browser library fully supports this. I've used the explicit @libary and @keyword decorators for clarity.
Click to open partial code example
@keyword
def get_element(selector):
located_element = somehow_find_element_on_page(locator)
return located_element
@keyword
def get_text(selector, assertion_operator, assertion_expected):
# truncated
return selector
@keyword
def get_attribute(selector, assertion_operator, assertion_expected):
# truncated
return selector
@keyword
def click(selector):
# truncated
return selectorCouple of things of note:
- All keywords have
${selector}as their first argument. - All keywords return a selector
These 2 are very much related. In a pipeline, the returned value of a keyword is the first argument of the next.
Please disagree with me
What do you think of this proposal? This would be a major language change and would take a lot of time and effort to implement. So I think it's important to have a good discussion on this first.
Both the chaining and piping approaches have their pros and cons. I am personally leaning towards the chaining approach because I think it's easier to reason about and does not suffer as much from keyword naming conflicts. On the other hand, last week I leaned more towards the piping approach because it feels like it belongs more in the existing language and way of thinking.
Relevant existing proposals
- This could replace part of what makes Inline keyword call syntax #3187 useful
- A different approach to this is chaining. See Language propsal: Keyword chaining #5849 for details.
Please let me know if I missed any existing relevant proposals
Activity
pekkaklarck commentedon Nov 10, 2026
This is interesting syntax for passing arguments to keywords. I can see that it could simplify data in some cases, but I see also various problems:
fun1(fun2())than likefun1() |> fun2().fun1(fun2(), fun3()).Get TextandGet Attributein the example in the description would need to return the selector, not element text or attribute value, for this to work.Lakitna commentedon Nov 26, 2026
This would be possible like:
All the other points are indeed big downsides. I think most of them boil down to the fact that very few people are well-versed in functional programming. This syntax was born in that paradigm and even there it's not super popular.