From cef67c2544419cc3dd8ee11cafb5ed2f5230a750 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 3 Feb 2025 22:23:21 +0100 Subject: [PATCH 1/3] Update XML test suite and documentation for control structures --- .../TestSuite.robot | 375 ++++++++++-------- .../config.json | 16 +- website/docs/different_libraries/standard.mdx | 7 +- 3 files changed, 212 insertions(+), 186 deletions(-) rename code-examples/standard_library/{RF5_Syntax => control_structures}/TestSuite.robot (88%) rename code-examples/standard_library/{RF5_Syntax => control_structures}/config.json (96%) diff --git a/code-examples/standard_library/RF5_Syntax/TestSuite.robot b/code-examples/standard_library/control_structures/TestSuite.robot similarity index 88% rename from code-examples/standard_library/RF5_Syntax/TestSuite.robot rename to code-examples/standard_library/control_structures/TestSuite.robot index 3c56a52b..f0e62e57 100644 --- a/code-examples/standard_library/RF5_Syntax/TestSuite.robot +++ b/code-examples/standard_library/control_structures/TestSuite.robot @@ -1,176 +1,201 @@ -*** Settings *** -Documentation Robot Framework 5 syntax examples. -Library DateTime - -*** Test Cases *** -TRY / EXCEPT: Catch any exception - TRY - Fail - EXCEPT - Log EXCEPT with no arguments catches any exception. - END - -TRY / EXCEPT: Catch an exception by exact message - TRY - Fail Error message - EXCEPT Error message - Log Catches only "Error message" exceptions. - Log Enables error-specific exception handling. - END - -TRY / EXCEPT: Multiple EXCEPT statements - TRY - Fail Error message - EXCEPT Another error message - Log Catches only "Another error message" exceptions. - EXCEPT Error message - Log Catches the "Error message" exception. - END - -TRY / EXCEPT: Multiple messages in EXCEPT statement - TRY - Fail CCC - EXCEPT AAA BBB CCC - Log Catches any "AAA", "BBB", or "CCC" exception. - END - -TRY / EXCEPT: Catch a specific exception, or an unexpected exception - TRY - Fail Error message - EXCEPT Another message - Log Catches only "Another message" exceptions. - EXCEPT - Log Catches any exception. - Log Useful for handling unexpected exceptions. - END - -TRY / EXCEPT: Catch exceptions where the message starts with - TRY - Fail A long error message with lots of details - EXCEPT A long error message type=start - Log Matches the start of an error message. - END - -TRY / EXCEPT: Capture the error message - TRY - Fail Goodbye, world! - EXCEPT AS ${error_message} - Log ${error_message} # Goodbye, world! - END - -TRY / EXCEPT: Using ELSE when no exceptions occured - TRY - Log All good! - EXCEPT Error message - Log An error occured. - ELSE - Log No error occured. - END - -TRY / EXCEPT / FINALLY: Always execute code no matter if exceptions or not - TRY - Log All good! - FINALLY - Log FINALLY is always executed. - END - TRY - Fail Catastrophic failure! - EXCEPT - Log Catches any exception. - FINALLY - Log FINALLY is always executed. - END - -TRY / EXCEPT / ELSE / FINALLY: All together! - TRY - Fail Error message - EXCEPT - Log Executed if any exception occurs. - ELSE - Log Executed if no exceptions occur. - FINALLY - Log FINALLY is always executed. - END - -TRY / EXCEPT: Glob pattern matching - TRY - Fail My error: 99 occured - EXCEPT My error: * type=glob - Log Catches by glob pattern matching. - END - -TRY / EXCEPT: Regular expression matching - TRY - Fail error 99 occured - EXCEPT [Ee]rror \\d+ occured type=regexp - Log Catches by regular expression pattern matching. - END - -WHILE: Loop while the default limit (10000) is hit - TRY - WHILE True - Log Executed until the default loop limit (10000) is hit. - END - EXCEPT WHILE loop was aborted type=start - Log The loop did not finish within the limit. - END - -WHILE: Loop while the given limit is hit - TRY - WHILE True limit=10 - Log Executed until the given loop limit (10) is hit. - END - EXCEPT WHILE loop was aborted type=start - Log The loop did not finish within the limit. - END - -WHILE: Loop while condition evaluates to True - ${x}= Set Variable ${0} - WHILE ${x} < 3 - Log Executed as long as the condition is True. - ${x}= Evaluate ${x} + 1 - END - -WHILE: Skip a loop iteration with CONTINUE - ${x}= Set Variable ${0} - WHILE ${x} < 3 - ${x}= Evaluate ${x} + 1 - IF ${x} == 2 - CONTINUE # Skip this iteration. - END - Log x = ${x} # x = 1, x = 3 - END - -WHILE: Exit loop with BREAK - WHILE True - BREAK - Log This will not be logged. - END - -Inline IF: No need for IF / END construct - IF True Log Inline IF is nice! - -Inline IF / ELSE - IF False Log False ELSE Log True - -Inline IF / ELSE IF / ELSE: Not pretty but works! - IF False Log False ELSE IF False Log False ELSE Log True - -Inline IF: Conditional variable assignment - ${value}= IF True Get Current Date ELSE Get Time - -Demonstrate return - RETURN: Return a value from a keyword - RETURN: Return without a value - -*** Keywords *** -RETURN: Return a value from a keyword - IF True - RETURN It is true! - ELSE - RETURN It is not true! - END - -RETURN: Return without a value - IF True RETURN +*** Settings *** +Documentation Robot Framework control structure examples. +Library DateTime + +*** Test Cases *** +TRY / EXCEPT: Catch any exception + TRY + Fail + EXCEPT + Log EXCEPT with no arguments catches any exception. + END + +TRY / EXCEPT: Catch an exception by exact message + TRY + Fail Error message + EXCEPT Error message + Log Catches only "Error message" exceptions. + Log Enables error-specific exception handling. + END + +TRY / EXCEPT: Multiple EXCEPT statements + TRY + Fail Error message + EXCEPT Another error message + Log Catches only "Another error message" exceptions. + EXCEPT Error message + Log Catches the "Error message" exception. + END + +TRY / EXCEPT: Multiple messages in EXCEPT statement + TRY + Fail CCC + EXCEPT AAA BBB CCC + Log Catches any "AAA", "BBB", or "CCC" exception. + END + +TRY / EXCEPT: Catch a specific exception, or an unexpected exception + TRY + Fail Error message + EXCEPT Another message + Log Catches only "Another message" exceptions. + EXCEPT + Log Catches any exception. + Log Useful for handling unexpected exceptions. + END + +TRY / EXCEPT: Catch exceptions where the message starts with + TRY + Fail A long error message with lots of details + EXCEPT A long error message type=start + Log Matches the start of an error message. + END + +TRY / EXCEPT: Capture the error message + TRY + Fail Goodbye, world! + EXCEPT AS ${error_message} + Log ${error_message} # Goodbye, world! + END + +TRY / EXCEPT: Using ELSE when no exceptions occured + TRY + Log All good! + EXCEPT Error message + Log An error occured. + ELSE + Log No error occured. + END + +TRY / EXCEPT / FINALLY: Always execute code no matter if exceptions or not + TRY + Log All good! + FINALLY + Log FINALLY is always executed. + END + TRY + Fail Catastrophic failure! + EXCEPT + Log Catches any exception. + FINALLY + Log FINALLY is always executed. + END + +TRY / EXCEPT / ELSE / FINALLY: All together! + TRY + Fail Error message + EXCEPT + Log Executed if any exception occurs. + ELSE + Log Executed if no exceptions occur. + FINALLY + Log FINALLY is always executed. + END + +TRY / EXCEPT: Glob pattern matching + TRY + Fail My error: 99 occured + EXCEPT My error: * type=glob + Log Catches by glob pattern matching. + END + +TRY / EXCEPT: Regular expression matching + TRY + Fail error 99 occured + EXCEPT [Ee]rror \\d+ occured type=regexp + Log Catches by regular expression pattern matching. + END + +WHILE: Loop while the default limit (10000) is hit + TRY + WHILE True + Log Executed until the default loop limit (10000) is hit. + END + EXCEPT WHILE loop was aborted type=start + Log The loop did not finish within the limit. + END + +WHILE: Loop while the given limit is hit + TRY + WHILE True limit=10 + Log Executed until the given loop limit (10) is hit. + END + EXCEPT WHILE loop was aborted type=start + Log The loop did not finish within the limit. + END + +WHILE: Loop while condition evaluates to True + ${x}= Set Variable ${0} + WHILE ${x} < 3 + Log Executed as long as the condition is True. + ${x}= Evaluate ${x} + 1 + END + +WHILE: Skip a loop iteration with CONTINUE + ${x}= Set Variable ${0} + WHILE ${x} < 3 + ${x}= Evaluate ${x} + 1 + IF ${x} == 2 + CONTINUE # Skip this iteration. + END + Log x = ${x} # x = 1, x = 3 + END + +WHILE: Exit loop with BREAK + WHILE True + BREAK + Log This will not be logged. + END + +Inline IF: No need for IF / END construct + IF True Log Inline IF is nice! + +Inline IF / ELSE + IF False Log False ELSE Log True + +Inline IF / ELSE IF / ELSE: Not pretty but works! + IF False Log False ELSE IF False Log False ELSE Log True + +Inline IF: Conditional variable assignment + ${value}= IF True Get Current Date ELSE Get Time + +Demonstrate return + RETURN: Return a value from a keyword + RETURN: Return without a value + +GROUP: Grouping keywords + GROUP Group of keywords + Log This is a keyword in a group. + Log This is the second keyword in the group. + END + +GROUP: Grouping keywords without a name + GROUP + Log This is a keyword in a group without a name. + Log This is the second keyword in the group. + END + +GROUP: Template for a group + [Template] Log + GROUP names + Gerwin + Mikka + Ed + END + GROUP numbers + 1 + 2 + 3 + END + +*** Keywords *** +RETURN: Return a value from a keyword + IF True + RETURN It is true! + ELSE + RETURN It is not true! + END + +RETURN: Return without a value + IF True RETURN Log This will not be logged. \ No newline at end of file diff --git a/code-examples/standard_library/RF5_Syntax/config.json b/code-examples/standard_library/control_structures/config.json similarity index 96% rename from code-examples/standard_library/RF5_Syntax/config.json rename to code-examples/standard_library/control_structures/config.json index df9c783b..0b2063e9 100644 --- a/code-examples/standard_library/RF5_Syntax/config.json +++ b/code-examples/standard_library/control_structures/config.json @@ -1,9 +1,9 @@ -{ - "name": "Robot Framework 5 Syntax, TRY/EXCEPT, Inline IF/ELSE, WHILE Loops and more", - "description": "readme.md", - "files": [ - { - "fileName": "TestSuite.robot" - } - ] +{ + "name": "Robot Framework 5 Syntax, TRY/EXCEPT, Inline IF/ELSE, WHILE Loops and more", + "description": "readme.md", + "files": [ + { + "fileName": "TestSuite.robot" + } + ] } \ No newline at end of file diff --git a/website/docs/different_libraries/standard.mdx b/website/docs/different_libraries/standard.mdx index f6b4dff6..03b639f3 100644 --- a/website/docs/different_libraries/standard.mdx +++ b/website/docs/different_libraries/standard.mdx @@ -39,8 +39,9 @@ Library XML ### XML Library - + -### Robot Framework 5 Syntax Examples +### Robot Framework Control Structures Examples + + - From 60a5cabd1b2e05944df24a675f5a69be7027b883 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 3 Feb 2025 22:23:45 +0100 Subject: [PATCH 2/3] Update XML test suite to modify intA and add intC elements --- code-examples/xml/XML_Test_Suite.robot | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/code-examples/xml/XML_Test_Suite.robot b/code-examples/xml/XML_Test_Suite.robot index 139a810c..f0c8eb3c 100644 --- a/code-examples/xml/XML_Test_Suite.robot +++ b/code-examples/xml/XML_Test_Suite.robot @@ -6,17 +6,22 @@ Check Request ${root} Parse Xml source=${CURDIR}/multiply.xml Element Text Should Be source=${root} xpath=.//intA expected=5 ${text} Get Element Text source=${root} xpath=.//intA - Should Be Equal As Numbers ${text} 5 + Should Be Equal As Integers ${text} 5 Modify intA Element in Request ${root} Parse Xml source=${CURDIR}/multiply.xml - # What is the keyword to modify the text in an element? + Set Element Text source=${root} xpath=.//intA text=10 + ${text} Get Element Text source=${root} xpath=.//intA + Should Be Equal As Integers ${text} 10 Add an intC Element to Request ${root} Parse Xml source=${CURDIR}/multiply.xml - Add Element source=${root} xpath=.//Multiply element=5 + Add Element source=${root} xpath=.//Multiply element=3 + ${text} Get Element Text source=${root} xpath=.//intC + Should Be Equal As Integers ${text} 3 Save Xml ${root} path=updated_sample.xml Remove an Element from Request ${root} Parse Xml source=${CURDIR}/multiply.xml - # What is the keyword to remove an element? + Remove Element source=${root} xpath=.//intA + Element Should Not Exist source=${root} xpath=.//intA From 24fcfda6828a172de7251aab028b91f102a15a37 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 3 Feb 2025 22:25:17 +0100 Subject: [PATCH 3/3] Update config.json to clarify the name for control structures --- code-examples/standard_library/control_structures/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code-examples/standard_library/control_structures/config.json b/code-examples/standard_library/control_structures/config.json index 0b2063e9..ccbdc49a 100644 --- a/code-examples/standard_library/control_structures/config.json +++ b/code-examples/standard_library/control_structures/config.json @@ -1,5 +1,5 @@ { - "name": "Robot Framework 5 Syntax, TRY/EXCEPT, Inline IF/ELSE, WHILE Loops and more", + "name": "Robot Framework Control Structures, TRY/EXCEPT, Inline IF/ELSE, WHILE Loops and more", "description": "readme.md", "files": [ {