How to sent the variable from test case file(robot_new.robot) to Keywords file(robot_keywords.resource) to the custom library(for example:- Custom_Library.py) functions?

I’ve just started using the robot framework for my project. But i am facing one problem in sending the variable as argument to the custom library function.

I have three files right now.

  1. robot_new.robot (this file has the test cases written).

  2. robot_keywords.resource (Keyword file which has one keyword defined)

  3. Custom_Library.py (Custom Library file which has the user defined functions and necessary imports)

So, now here the problem is when I am sending the variable from ‘New_Test.robot’ to ‘Custom_Library.py’ its not working. and I am getting error because the value of the variables vendor_name, api_name, version inside the function is not being taken correctly. So, can anyone find whats the problem here ?

I am getting error in file ‘Custom_Library.py’ in line
testbench = testbenchFactory.CreateVendorSpecificTestbench(vendor_name, api_name, version)

Hi Shiv,

I suspect it might be the line:

	def __init__(self) -> None:

Causing you trouble?

I built an example matching your screen shot as best I can (I don;t have the testbenchfactory module), that line gave me the error:

Error in file 'robot_keywords.resource' on line 2: Importing library 'Custom_Library.py' failed: IndentationError: expected an indented block after function definition on line 2 (Custom_Library.py, line 4)

I changed it to syntax I’m more familiar with:

	def __init__(self):
		pass

Here is my full example, you can copy them to another folder and try them out to see if you can reproduce my result, as that might help you trouble shoot your issue

robot_new.robot

*** Settings ***
Resource 		robot_keywords.resource

*** Variables ***
${vendor_name} 		"dSPACE GmbH"
${API_name} 			"XIL API"
${Version} 				"2021-B"

*** Test Cases ***

Testbench Creation
	${Testbench_created}= 	Craete X11 Testbench 		${vendor_name} 		${API_name} 		${Version}

robot_keywords.resource

*** Settings ***
Library 		Custom_Library.py

*** Keywords ***
Craete X11 Testbench
	[Arguments]		${vendor_name} 		${API_name} 		${Version}
	Log 		${vendor_name}
	Log 		${API_name}
	Log 		${Version}
	${Testbench_created}= 		Creating New Testbench		${vendor_name} 		${API_name} 		${Version}
	RETURN 	${Testbench_created}

Custom_Library.py

class Custom_Library:
	# def __init__(self) -> None:
	def __init__(self):
		pass

	def creating_new_testbench(self, vendor_name, api_name, version):
		print("vendor_name:", vendor_name, "	api_name:", api_name, "	version:", version)
		return ":|:".join([vendor_name, api_name, version])

And here is a screen shot of my log, you can see the variables are passed to the python function and back to the resource file and eventually back to the test case:

Hope this helps you find the problem,

Dave.

Thank you so much for your quick solution. it worked.

1 Like