Revision: 11d6cf18fba6
Branch:   default
Author:   Jussi Malinen <jussi.ao.mali...@gmail.com>
Date:     Thu Apr 25 05:19:22 2013
Log:      exit for loop if
http://code.google.com/p/robotframework/source/detail?r=11d6cf18fba6

Modified:
 /atest/robot/running/exit_for_loop.txt
 /atest/testdata/running/exit_for_loop.txt
 /src/robot/libraries/BuiltIn.py

=======================================
--- /atest/robot/running/exit_for_loop.txt      Fri Nov 30 03:00:31 2012
+++ /atest/robot/running/exit_for_loop.txt      Thu Apr 25 05:19:22 2013
@@ -46,6 +46,12 @@

 Exit For Loop In Keyword Teardown
     Test And All Keywords Should Have Passed
+
+Exit For Loop If True
+    Check Test Case    ${TESTNAME}
+
+Exit For Loop If False
+    Check Test Case    ${TESTNAME}

 *** Keyword ***
 Test And All Keywords Should Have Passed
=======================================
--- /atest/testdata/running/exit_for_loop.txt   Fri Nov 30 03:00:31 2012
+++ /atest/testdata/running/exit_for_loop.txt   Thu Apr 25 05:19:22 2013
@@ -67,6 +67,19 @@
 Exit For Loop In Keyword Teardown
     Exit For Loop In Keyword Teardown

+Exit For Loop If True
+    :FOR    ${var}    IN    one    two
+    \    Exit For Loop If     1 == 1
+    \    Fail    Should not be executed
+    Should BE Equal    ${var}    one
+
+Exit For Loop If False
+    [Documentation]   FAIL Should fail here
+    :FOR    ${var}    IN    one    two
+    \    Exit For Loop If     1 == 2
+    \    Fail    Should fail here
+
+
 *** Keyword ***
 With Loop
     :FOR    ${var}    IN    one    two
=======================================
--- /src/robot/libraries/BuiltIn.py     Mon Mar 18 03:41:31 2013
+++ /src/robot/libraries/BuiltIn.py     Thu Apr 25 05:19:22 2013
@@ -354,6 +354,9 @@
         |      | Run Keyword If | '${var}' == 'EXIT' | Exit For Loop |
         |      | Do Something   | ${var} |

+        Starting from Robot Framework 2.8 it is also possible to use
+        `Exit For Loop If`.
+
         New in Robot Framework 2.5.2.
         """
         # Error message is shown only if there is no enclosing for loop
@@ -361,6 +364,26 @@
         error.ROBOT_EXIT_FOR_LOOP = True
         raise error

+    def exit_for_loop_if(self, condition):
+        """Immediately stops executing the enclosing for loop if given
+        condition is true.
+
+ This keyword can be used directly in a for loop or in a keyword that
+        the for loop uses. In both cases the test execution continues after
+        the for loop. If executed outside of a for loop, the test fails.
+
+        To unconditionally exit for loop, see `Exit For Loop`.
+
+        Example:
+        | :FOR | ${var} | IN | @{SOME LIST} |
+        |      | Exit For Loop If | '${var}' == 'EXIT' |
+        |      | Do Something   | ${var} |
+
+        New in Robot Framework 2.8.
+        """
+        if self._is_true(condition):
+            self.exit_for_loop()
+
     def should_not_be_true(self, condition, msg=None):
         """Fails if the given condition is true.

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to