damop
damop

Reputation: 31

Return list values from Python Script using Robot Framework custom Keyword

I have created a Robot Framework custom keyword in a python script that returns the full file paths of files in a directory structure. I can run the python script separately and I get the expected results, however, when I use the script as a custom keyword the returned list in empty.

Any help is appreciated See below for code: ROBOT CODE

Settings 
Library  FilePaths.py

Test Cases

GetsubmissionFiles

  @{List}=  get filepaths  ////SomeServer//D//TestData//Automation//UK//

Here is the python code:

import os
class  FilePaths:
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

d = "\\\\SomeServer\\D\\TestData\\Automation\\UK\\"

def get_filepaths(d):

    file_paths = []  
    for root, directories, files in os.walk(d):
        for filename in files:
            filepath = os.path.join(root, filename)
            file_paths.append(filepath)
    return file_paths

full_file_paths = get_filepaths(d)

print(full_file_paths)

Issue is Robot Framework results in an empty list value with none of the file paths Return value = []

Upvotes: 0

Views: 1631

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386210

The problem is that you're not using a valid file path. For UNC paths you need to use just a single slash rather than a double slash:

@{List}=  get filepaths  //SomeServer/D/TestData/Automation/UK/

In your question you claim it "I can run the python script separately and I get the expected results", but in the python code you are using backslashes. Since you're using backslashes in a string, you must double them up. With forward slashes there is no need to do that.

In other words, it worked in python but not in robot because you were using a correct path in python and an incorrect path in robot.

Upvotes: 0

Related Questions