I am trying to import a method from the python class ExampleLibrary
from the Python file Example.py
#Example.py
class ExampleLibrary:
ROBOT_LIBRARY_SCOPE = 'TEST CASE'
counter = 0
def county(self):
self.counter = 29
print(self.counter)
return self.counter
def clear_counter(self):
self.counter = 0
print(self.counter)
My Robot file is like
*** Settings ***
Library ExampleLibrary
*** Test Cases ***
This is a Sample Test
[Documentation] First Test
[Tags] Variables display
${var} county
log ${var}
The robot framework is unable to recognize the keyword county
from the Example.py
but the ExampleLibrary
class is being imported properly. I am using the Pycharm IDE. Can anyone help me out? Thank you.
Using your code, and adding Example.py's location into the PYTHONPATH, I get two errors. These errors should be visible on the console and in the log.html as well and I think you should have both as well.
Importing test library 'ExampleLibrary' failed: ModuleNotFoundError: No module named 'ExampleLibrary'
and
No keyword with name 'county' found.
The second one is the consequence of the first one, and the problem is that there is no information where ExampleLibrary
class is. To resolve this, and correctly import the library you should define in the robot file where the ExampleLibrary
class can be found.
*** Settings ***
Library Example.ExampleLibrary
Your other choice could be to rename Example.py to ExampleLibrary.py. But if you have more classes in a Python file like in this question, Inner nested class access from robot framework , you could face similar problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.