我需要在每个测试用例之前执行一些关键字。 假设我有一个.robot文件,其中包含4个测试用例,在执行这4个测试用例之前,我需要运行一次关键字,运行4次。在TestNG中,我们可以使用@BeforeTest批注。我想知道从机器人框架可以用来做什么?
谢谢。
答案 0 :(得分:6)
Test Setup
,Test Teardown
,测试超时关键字可用于指定在每个测试用例之前需要调用的函数。
-Test Setup
将分别在Junit / Testng中充当@Before/@BeforeMethod
-Test Teardown
将在JUnit / Testng中充当@After/@AfterMethod
-[Setup] Keyword
-如果只想对该测试用例执行@BeforeTest
,则将使用-。
请参考以下示例-
*** Settings ***
Library OperatingSystem
Suite Setup This Is Suite Startup Keyword
Suite Teardown This Is Suite TearDown Keyword
Test Setup This Is Before Test
Test Teardown This Is After Test
*** Keywords ***
This Is Suite Startup Keyword
Log To Console This Is Suite Startup Keyword
This Is Suite TearDown Keyword
Log To Console This Is Suite TearDown Keyword
This Is Before Test
Log To Console This Is Before Test
This Is After Test
Log To Console This Is After Test
This Is Special Execution Case
Log To Console This Is Special Execution Case
*** Test Cases ***
Test Case One
[setup] This Is Special Execution Case
Log To Console This Is My Test Case 1
Test Case Two
Log To Console This Is My Test Case 2
Test Case Three
Log To Console This Is My Test Case 3
有关更多详细信息,请参见Robot Framework User Guide部分的初始化文件和2.4.5 Suite的安装和拆卸。
答案 1 :(得分:1)
您可以使用Robotframework <!-- Button -->
<a data-toggle="modal" data-target="#exampleModalLong">
<%= image_tag("https://i.imgur.com/qtVofCH.jpg") %>
</a>
<!-- Modal -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
设置来定义将在套件中每个案例之前运行的关键字。
如果要在特定情况下指定设置,可以使用Test Setup
-如果设置,它将覆盖套件级别的设置:
[Setup]
运行案例1和案例3时,您会在执行之前看到消息“这是针对每种情况运行的”,但不是针对案例2的消息-它具有覆盖的设置,并且您会看到其消息( “自定义案例设置”)
答案 2 :(得分:1)
以下是机器人框架中的关键字,代替了执行挂钩。
┌────────────────┬───────────────────────┐
│ Robot Keyword │ TestNG Execution Hook │
├────────────────┼───────────────────────┤
│ Test Setup │ @BeforeTest │
│ Test Teardown │ @AfterTest │
│ Suite Setup │ @BeforeSuite │
│ Suite Teardown │ @AfterSuite │
└────────────────┴───────────────────────┘