Dani
Dani

Reputation: 183

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. The OR file is placed inside project . My objective is to place the ObjectMap.Robot in remote place to access it.

Currently I have defined the variable in the 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.

*** 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. Some of used parameters cannot be resolved. Use Variable mappings in red.xml for parameter resolution

Tried adding to red.xml, the error still persist. 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.

Upvotes: 0

Views: 4383

Answers (4)

Satyajit Behera
Satyajit Behera

Reputation: 556

From what I recall and if you hover over one of those keywords you see: “resolved name: abspath(‘.’)” and with using the EXECDIR you need to specify the value of the EXECDIR variable, this can be set in the PyCharm: Settings > Languages & Frameworks > Robot Framework > Variables …I believe or specify the value of the EXECDIR variable using the robot.variables setting.

Hopefully, others can add more to the usage of EXECDIR if needed.

Upvotes: 0

jozefow
jozefow

Reputation: 786

A bit late (I must have missed this question on SO),let me sum up above issue. RED does not know the value of variable. 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. The same applies to system variables such as ${EXECDIR} which can change depending where you start Robot execution and how robot command is constructed.

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. 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).

Therefore for any imports with variables in path, RED assumes that USER has to specify temporary valid values to be used during edit phase.

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.

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

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

If you have any questions or issues,please create those on issue tracker on RED GitHub project: https://github.com/nokia/RED/issues

RED PM

Upvotes: 0

Dani
Dani

Reputation: 183

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

My py code

'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} 

Upvotes: 0

A. Kootstra
A. Kootstra

Reputation: 6981

As highlighted by @Bryan Oakley, this is not a Robot Framework problem but a project configuration issue in the Eclipse RED Robot Framework editor.

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. I created a new project and added three files

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

test.robot

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

*** Test Cases ***

resource.robot

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

ObjectStore.robot

[EMPTY]

RED.xml RED.xml variable mapping

This then ensures that no error is shown in test.robot

enter image description here

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.

Upvotes: 1

Related Questions