简体   繁体   English

Robot FrameWork:在“设置”中参数化资源路径时出现问题

[英]Robot FrameWork : Issue when parameterizing Resource path in Settings

Robot Framework -I have issue parameterizing the resource path in settings section.Currently I have object repository in a file for my selenium project and saved it as ObjectMap.Robot file . Robot Framework-我在设置部分参数化资源路径时遇到问题。目前,我在selenium项目的文件中有对象存储库,并将其保存为ObjectMap.Robot file The OR file is placed inside project . OR文件放置在project内。 My objective is to place the ObjectMap.Robot in remote place to access it. 我的目标是将ObjectMap.Robot放置在远程位置以对其进行访问。

Currently I have defined the variable in the ConfigVariables.robot 目前,我已经在ConfigVariables.robot定义了变量

*** Variables ***

${DataFilePath}    /Sample/DataFiles/
${OR_PATH}    \\\\AIX2UB333/Resources/ObjectMap/

The ${OR_PATH} keep changing And to access OR file in my keyword file, I have set my setting as below. $ {OR_PATH}不断变化为了访问关键字文件中的OR文件,我将设置设置如下。

*** Settings ***

Resource    ../Resources/ConfigurationFiles/ConfigVariables.robot
Resource    ${OR_PATH}/ObjectMap.robot

Issue : Error is shown as that 问题:错误显示为

The import name/path '${OR_PATH}/ObjectMap.robot' is parameterized. 导入名称/路径'$ {OR_PATH} /ObjectMap.robot'已参数化。 Some of used parameters cannot be resolved. 一些使用的参数无法解析。 Use Variable mappings in red.xml for parameter resolution 在red.xml中使用变量映射进行参数解析

Tried adding to red.xml , the error still persist. 尝试添加到red.xml ,错误仍然存​​在。 The funny thing is that if i run the test case it would run successfully. 有趣的是,如果我运行测试用例,它将成功运行。 But the variables used from the objectmap has a red error line in test cases. 但是在测试用例中,对象图中使用的变量有一条红色错误线。 Every variables has the error 每个变量都有错误

Variable is used, but not defined. 使用了变量,但未定义。

As highlighted by @Bryan Oakley, this is not a Robot Framework problem but a project configuration issue in the Eclipse RED Robot Framework editor. 正如@Bryan Oakley强调的那样,这不是Robot Framework问题,而是Eclipse RED Robot Framework编辑器中的项目配置问题。

It seems to me that something in your setup is not correct with respect to the project variable mapping. 在我看来,就项目变量映射而言,您的设置中的某些内容不正确。 Please ensure that you have the latest RED by updating your eclipse from the market place or by downloading the latest from the GitHub site. 请通过从市场更新日食或从GitHub站点下载最新的日食来确保您拥有最新的RED。 I created a new project and added three files 我创建了一个新项目并添加了三个文件

project:
.
├── red.xml
├── OR
|   └── ObjectStore.robot
├── test.robot
└── resource.robot

test.robot test.robot

*** Setting ***
Resource    resource.robot
Resource    ${OR}/ObjectStore.robot

*** Test Cases ***

resource.robot resource.robot

*** Variable ***
${OR}    OR

ObjectStore.robot ObjectStore.robot

[EMPTY]

RED.xml RED.xml RED.xml变量映射

This then ensures that no error is shown in test.robot 这样可以确保在test.robot中没有显示错误

在此处输入图片说明

As your object store may change, I'd also advise not to include it in a hard coded configuration reference. 由于您的对象库可能会更改,因此我也建议不要将其包括在硬编码的配置参考中。 Instead use the power of Robot Framework command line variable to add a variable or refer to a variable file to have the flexibility you seek without the need to modify files after fetching them from a source code repository. 而是使用Robot Framework命令行变量的功能来添加变量或引用变量文件,以具有所需的灵活性,而无需在从源代码存储库中获取文件后修改文件。

I have found a workaround for the situation asked. 我找到了一种针对所问情况的解决方法。 I inserted a py file which as the code to copy ObjectMap from my remote machine to my local project and method name of this code was used as keyword in robot and applied in Suite setup. 我插入了一个py文件,作为将ObjectMap从远程计算机复制到本地项目的代码,该代码的方法名称在robot中用作关键字并应用于Suite设置。 In robot I had made a flag as well to run only if the condition satify. 在机器人中,我还制作了一个标志,只有在条件满足时才能运行。 The flag is added becos , if any one wants to run the code in the same remote machine that would create various copies of it Object Map in the same machine. 如果有人想要在同一台远程计算机上运行代码,而该标志将在同一台计算机上创建对象映射的各种副本,则会在becos中添加该标志。

My py code 我的PY代码

'def copy_file_from_source_to_destination(self,src,dst):           
    try:
        shutil.copy2(src, dst)
    except Exception as e:
        return str(e)
    return 'Success'  '

My robot keyword 我的机器人关键字

'Get Central OR

    ${DESTINATION}=    Catenate    ${EXECDIR}${TARGET_OR} 
    Log    ${DESTINATION}
    ${CALL_STATUS}=    Convert To Uppercase    ${CALL_STATUS}
    Run Keyword If    '${CALL_STATUS}'=='YES'    Copy File From Source To Destination    ${CENTRAL_OR}    ${DESTINATION} 

A bit late (I must have missed this question on SO),let me sum up above issue. 有点晚了(我肯定在SO上错过了这个问题),让我总结一下以上问题。 RED does not know the value of variable. RED不知道变量的值。 Variable can be modified during execution (either by testlogic,suite setups,variable files etc.) so any value assignments from Variable sections cannot be taken by RED to resolve parametrised path. 可以在执行期间修改变量(通过testlogic,套件设置,变量文件等),因此RED不能采用Variable部分中的任何值分配来解析参数化路径。 The same applies to system variables such as ${EXECDIR} which can change depending where you start Robot execution and how robot command is constructed. 这同样适用于系统变量,例如$ {EXECDIR},这些变量可以根据您从何处开始执行机器人以及如何构造机器人命令而更改。

In another scenario, CI job, based on input parameters (for instance version or type of software to be tested with Robot) modifies variable in paths to use proper library or resource which is valid only for that version or type of software. 在另一种情况下,CI作业根据输入参数(例如,要使用Robot测试的软件的版本或类型)修改路径中的变量,以使用仅对该版本或软件有效的适当库或资源。 Without VM mechanism,tester would have to temporary change suites with parametrised imports to direct paths just to be able to use proper imports (real world scenario in Nokia and the reason for VM in red.xml). 如果没有VM机制,测试人员将不得不使用参数化的导入来临时更改套件以直接引导路径,以便能够使用正确的导入(诺基亚中的实际情况以及red.xml中使用VM的原因)。

Therefore for any imports with variables in path, RED assumes that USER has to specify temporary valid values to be used during edit phase. 因此,对于路径中具有变量的任何导入,RED假定USER必须指定在编辑阶段要使用的临时有效值。

This is a reason for Variable Mappings in red.xml - allow to specify values of variables so any paths can be resolved thus allowing to import files. 这是在red.xml中使用变量映射的原因-允许指定变量的值,以便可以解析任何路径,从而允许导入文件。

There is also an entry in RED help (in application and on github): http://nokia.github.io/RED/help/user_guide/working_with_RED/variable_mapping.html RED帮助(在应用程序和github中)中还有一个条目: http : //nokia.github.io/RED/help/user_guide/working_with_RED/variable_mapping.html

Warning regarding "something is outside Project/Workspace" - a warning which may help to understand why tests are not working when they were checkout from repository on different machine. 关于“项目/工作区外部的某些东西”的警告-警告,可以帮助您理解为什么从其他计算机上的存储库中检出测试时,测试不起作用。 Any Errors/Warnings can be changed in Windows->Preferences->Robot Framework -> Error/Warnings Help topic: http://nokia.github.io/RED/help/user_guide/validation/validation_preferences.html 可以在Windows->首选项->机器人框架->错误/警告帮助主题中更改任何错误/警告: http : //nokia.github.io/RED/help/user_guide/validation/validation_preferences.html

If you have any questions or issues,please create those on issue tracker on RED GitHub project: https://github.com/nokia/RED/issues 如果您有任何疑问或问题,请在RED GitHub项目的问题跟踪器上创建这些问题: https : //github.com/nokia/RED/issues

RED PM 红色下午

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Robot Framework中的Robot Resource File和Robot Test Suite有什么区别 - What is the difference between Robot Resource File and Robot Test Suite in Robot Framework 机器人框架:Selenium 库 - 未考虑带有关键字的自定义资源文件 - Robot Framework : Selenium Library - Custom Resource File with keywords are not taking into account 机器人框架输出和结果文件路径和名称配置 - robot framework output and result file path & name configuration 尝试启动Robot Framework时出错,无法投射进程 - Error when attempting to launch Robot Framework, process cannot be cast 安装 Eclipse 时代理设置的问题 - Issue with the proxy settings when installing Eclipse 405 - 机器人框架中不允许的方法 - 405 - Method Not Allowed in Robot Framework 在RED机器人框架Eclipse编辑器中指定用户定义的Java库时出错 - It errors when specifying the user defined java library into RED robot framework eclipse editor Struts框架设置中的错误 - error in Struts framework settings Intelliji的想法使迁移黯然失色。 在Eclipse中,哪里可以找到IntelliJ IDEA的“ Web资源目录路径对话框”的相同设置? - Intelliji idea to eclipse migration. Where to find same settings for IntelliJ IDEA's “Web Resource Directory Path Dialog” in Eclipse? Django设置中的相对路径 - relative path in Django settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM