2017-02-09 10 views
1

夥計們。 我是Robot Framework中的新成員,可能是我的問題看起來很簡單,但我無法找到正確的解決方案。機器人框架如何從「測試用例」中的庫中獲得選擇器值

我有一個測試:

*** Settings *** 
Documentation Login Scenarios 
Library ExtendedSelenium2Library 
Library Resources/LoginPage.py 
Resource Resources/Common.robot 
Library Resources/TopMenuPage.py 
Suite Setup Begin Web Test 
Suite Teardown End Web Test 

*** Variables *** 
${USERNAME} user 
${PASSWORD} password 

*** Test Cases *** 
Login With Valid Credentials 
    [Documentation] Login With Valid Credentials 
    [Tags] Functional 
    LoginPage.input_username ${USERNAME} 
    LoginPage.input_password ${PASSWORD} 
    LoginPage.click_sign_in_button 
    ${test} TopMenuPage.get_selectors 
    page should contain link ${test['logoutButton']} 
    [Teardown] click link css=[ng-click="mainCtrl.logout()"] 

而且我有我的圖書館(TopMenuPage.py)代碼:

selectors = { 
    "logoutButton": "css=[ng-click=\"mainCtrl.logout()\"]", 
    "welcome": "binding=mainCtrl.user.name" 
} 

class TopMenuPage(object): 
    def get_selectors(self): 
     return selectors 

如何在正確的方式,我可以讓我選擇的測試? 例如:

page should contain link TopMenuPage.get_selectors['logoutButton'] 

感謝響應。

+0

現在我使用額外的變量$ {test},它的工作。但我認爲這不是一個好的解決方案。 –

回答

0

你不能這樣做page should contain TopMenuPage.get_selectors['logoutButton'],因爲page should contain需要一個字符串作爲參數,而不是函數調用。您需要撥打TopMenuPage.get_selectors並將結果保存在變量中,然後使用該變量。

+0

謝謝你的回答。最後一個問題:我可以創建一個可用於所有套件的變量嗎? 我試圖將$ {test}變量移動到*** Variables ***,但我得到一個錯誤 - 「解析變量'$ {test ['logoutButton']}'失敗:TypeError:字符串索引必須是整數」 –

+0

@ AlexanderMelnychuk「是的,機器人支持測試,套件和全局變量,全部記錄在[用戶指南]中(http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-set-test-suite-global-variable -keywords)。 –

相關問題