今天,我同时在 windown 和 Mac 两台机器上的 RobotFramework 中导入 IOSLibrary,Windowns 机器上一次性成功(本来也是很简单的事情),但是 Mac 上却一直失败。
最后还是解决掉了,现在分享一下解决过程~~
在 Mac 上使用 pip install --upgrade robotframework-ioslibrary 命令安装 IOSLibrary
安装成功之后,将 IOSLibrary 导入到 RIDE 里面
导入之后,Library 列表中 IOSLibrary 名字会变成黑色,使用库中的关键字时,字体会变成蓝色,好像已经导入成功。
但是。。在 run 的时候却出现了错误
根据错误提示,找打到 IOSLibrary 的安装目录,查看int.py 文件,line 8 显示如下:
from robot.variables import GLOBAL_VARIABLES
似乎是 GLOBAL_VARIABLES 找不到了
于是,继续查看。。。
打开 pyhon 安装目录下的 robot 文件夹,打开找到 variables 文件夹,打开查看int.py 文件,内容如下:
# Copyright 2008-2015 Nokia Solutions and Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Implements storing and resolving variables.
This package is mainly for internal usage.
"""
from .assigner import VariableAssigner
from .isvar import contains_var, is_var, is_scalar_var, is_list_var, is_dict_var
from .notfound import variable_not_found
from .scopes import VariableScopes
from .splitter import VariableSplitter, VariableIterator
from .tablesetter import VariableTableValue, DictVariableTableValue
from .variables import Variables
然后又找了整个 variables 目录,果然没有 GLOBAL_VARIABLES 的蛛丝马迹。
还好还好,我不是在 windown 上成功了么,然后我对比了两个文件,自己手动修改了int.py 文件,内容如下:
# Copyright 2008-2015 Nokia Solutions and Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Implements storing and resolving variables.
This package is mainly for internal usage.
"""
import os
import tempfile
from robot import utils
from robot.output import LOGGER
from .assigner import VariableAssigner
from .isvar import contains_var, is_var, is_scalar_var, is_list_var, is_dict_var
from .notfound import variable_not_found
from .scopes import VariableScopes
from .splitter import VariableSplitter, VariableIterator
from .tablesetter import VariableTableValue, DictVariableTableValue
from .variables import Variables
GLOBAL_VARIABLES = Variables()
def init_global_variables(settings):
GLOBAL_VARIABLES.clear()
_set_cli_vars(settings)
for name, value in [ ('${TEMPDIR}', utils.abspath(tempfile.gettempdir())),
('${EXECDIR}', utils.abspath('.')),
('${/}', os.sep),
('${:}', os.pathsep),
('${\\n}', os.linesep),
('${SPACE}', ' '),
('${EMPTY}', ''),
('@{EMPTY}', ()),
('${True}', True),
('${False}', False),
('${None}', None),
('${null}', None),
('${OUTPUT_DIR}', settings['OutputDir']),
('${OUTPUT_FILE}', settings['Output'] or 'NONE'),
('${REPORT_FILE}', settings['Report'] or 'NONE'),
('${LOG_FILE}', settings['Log'] or 'NONE'),
('${LOG_LEVEL}', settings['LogLevel']),
('${DEBUG_FILE}', settings['DebugFile'] or 'NONE'),
('${PREV_TEST_NAME}', ''),
('${PREV_TEST_STATUS}', ''),
('${PREV_TEST_MESSAGE}', '') ]:
GLOBAL_VARIABLES[name] = value
def _set_cli_vars(settings):
for path, args in settings['VariableFiles']:
try:
GLOBAL_VARIABLES.set_from_file(path, args)
except:
msg, details = utils.get_error_details()
LOGGER.error(msg)
LOGGER.info(details)
for varstr in settings['Variables']:
try:
name, value = varstr.split(':', 1)
except ValueError:
name, value = varstr, ''
GLOBAL_VARIABLES['${%s}' % name] = value
然后再 run 的时候果然就 OK 了!!