2017-12-06 3 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() 
:

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

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

파이썬이 같은 CONFIGMANAGER 객체를 사용하여 확실히 위의 변수를 해석 할 수있다 : I는 다음과 같습니다의 config.ini 파일 내 프로젝트 내부에 저장된 구성 항목의 무리가 있습니다

Robotframework에서 config.ini를 변수 파일로 가져 와서이 값을 사용할 수 있습니까? Robot 스크립트에 다른 변수 파일을 갖고 싶지 않습니다.

편집 :

내 로봇 파일과 같은 뭔가를 시도하고있다 :

*** 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

로봇 프레임 워크 변수 파일이 될 수 파이썬 코드, 그들은 파이썬 때문에, 당신이 어떤 변수를 만들 수 있습니다 네가 원하는대로.

키/값 쌍의 사전을 반환하는 파이썬 함수를 만들어야합니다. 각 키는 로봇 변수가됩니다. 질문의 데이터에 대한 예를 들어

, 당신은 ${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