-1

please note that attempt is to write python script and not in robot files

I have two files


api.py

import requests
from robot.libraries.BuiltIn import BuiltIn
from robot.api import logger
from robot.running.model import Keyword

bi = BuiltIn()

class APIRequests:
    ROBOT_LIBRARY_SCOPE = 'TEST CASE'
    def something():
      return "some string/value"

In the same folder, i have another file which I script robot file

login.robot

*** Settings ***
Library         BuiltIn
Library         api.py
*** Test Cases ***
Valid Weathercheck:
    ${abc} = something 
    Log to console ${abc}

When I execute from the command console robot login.robot I get an error message saying the 'No keyword with name 'something' found.'

Query2

When we want to use some existing web driver modules which are existing in python , i am unable to find the needed documentation around it on how I can link/import them as ready keywords

Rams
  • 193
  • 1
  • 17

1 Answers1

1

Robot won't automatically create an instance of your class, unless the class name is the same name as the filename. In your case you have a file named api.py but a class name of APIRequests. You either need to change the name of the file to APIRequests.py, change the class name to api, or import the keywords as api.APIRequests.

From the robot framework user guide:

Python classes are always inside a module. If the name of a class implementing a library is the same as the name of the module, Robot Framework allows dropping the class name when importing the library. For example, class MyLib in MyLib.py file can be used as a library with just name MyLib.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • It is actually a typo , apologies for that - apirequests is the name of class . I found that there is a different error in the log which i have overlooked , the file apirequest with the class name also as apirequests is available in the same folder/directory but I do see an error like "Importing test library 'apirequests' failed: ImportError: No module named apirequests" – Rams Aug 22 '18 at 17:25
  • https://stackoverflow.com/questions/32832629/importing-test-library-error-for-user-defined-methods - thanks, got the answer and response for both the queries – Rams Aug 22 '18 at 17:47