2017-02-09 8 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}変数を***変数***に移動しようとしましたが、エラーが発生しました - "変数$ {test ['logoutButton']}を解決できませんでした:TypeError:文字列インデックスは整数でなければなりません" –

+0

@ AlexanderMelnychuk "はい、ロボットはテスト、スイート、グローバル変数をサポートしています。それはすべて[ユーザーガイド](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-set-test-suite-global-variable)に記載されています。 -keywords)。 –

関連する問題