Manjeet
Manjeet

Reputation: 53

RobotFramework is unable to import modules mentioned in python file

I have a .robot file which imports a .py file(my python file has some modules as import statements) When i am trying to run the robot file i am getting below error. How do i make sure that the modules imported in python class file are also imported?

[ ERROR ] Error in file 'C:\Users\Admin\Documents\PythonDemo\src\framework\tests\login_box.robot': Importing test library 'CreateCampaign.py' failed: ImportError: No module named framework.page_object_model.home_page
Traceback (most recent call last):
  File "C:\Users\Admin\Documents\PythonDemo\src\framework\tests\CreateCampaign.py", line 1, in <module>
from framework.page_object_model.home_page import HomePage
PYTHONPATH:
  C:\Users\Admin\Documents\PythonDemo\src\framework
  C:\Windows\system32\python27.zip
  C:\Python27\DLLs
  C:\Python27\lib
  C:\Python27\lib\plat-win
  C:\Python27\lib\lib-tk
  C:\Python27
  C:\Python27\lib\site-packages
==============================================================================
Login Box :: Tests Login to BOX.com
==============================================================================
Log into Box using valid credentials                                  | FAIL |
No keyword with name 'When I log into Box as my ${user} with ${userpass}' found.

.robot file

*** Settings ***
Library  test_create_campaign.py

Documentation  Tests Login to BOX.com

*** Variables ***
${user}         [email protected]
${userpass}     testing

*** Test Cases ***
Log into Box using valid credentials
    When I log into Box as my ${user} with ${userpass}

.py file

from framework.page_object_model.home_page import HomePage
from robot.api.deco import keyword

class CreateCampaign(LayarTestCase):
@keyword(name='I log into Box as my ${user} with ${userpass}')
    def test_create_campaign(self, user, userpass):
        print user
        print userpass

Upvotes: 3

Views: 4624

Answers (1)

Mann
Mann

Reputation: 307

I modified the python file to make it work.

.py file

from framework.page_object_model.home_page import HomePage
from robot.api.deco import keyword

class test_create_campaign:
    @keyword(name='I log into Box as my ${user} with ${userpass}')
    def test_create_campaign(self, user, userpass):
        print user
        print userpass
  1. Corrected the syntax of class definition.
  2. Renamed the class name to be the same as the file name. This is important because Robot framework will not accept the keyword otherwise. Is there a reason you are using a class? You can define a method (keyword) without a class and that will work as well.

Upvotes: 2

Related Questions