Currently I’m exploring the different ways to use keywords and I’m getting some difficult to understand the reason why something works (and not works ). Could you help me to learn a bit more about this topic please?
Scenario:
Given I have a testcase.robot
And the testcase.robot import the file KeywordsClass.py
And the testcase.robot import the file keywords_module.py
And both python files has a similar function
And the folder has only these tree files
When I execute the testcase.robot executing robot testcase.robot
Then the result below are verified
Question:
Why I need to use .py when importing the keyword libraries in this scenario? I verified in many examples where it is not used, however, if it is removed from my code, the following error is reported.
The second test case failed as you can see in the Figure 1. According to the message, the “Class Method” expected 1 argument, but it is not true since it has two and it is the same function used in the first test case but into a class (in my point of view). Do you have idea why this error are returned?
Files
"""
testcase.robot
"""
*** Settings ***
Library keywords_module.py
Library KeywordsClass.py
*** Test Cases ***
Example that calls a keyword from python module
${result}= Module Function hello world
Should be equal ${result} hello world
Example that calls a keyword from KeywordsClass
${result}= Class Method hello world
Should be equal ${result} hello world
Your class_method doesn’t have the self argument that methods in Python must have.
To import a library without the extension, it needs to in the Python module search path. That happens automatically if the library is installed but you can also set PYTHONPATH environment variable or use --pythonpath with the robot command.
Well, I believe you figured out that I’m a newbie in python.
Thank you for the clarification! Based on it, I verified that:
The pyYAML modules was not installed, but it is required to handle the robot.yaml (according to the documentation)
The PYTHONPATH was not defined
So, I did the following:
I added the PYTHONPATH to the system environment with the initial python installation path (since empty value is not accepted and I suppose the robot will add automatically the script folder from robot.yml to PYTHONPATH ) as showed in the Figure 3 below: