-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GROUP
syntax for grouping keywords and control structures
#5257
Comments
I don't particularly like the proposed BLOCK syntax when used like this in the data. Creating separate keywords and using them to create the test would make it a lot easier to understand. I see some benefits in avoiding the need to create those keywords if they are used only once, but this usage alone wouldn't be worth adding this syntax. There are, however, two other usages where a block syntax would help:
|
I'll add this to the very initial RF 8.0 scope because #5119 is there already. I don't see any backwards compatibility problems with the change, so it could also be implemented earlier. I probably won't have time for it myself, but I'd be happy to help and review PRs. |
BLOCK
syntax for grouping related steps
Pinging in @asimell as this will have downstream effects on the Jenkins plugin |
I'm sorry but I really don't see how adding this BLOCK .. END syntax makes the overall test case more organized nor any more readable. How does this written syntax translate into the dynamic viewing of the log? Is it just more lines in the log? I see it as dramatically decreasing the readability. And if it adds no functionality, my first question, then what is the purpose? |
This will probably have an impact on the Jenkins plugin even though individual keywords are only parsed for logging purposes and their data is not actually stored for the plugin to use. @emanlove I don't necessarily see it increasing readability in the test case in itself. From Pekka's examples a simple |
As I commented earlier, I don't see this too important in normal data. Basically the proposed syntax would allow writing *** Test Cases ***
Example
BLOCK Do something
Action 1
Action 2
END
BLOCK Verify something succeeded
Verify 1
Verify 2
END instead of needing to create user keywords like *** Test Cases ***
Example
Do something
Verify something succeeded
*** Keywords ***
Do something
Action 1
Action 2
Verify something succeeded
Verify 1
Verify 2 In the log file the result would be the same except in the former case the test would contain BLOCKs with child keywords and in the latter case the test would contain keywords with child keywords. In most cases the latter approach would be better, and it would be obviously better if the created keywords could be reused. I can understand that someone is worried that this makes it easy to create bad tests, but that's possible already today by not using abstractions at all: *** Test Cases ***
Example
# Do something
Action 1
Action 2
# Verify something succeeded
Verify 1
Verify 2 It can be hard to motivate some users to change the above example to use proper user keywords because that requires some work. Changing it to use BLOCKs would be simpler and, as already noted, there's practically no difference when you look at the log file. That said, it would probably be good to have a linter rule for prohibiting BLOCKS at least on the test level, All in all, I see some benefits with the BLOCK syntax when used like above. These benefits probably wouldn't be worth the implementation effort and added complexity Robot itself and to the whole ecosystem. It is a good point that tools processing output.xml would need to take The main reason I believe this would be a good idea is that this syntax would provide a convenient programmatic API for creating structured tests and keywords. This has been requested multiple times especially in the RPA context. The most recent example #5119 that proposed making it possible to add user keywords to tests directly. The BLOCK structure would make it possible to implement exactly this behavior without making existing I pretty strongly believe making it possible to create structured tests/keywords programmatically is a useful feature. Support for simple named blocks is the simplest possible way I can think it could be implemented. We obviously could decide not so support BLOCK structures in data, but I think that would be really odd and wouldn't save much effort. Another possible benefit is that BLOCKs could possibly work as setup/teardown. Because currently setup/teardown must always be a keyword, that requires more work, but having the syntax available would make the effort smaller. |
When I first encountered this proposal, I was somewhat skeptical. However, upon further reflection, I see several potential benefits. For one, tests lacking abstractions (or not utilizing the BDD approach) can be pretty difficult to read. The use of Additionally, this approach may also be suitable for a programmatic API. I don’t have a strong opinion on this matter since I rarely need to use the robot's API. |
We decided to implement this and do it already in RF 7.2. The most important reasons are:
|
When discussing about this, we weren't sure what to call these things. The proposed
GROUP was our favorite, but we are open to other ideas still. |
Why not just curly brackets { ... }. Not much to write, but very clear what it means. |
Using curly braces in this context would be pretty inconsistent. It would be a natural choice if we'd use them with other control structures such as IF, but now that we've settled to syntax like |
I agree to your concern about inconsistency. |
Are you planning to support |
[Setup] BLOCK
Log Hello!
IF $expr Log Hello in IF!
END
I think also this should be a separate issue and should then introduce IF, FOR, WHILE and GROUP to be possible in setups and teardowns. Maybe even with line continuation?! [Setup] GROUP
... Log Hello!
... IF $expr Log Hello in IF!
... END |
Yeah, we should allow any construct to be used as setup/teardown except for things like BREAK and RETURN. That requires a separate issue and part of that issue is deciding the syntax. |
I am still contemplating whether "GROUP" is the most suitable name for this. It appears somewhat unusual when read alone and even more so when used frequently. For example, Python employs "ExceptionGroup," which is both clear and unambiguous. Suggestion: Could we consider "SECTION" or "CONTEXT" as alternatives? |
I'm really confused by why one must have this test level Block ... End syntax to have a programmatic API for creating structured tests and keywords? Can't the api just have methods for creating keywords? I see that whatever implementation needed for such a Block ... End syntax would be the same/similar for having a programmatic API. Thus maybe an argument of why not create both. But if everyone agrees that the majority of what the BLOCK ... END syntax can and really should be a keyword - we are a keyword framework after all - and that it does not increase readability - some of us are saying it greatly decrease it - then why add this keyword syntax at all??? |
@mikeleppane SECTIONS are in Robot Framework these @emanlove I generally agree, with your idea. But i realised that this can really be helpfull. *** Test Cases ***
Test Customer Management
Login To Customer Management admin 123
${Customer_Name} Get Customer Name 32
@{Invoices} Get Customer Invoices 32
&{addr} Get Customer Address 32
...
... # here some more keywords that uses these data.
... Grouping the fetching of customer data would make sense, to help readability. In this particular case, a keyword would be komplext, because it would have to return three values. *** Test Cases ***
Test Customer Management
Login To Customer Management admin 123
GROUP Fetch Customer Data
${Customer_Name} Get Customer Name 32
@{Invoices} Get Customer Invoices 32
&{addr} Get Customer Address 32
END
...
... # here some more keywords that uses these data.
... One other use-case and that is the one why i volunteered to implement it: And last ,but not least: |
@emanlove, #5119 proposal an API to create keywords programmatically. The problem was that #5119 proposed making it possible to add child keywords directly to The block/group construct is a lot simpler. It's simply a container with a name used only for documentation purposes. Executing it means executiing its children. |
I just realized that this will also be handy for REPL (DebugLibrary & RobotDebug). It is easier to understand as user, that you can create a Multi-Keyword action with the GROUP. |
BLOCK
syntax for grouping related stepsGROUP
syntax for grouping statements in Test|Task or Keywords.
One thing to decide is how to handle GROUP with templates. We first need to decide do we want to support them together at all. I believe we should, because GROUP is only used for grouping and we support templates also with FOR and IF. Assuming we want to support GROUP with templates, we need to decide how they should work if an iteration is skipped. Semantics related to that have just changed with normal templates, and nowadays a skipped iteration doesn't stop the whole test (#4426). Instead the test status is checked after all iterations have been run and is:
The following example illustrates how GROUP should work, in my opinion, under these semantics. Both groups should be executed with all of them. *** Settings ***
Test Template Run Keyword
*** Test Cases ***
PASS + SKIP + FAIL -> FAIL
GROUP
Log Pass 1
Skip Skip 1
Fail Fail 1
END
GROUP
Log Pass 2
Skip Skip 2
Fail Fail 2
END
PASS + SKIP -> PASS
GROUP
Log Pass 1
Skip Skip 1
END
GROUP
Log Pass 2
Skip Skip 2
END
SKIP + SKIP -> SKIP
GROUP
Skip Skip 1.1
Skip Skip 1.2
END
GROUP
Skip Skip 2.1
Skip Skip 2.2
END I believe most of this will work as above with the basic implementation. The only possible problems I see are with error reporting. I just noticed templated IF and FOR have that kind of problems as well and thus reopened the aforementioned #4426. I plan to fix those problems and that probably also affects also GROUP, but there's also a risk for a conflict. Let's discuss on Slack how we should proceed @Snooz82. I can also take care of the template support with GROUP if you want. |
What about BDDs? It was mentioned in the thread, but I see possible benefit if the GROUP could be aliased. Disclaimer: I don't use the BDDs as usually it looks too verbose to me. But with GROUP syntax it could change. GROUP -> alias with Given, When, Then:
It could of course be written with GROUP and proper comments, like Given/When.. or Arrange/Act/Assert:
Basically if the new syntax is introduced, I'm debating about recommended approach for users who use BDD style and if it makes sense to accomodate for them. |
In BDD you want to have as easy to understand tests/examples as possible. Although the |
Yep. As a developer who primarily uses the BDD (Behavior Driven Development) style, I find little value in using |
Functionality done and tested. Using with templates as well as documentation still missing. --------- Co-authored-by: Pekka Klärck <[email protected]>
This includes non-existing variables in name, empty GROUP and even missing END. We probably should validate syntax before even executing tests/keywords and report syntax errors early. That should then be done also with other control structures.
This ought to be now done. The main functionality was provided in PR #5275 by @Snooz82 and I. I did some fixes and cleanup afterwards and as the last task wrote documentation. I hope @Snooz82 can review the docs and after that we can close this issue. We still need to add |
I took another look at the docs and enhanced them a bit in the above commit. I believe the docs are good enough now and close this issue. If someone still wants to look them, you can find them here. |
GROUP
syntax for grouping statements in Test|Task or Keywords.GROUP
syntax for grouping keywords and control structures
The proposed BLOCK keyword would allow users to logically group related steps, improving test case organization, readability, and making the logs clearer and more structured by avoiding clutter at the top level.
Currently, to achieve logical grouping, users often create custom keywords to wrap related steps, leading to extra development and maintenance efforts. With BLOCK, users can group steps directly within test cases, minimizing the need for custom keywords.
Example:
The text was updated successfully, but these errors were encountered: