简体   繁体   English

在 Robot Framework 中运行一段时间的测试用例

[英]Running test case for a duration of time in Robot Framework

I wanted to run robot test for a duration of time, say for 1hr.我想在一段时间内运行机器人测试,比如 1 小时。 No matter if the execution of all test cases in a test suite is completed.不管一个测试套件中所有测试用例的执行是否完成。 It should repeat the test cases until the given time reached.它应该重复测试用例,直到达到给定的时间。

I tried to use --prerunmodifier and tried to write my own module, I used robot.api module robot.running.context , and override the present method end_suite() .我尝试使用--prerunmodifier并尝试编写自己的模块,我使用了 robots.api 模块robots.running.context ,并覆盖了当前方法end_suite() But not successful!但没有成功! :( :(

As per the Robot framework user guide the robot framework test suite will be executed for a maximum time of 120 minutes ie 2hrs. 根据《机器人框架用户指南》,机器人框架测试套件的执行时间最长为120分钟,即2小时。 Not we can overwrite this timeout by explicitly mentioning the test execution time in the test files Settings table as below 我们不能通过在测试文件“设置”表中明确提及测试执行时间来覆盖此超时,如下所示

***Setting***
Test Timeout  60 minutes

Further you are most welcome to set a test cases specific timeout using [Timeout] option as below 此外,我们非常欢迎您使用[Timeout]选项设置测试用例特定的超时,如下所示

***Test Cases***
Sample Test Case
  [Timeout]  5 minutes
  Do some testing
  Validate some results

Feel free to try and ask further questions. 随意尝试并提出其他问题。

Try with ' Repeat Keyword ' keyword. 尝试使用“ 重复关键字 ”关键字。 It takes as argument for how long it should repeat given keyword. 它作为参数应重复给定关键字多长时间。 But in this case all your test cases should go to one keyword. 但是在这种情况下,您所有的测试用例都应该使用一个关键字。 Use 'Run Keyword And Ignore Error' inside of it so you ignore errors. 在其中使用“运行关键字并忽略错误”,以便您忽略错误。

Eg: 例如:

Repeat Keyword   2h    Keyword With All Test Cases

Second option would be writing a Listener - has similar functionality as prerun modifier but is executed during tests not before. 第二种选择是编写一个监听器 -具有与prerun修饰符相似的功能,但是在测试之前执行。

I would approach this with an outside runner script using two threads. 我将使用两个线程使用外部跑步者脚本来解决这个问题。 Sample algorithm with no implementation: 没有实现的示例算法:

Start a time counter (just the current epoch time); 启动一个计时器(只是当前的纪元时间); the first (the main) thread is a controlling one. 第一个(主)线程是控制线程。 It sleeps for 1s, and on run checks and branches: 它休眠1秒钟,然后运行检查和分支:

  • the counter has not reached the threshold (eg current epoch - starting < limit) - check is the other thread running (has not finished execution): 计数器尚未达到阈值(例如,当前纪元-开始<限制)-检查其他线程是否正在运行(尚未完成执行):
    -- yes: pass -是的: pass

    -- no: that "other" thread is the execution of the robot suites. -否:那个“其他”线程是机器人套件的​​执行。 It is not running - spawn a thread that will run the suites; 它没有运行-产生一个将运行套件的线程; before that - copy the logs from the previous execution - if you care about them (in general I guess you would, to analyze the run's result; except if you're doing longevity perf test, and want to monitor just the SUT). 在此之前-如果您关心它们,则复制以前执行中的日志(通常,我想您会分析运行结果;除非您正在进行寿命性能测试,并且只想监视SUT)。 Thus you will re-start the suites after they finished. 这样,您将在套件完成后重新启动它们。

  • the counter has exceeded the threshold - stop the run in the other thread. 计数器已超过阈值-停止在另一个线程中运行。 For that the INT or TERM signal - this will allow the framework to create the log files. 对于INT或TERM信号 -这将允许框架创建日志文件。 If you use KILL, that'll abruptly end the current execution - if you don't care about the logs that's an option. 如果您使用KILL,则会突然终止当前执行-如果您不关心该选项是什么日志。 But you risk leaving your SUT in polluted state - the case that was running may have changed its configuration, and will not have the chance to clear up after itself. 但是您冒着使SUT处于污染状态的风险-正在运行的机箱可能已更改其配置,并且将无法自行清除。

I would advise on starting the execution to specify not to generate log and report html files from the intermediate runs (the --log none --report none CLI options) - their generation will take execution time, during which your cases will not be "spinning". 我建议开始执行以指定从中间运行中生成日志和报告html文件( --log none --report none CLI选项),它们的生成将花费执行时间,在此期间,您的案例不会为“旋转”。 After the run is done you can generate them from the intermediate output.xml files you've copied before. 运行完成后,您可以从之前复制的中间output.xml文件中生成它们。

If you are keen on this approach, and want to use python for the controlling script/system, I'd suggest looking at the source of pabot - it's that (threaded control and runs, but no timebound, your ask) on steroids. 如果您热衷于此方法,并且想将python用于控制脚本/系统,我建议您查看一下pabot来源 -它是对类固醇的(线程控制和运行,但没有时间限制)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用关键字跳过机器人框架中的测试用例 - How to skip test case in Robot framework using keyword 如何在Robot Framework中将一个测试用例的结果传递给另一个测试用例 - How to pass the result of one test case to another test case in Robot Framework 机器人框架:运行测试时出错(解析_____.机器人失败:找不到数据源) - Robot Framework: Error running test (Parsing _____.robot failed: Data source not found) 合并机器人框架测试报告 - Combining robot framework test reports 在Robot Framework中测试python函数 - Test a python function in Robot Framework 在Robot框架中将变量从一个测试用例传递到另一个测试用例 - Pass variables from one test case to another in Robot framework (Global variable) 如何在Robot Framework中获取当前测试用例的状态通过/失败 - How to get current test case(s) status pass/failed in Robot Framework Python:在unittest框架的测试用例中放置一次性初始化的位置? - Python: Where to put a one time initialization in a test case of unittest framework? 如何在Robot框架中自定义测试报告? - How to Customize Test Report in Robot Framework? 机器人框架测试自动化硒 - Robot-Framework-Test-Automation selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM