2017-04-16 91 views
1

我有一些機器人測試用例在目錄中分開。目錄層次是:如何在機器人框架中設置多級測試設置/拆卸

內容的 __init__.robot
ParentTestDirectory 
    |__ ChidTestDirectoryOne 
     |__ TestOne.robot 
    |__ ChidTestDirectoryTwo 
     |__ TestTwo.robot 
    |__ __init__.robot 

內容的
*** Settings *** 
Test Setup   LOG TO CONSOLE Test setup from __init__.robot 
Test Teardown  LOG TO CONSOLE Test teardown from __init__.robot 

TestOne.robot

內容的 TestTwo.robot
*** Settings *** 
Test Setup   LOG TO CONSOLE Test setup from TestOne.robot 
Test Teardown  LOG TO CONSOLE Test teardown from TestOne.robot 
*** Test Cases *** 
Test One 
    LOG TO CONSOLE This is Test One! 

*** Settings *** 
Test Setup   LOG TO CONSOLE Test setup from TestTwo.robot 
Test Teardown  LOG TO CONSOLE Test teardown from TestTwo.robot 
*** Test Cases *** 
Test Two 
    LOG TO CONSOLE This is Test Two! 

我有一個使用python編寫的runner,它使用robot runner模塊;這是命令sudo python run.py --testsuit scenarios.ParentTestDirectory運行測試用例的結果:

============================================================================== 
Scenarios                  
============================================================================== 
Scenarios.ParentTestDirectory             
============================================================================== 
Scenarios.ParentTestDirectory.ChidTestDirectoryOne        
============================================================================== 
Scenarios.ParentTestDirectory.ChidTestDirectoryOne.TestOne      
============================================================================== 
Test One                Test setup from TestOne.robot 
.This is Test One! 
.Test teardown from TestOne.robot 
Test One                | PASS | 
------------------------------------------------------------------------------ 
Scenarios.ParentTestDirectory.ChidTestDirectoryOne.TestOne   | PASS | 
1 critical test, 1 passed, 0 failed 
1 test total, 1 passed, 0 failed 
============================================================================== 
Scenarios.ParentTestDirectory.ChidTestDirectoryOne     | PASS | 
1 critical test, 1 passed, 0 failed 
1 test total, 1 passed, 0 failed 
============================================================================== 
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo        
============================================================================== 
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo.TestTwo      
============================================================================== 
Test Two                Test setup from TestTwo.robot 
.This is Test Two! 
.Test teardown from TestTwo.robot 
Test Two                | PASS | 
------------------------------------------------------------------------------ 
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo.TestTwo   | PASS | 
1 critical test, 1 passed, 0 failed 
1 test total, 1 passed, 0 failed 
============================================================================== 
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo     | PASS | 
1 critical test, 1 passed, 0 failed 
1 test total, 1 passed, 0 failed 
============================================================================== 
Scenarios.ParentTestDirectory           | PASS | 
2 critical tests, 2 passed, 0 failed 
2 tests total, 2 passed, 0 failed 
============================================================================== 
Scenarios                | PASS | 
2 critical tests, 2 passed, 0 failed 
2 tests total, 2 passed, 0 failed 
============================================================================== 

正如你看到的,它只是運行最新的測試安裝/拆卸。我希望它能夠從父目錄運行測試設置/拆卸,並且應該在孩子之前執行。換句話說,我希望父設置在每個測試用例分別在自己的設置之前運行。我可以通過機器人框架功能實現嗎?

+0

在所有子測試用例啓動之前,您是否希望父設備只運行一次?如果是這樣,請考慮在'__init __。robot'中使用'Suite Setup'和'Suite Teardown'。還是你想讓父設置在每個測試用例單獨運行之前運行? –

+0

@ A.Kootstra,你的第二個猜測是真實的。我希望父級設置在每個測試用例分別運行之前運行。 –

+1

當第二個選項是你正在尋找的,那麼@Brian Oakley的答案是正確的。 –

回答

3

測試案例只能有一個設置。當您將Test Setup作爲整體套件的設置時,將定義默認測試設置。如果子套件或單個測試定義了測試設置,則將運行而不是定義的更高的套件級別設置。

在標題爲機器人框架用戶指南Initialization files的部分,它說,這(與我加的):

測試設置,測試拆解,測試超時

設置缺省值該目錄包含的所有測試用例的測試設置/拆卸值或測試超時值。 可以在較低級別上覆蓋。在Robot Framework 2.7中添加了對初始化文件中定義測試超時的支持。

如果你想在浴室的定義是,除了每個試驗規定的設置運行測試設置,你應該把這些代碼轉換成自定義的關鍵字,讓每個測試呼叫關鍵字作爲其設置的一部分。

相關問題