Importing variables using the Import Resource keyword

3,428 views
Skip to first unread message

C.Jones

unread,
Aug 23, 2011, 2:46:12 PM8/23/11
to robotframework-users, rylan.h...@points.com
I'm trying to a resource dynamically based on a data set that is
defined in the test case. The most appropriate method I've found to
do this is the "Import Resource" keyword in the BuiltIn library. I
was my understanding that this keyword would include the resource in
the test suite scope, making the keywords and variables in that
resource available throughout that suite.

The problem I've encountered is that the variables listed in the
resource being imported do not exist after Import Resource is called.
For example, I can call Import Resource with the path of a resource
containing a variable ${NAME} and on the next line of the test case,
call Log ${NAME} and I will be told that ${NAME} does not exist.
However, I am able to use the keywords defined in the same file after
it's been imported.

Could you let me know how this keyword should be used or suggest a
possible alternative? Thanks.

C.Jones

unread,
Aug 24, 2011, 2:35:30 PM8/24/11
to robotframework-users
Use case:

LoginTest.txt
*** Settings ***
Resource Login.txt

*** Test Cases ***
Test Login
Using Member 12345
Test Login

*** Keywords ***
Using Member
[Arguments] ${member}
Import Resource ${member}.txt

12345.txt
*** Variables ***
${member_id} 12345
${name} John Smith

Login.txt
*** Settings ***
Library SeleniumLibrary

*** Keywords ***
Login
Input Text member_id ${member_id}
Input Text name ${name}
Click Button submit

Pekka Klärck

unread,
Sep 2, 2011, 5:47:23 PM9/2/11
to curtis...@points.com, robotframework-users, rylan.h...@points.com
2011/8/23 C.Jones <curtis...@points.com>:

> I'm trying to a resource dynamically based on a data set that is
> defined in the test case.  The most appropriate method I've found to
> do this is the "Import Resource" keyword in the BuiltIn library.  I
> was my understanding that this keyword would include the resource in
> the test suite scope, making the keywords and variables in that
> resource available throughout that suite.
>
> The problem I've encountered is that theP variables listed in the

> resource being imported do not exist after Import Resource is called.
> For example, I can call Import Resource with the path of a resource
> containing a variable ${NAME} and on the next line of the test case,
> call Log  ${NAME} and I will be told that ${NAME} does not exist.
> However, I am able to use the keywords defined in the same file after
> it's been imported.
>
> Could you let me know how this keyword should be used or suggest a
> possible alternative?  Thanks.

I cannot tell how to use this keyword because you have found a bug. I
just submitted it into the tracker [1] and it will be fixed for the
next release (hopefully already next week).

Probably the best workaround for this problem is using variable files
and Import Variables keyword. Alternatively you could use Import
Resource in suite setup -- variables imported there are visible to all
tests -- but based on your use case that doesn't work for you so well.

[1] http://code.google.com/p/robotframework/issues/detail?id=944

Cheers,
.peke

PS: Sorry for neglecting this mail for so long. It unfortunately got
under a big pile of other unread mails which I'm only now able to go
through.
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

N.T.

unread,
Jul 6, 2015, 1:21:34 AM7/6/15
to robotframe...@googlegroups.com, rylan.h...@points.com, curtis...@points.com
Hi All,

Has this issue been fixed?

According to the robotframework group it has been fixed but when I use it I get the exact same error.

So similar to the submitter's issue I need to be able to run different resource files. 

I created different keywords to import the right variable file. (EX: US, AU, JP, etc)

So this is how the setup resource file looks like:

*** Settings ***
Library           Selenium2Library
Resource          ../variables/AU/Resource.txt
Resource          ../variables/US/Resource.txt
Resource          ../variables/AU/importAU.txt


*** Variables ***
$
{COUNTRY}        AU


*** Keywords ***
Homepage should be open
   
Run Keyword    AU
   
Set Selenium Speed    1 second
   
Open Browser    ${url_staging}    chrome


And this is how the importAU.txt looks like:

*** Settings ***
Library           Selenium2Library


*** Keywords ***
AU
   
[Documentation]    Initializes the AU keyword variables
   
Import Variables    ../variables/AU/Resource.txt

Despite that I created the file and I can import this without any error through the settings, I can't seem to do this using the "Import Resource" or the "Import Variables" button.

KEYWORD: BuiltIn.Import Resource ../variables/AU/Resource.txt
Documentation:

Imports a resource file with the given path.

Start / End / Elapsed:20150706 13:49:31.289 / 20150706 13:49:31.293 / 00:00:00.004
13:49:31.293FAILResource file '..\variables\AU\Resource.txt' does not exist.

Am I doing something wrong?

Christian Rudolf Tan

unread,
Aug 16, 2018, 2:40:22 AM8/16/18
to robotframework-users
Hi I am also having this issue. i only followed the example found in the robotframework website. I am using ride ide and when i add a resource file it turns red
Reply all
Reply to author
Forward
0 new messages