java 如何通过Java实现的关键字停止Robot Framework中的测试执行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11086413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 03:43:08  来源:igfitidea点击:

How to stop test execution in Robot Framework through keywords implemented with Java?

javakeywordrobotframework

提问by PavloSI

I have a keyword implemented with Java and if keyword fails i need to stop the whole test execution with message: "ERROR: example message".

我有一个用 Java 实现的关键字,如果关键字失败,我需要用消息停止整个测试执行:“错误:示例消息”。

采纳答案by janne

Take a look at the user guide under Reporting keyword status:

查看“报告关键字状态”下的用户指南:

You may throw any exception in the keyword method. The exception type will be used as prefix and you can add a message as well.

您可以在关键字方法中抛出任何异常。异常类型将用作前缀,您也可以添加一条消息。

回答by binithb

Raising exceptions is the officially recommended way.

引发异常是官方推荐的方式。

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#reporting-keyword-status

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#reporting-keyword-status

Java (as there in the comment to accepted answer)

Java(如已接受答案的评论中所示)

throw new AssertionError("ERROR: example message")

Python

Python

from exceptions import AssertionError
.
.
.
 def rftest(self):
   test_result = lib.runtest()
   if (0 != test_result ):
          raise AssertionError("Test Failed")

回答by Emil Salageanu

I see 2 solutions for this:

我看到了 2 个解决方案:

  • First solution:
  • 第一个解决方案:

In the test itself you can use

在测试本身中,您可以使用

Library         Dialogs
(....)
pause execution     myMessage

which will show a popup on the screen and pause the execution until the OK button is called. You can, for instance return a specific value from the java keyword in case of error and pause if that value is returned.

这将在屏幕上显示一个弹出窗口并暂停执行,直到调用 OK 按钮。例如,您可以在出现错误时从 java 关键字返回特定值,如果返回该值则暂停。

  • Second Solution
  • 第二种解决方案

I prefer this one: just connect a debugger to the java code which executes the keyword and stop when an exception occurs. It also allows to inspect the state of the JVM at that moment. This postshows how to do connect a remote debugger to the jvm which runs the robot keyword.

我更喜欢这个:只需将调试器连接到执行关键字并在发生异常时停止的 java 代码。它还允许检查当时 JVM 的状态。这篇文章展示了如何将远程调试器连接到运行机器人关键字的 jvm。