1

I have created python file and trying to import that to my robot project.Below is the python file name helloworld.py,

class   helloworld:
    ROBOT_LIBRARY_SCOPE = 'TESTCASE'
    def fun_scope(self):
        print("Hello World")

Below is the robot script,

*** Settings ***
Library    helloworld

*** Test Cases ***

TC1
    Fun Scope

While executing i am getting below error,

[ ERROR ] Error in file '/home/sadha/PycharmProjects/NotificationService/Test/custom.robot' on line 2: Importing library 'helloworld' failed: ModuleNotFoundError: No module named 'helloworld'
Traceback (most recent call last):
  None
PYTHONPATH:
  /home/sadha/PycharmProjects/NotificationService/venv/bin
  /usr/lib/python38.zip
  /usr/lib/python3.8
  /usr/lib/python3.8/lib-dynload
  /home/sadha/PycharmProjects/NotificationService/venv/lib/python3.8/site-packages

I tried all the possible solution but nothing worked :(

Sadha Nanda
  • 337
  • 4
  • 15
  • The name of your class should start with a capital letter, though it probably has nothing to do with your problem. – Jiri Janous Apr 23 '21 at 06:53

1 Answers1

2

Specifing the name of the library fixes the problem. Just use helloworld.py in your robot.

*** Settings ***
Library    helloworld.py

*** Test Cases ***

TC1
    Fun Scope
Jiri Janous
  • 1,189
  • 1
  • 6
  • 14
  • Thanks it solved the execution issue but in console still i am getting the Traceback error related to pythonpath which mentioned above – Sadha Nanda Apr 23 '21 at 07:07
  • Using your code i had the same problem, but this was solved with the solution i posted. I get no issues now. Could be a python path problem. have you tried executing your python alone? – Jiri Janous Apr 23 '21 at 07:30
  • Hi, yes i am not facing any issue while executing python file alone via terminal and IDE – Sadha Nanda Apr 23 '21 at 07:34
  • @SadhaNanda Use the `--pythonpath` argument and specify the files location. Checkout this answer about importing custom libraries: https://stackoverflow.com/a/57672418/3820025. – Bence Kaulics Apr 23 '21 at 15:53