平常在使用 Robot Framework 時,通常會搭配 RIDE 來撰寫,整體而言算是個有幫助的 IDE 功具。有時侯在開發 UAT 時,會希望一但有錯誤就馬上停止執行,這樣可以馬上就定位到有問題的地方(keyword)。

在 RIDE 中有一個 Pause On Failure 的功能,如字面所述,就是一旦有失敗,它就會進入暫停的狀態,但這個功能最大的問題就是:‘Pause On Failure’ should ignore the keyword failure when using ‘Wait Until Keyword Succeeds’ 。
細節可以參考:https://github.com/robotframework/ride/issues/1259

像我們的 UAT 當中,有一個叫 Wait Property 的 keyword,會等待某個屬性值變成我們期望的值,但因為它裡頭是用 Wait Until Keyword Succeeds 實作,因此一但進入 等待 狀態時,就會變成 Pause 了。因此,我幫 RIDE 進行了一個小手術,讓它在 Wait Until Keyword Succeeds 之後會暫時 ignore Failure,讓 Wait Property 可以順利執行。

關鍵點在 TestRunnerAgent.py 裡頭的 start_keyword 及 end_keyword,可參考下面的 diff:

diff –git a/src/robotide/contrib/testrunner/TestRunnerAgent.py b/src/robotide/contrib/testrunner/TestRunnerAgent.py
index 1d1b0f7..eee9806 100644
— a/src/robotide/contrib/testrunner/TestRunnerAgent.py
+++ b/src/robotide/contrib/testrunner/TestRunnerAgent.py
@@ -112,6 +112,8 @@ class TestRunnerAgent:
         self._send_pid()
         self._create_debugger((len(args)>=2) and (args[1] == ‘True’))
         self._create_kill_server()
+        self.ignorePausedOnFail = False
+        self.nestedLevel = 0

     def _create_debugger(self, pause_on_failure):
         self._debugger = RobotDebugger(pause_on_failure)
@@ -143,6 +145,13 @@ class TestRunnerAgent:
         self._send_socket(“end_suite”, name, attrs)

     def start_keyword(self, name, attrs):
+        self.nestedLevel += 1
+        if attrs[‘kwname’] == ‘Wait Until Keyword Succeeds’:
+             self.ignorePausedOnFail = True
+        if self.nestedLevel <= 2:
+            print “[KEYWORD]” + ” “*self.nestedLevel + attrs[‘kwname’]
+        sys.stdout.flush()
+
         self._send_socket(“start_keyword”, name, attrs)
         if self._debugger.is_breakpoint(name, attrs):
             self._debugger.pause()
@@ -154,8 +163,14 @@ class TestRunnerAgent:
             self._send_socket(‘continue’)

     def end_keyword(self, name, attrs):
+        self.nestedLevel -= 1
+        if self.ignorePausedOnFail == True:
+            attrs[‘status’] = ‘PASS’
         self._send_socket(“end_keyword”, name, attrs)
         self._debugger.end_keyword(attrs[‘status’]==’PASS’)
+        if attrs[‘kwname’] == ‘Wait Until Keyword Succeeds’:
+             self.ignorePausedOnFail = False
+

Facebook Comments Box