2017-04-17 24 views
0

我目前有一系列功能測試,我希望能夠在運行時聲明2個選項中的一個。測試目前正在使用XVFB並且無法正常運行。你可以在運行時用Robot Framework聲明變量

操作該瀏覽器當前的代碼是:

Start Virtual Display and enter the URL 
    [Documentation] Test creates virtual display using XVFB 
    [Arguments] ${URL} 
    start virtual display 1440 900 
    Open Browser ${URL} 
    set window size 1440 900 
    sleep ${delay} 

如果我註釋掉start virtual display 1440 900一步,測試用例會自動調用本機瀏覽器中執行的測試步驟。

我希望有一個「簡單的方法」來評論或取消註釋start virtual display測試步驟 - 也許通過聲明它作爲一個變量?

回答

2

你可以在命令行設置變量:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#setting-variables-in-command-line

是不是還不夠嗎?

編輯根據您的代碼示例:

Start Virtual Display and enter the URL 
    [Documentation] Test creates virtual display using XVFB 
    [Arguments] ${URL} 
    Run Keyword If '${vd}' == 'TRUE' Start Virtual Display 1440 900 
    Open Browser ${URL} 
    Set Window Size 1440 900 
    Sleep ${delay} 

然後用--variable vd:TRUE

+0

對不起 - 我沒有做好描述我的實際情況 - 將修改我原來的問題澄清。 –

+0

答案擴展。 –

+0

謝謝Jan!這正是我期望做的,但現在唯一剩下的問題是現在要通過在Jenkins中運行的bash腳本來傳遞該變量。 –

0

打電話給你測試,在更新後的問題,在我看來,你正在尋找Run Keyword If功能,讓您使用在啓動RF以確定腳本執行時在命令行中指定的變量的值。更多關於運行關鍵字如果可以發現here