2017-12-06 7 views
0

私は、PythonとRobotframeworkスクリプトの組み合わせを使って実装されたプロジェクトを持っています。Robotframeworkの構文解析

class MyConfigManager(ConfigManager): 
    """ 
    Class to hold all config values in form of variables. 
    """ 

def __init__(self): 
    super().__init__("dispatch/config.ini") 
    self._android = Android(self._config) 

@property 
def username(self): 
    return self._config.get(_env_section, "Username") 

@property 
def password(self): 
    return self._config.get(_env_section, "Password") 

config = MyConfigManager() 
:Pythonは大丈夫のようCONFIGMANAGERオブジェクトを使用して上記の変数を解釈することができます

[Environment] 
Username: [email protected] 
Password: testpassword 

[WebUI] 
login_url:  http://testsite.net/ 

:私は、構成アイテムの束が私のプロジェクト内でこのようになりますconfig.iniファイルを保存しています

Robotframeworkのconfig.iniを変数ファイルとしてインポートして、これらの値を使用することはできますか?私は自分のロボットスクリプトに別の変数ファイルを持たないようにしています。

EDIT:

私はロボットのファイルで、このような何かをしようとしています:変数のファイルがPythonコードすることができ、彼らのpythonているので、あなたはすべての変数を作成することができます

*** Settings *** 
Documentation WebUI Login Tests 
Library   SeleniumLibrary 
Resource  common_keywords.robot 
Variables  config.ini 
#^will this work? 
Default Tags Smoke 
Suite Setup  Set Selenium Timeout  15seconds 
Suite Teardown Close Browser 

*** Variables *** 

${login_button}  class:auth0-lock-submit 



*** Test Cases *** 
TC001_Login_Test 
    [Documentation]  Open login page, login with credentials in arguments. 
    Open Browser Confirm Login Page  chrome  ${login_url} 
    Provide Input Text   name:email   ${username} 
    Provide Input Text   name:password  ${password} 
    Find Element And Click  ${login_button} 
# the three vars ${login_url}, ${username}, ${password} would be from 
# config.ini but this isnt working. What am I doing wrong? or is not 
# possible to do this? 

答えて

4

ロボットフレームワークあなたは欲しい。

キーと値のペアの辞書を返すPython関数を作成するだけです。各キーはロボット変数になります。あなたは${CONFIG.Environment.username}ような変数を作成する場合たとえば、あなたの質問内のデータのために、あなたはこのようにそれを行うことができ

:「ConfigVariables.py」という名前のファイルに保存

import ConfigParser 
def get_variables(varname, filename): 
    config = ConfigParser.ConfigParser() 
    config.read(filename) 

    variables = {} 
    for section in config.sections(): 
     for key, value in config.items(section): 
      var = "%s.%s.%s" % (varname, section, key) 
      variables[var] = value 
    return variables 

、およびあなたのテストで見つけることができるところに置いてください。次に、このようにそれを使用することができます:

*** Settings *** 
Variables ConfigVariables.py CONFIG /tmp/Config.ini 

*** Test cases *** 
Example 
    should be equal ${CONFIG.Environment.username} [email protected] 
    should be equal ${CONFIG.Environment.password} testpassword 
    should be equal ${CONFIG.WebUI.login_url}  http://testsite.net/ 

ロボットのフレームワークのユーザーガイドに記載された変数を定義するための関数を使用して、というタイトルのセクションでVariable Files