Re: Help with libraries in __init__.txt file

1,036 views
Skip to first unread message

Florian Heine

unread,
Oct 23, 2012, 2:45:15 AM10/23/12
to robotframe...@googlegroups.com
Hello Kevin,

We have had very similar problems with the fact that the keywords imported into the __init__ file are not available in the test case files. This is documented functionality, if you look at the Robot user guide (section about initialisation files).

In order to get your tests to pass, you need to import your library into both test1.txt and test2.txt as the teardown is effectively run as if it was defined locally in test1.txt and test2.txt.

I am not sure why there is this restriction on not using the __init__ file to perform library imports on behalf of the entire test suite, but maybe one of the developers will be able to shed some light on that.

      Regards,
          Florian

On Monday, 22 October 2012 14:59:43 UTC+1, Kevin wrote:
Hello,

I am having a hard time figuring out why the __init__.txt does not work as I expect.

Lets say you have the following test suite:

mytestsuite
__init__.txt
test1.txt
folder
test2.txt

Both test1.txt and test2.txt contain the following testcase that does nothing more than:

*** Testcases ***
Test Foo
    Open Browser  http://www.google.nl


And  __init__.txt does not contain anything else other than:

*** Settings ***
Library  SeleniumLibrary
Test Teardown  Close Browser


Now if I do:

pybot mytestsuite

Then the test teardown is applied to all testcases in the suite. In this case, both tests will pass. 

init.jpg has a screenshot of all previous actions.

With this principle, we started making our own library, this library contains a keyword that needs to be executed as a test teardown for every test.

The context.py library contains the following code:

context = {}

def clear_context():
    context.clear()


Upon importing this library, this should give access to the Clear Context keyword.

*** Settings ***
Library  ../lib/context.py

*** Testcases ***
Test Foo
    Clear Context

This is proven by the lib.jpg screenshot. (I temporary changed test1.txt for sake of example)

Now can anyone explain to me why importing this library in the __init__.txt file, and using Clear Context as test Teardown does not work? See lib_init.jpg

Thanks for any assistance!

BR,

Kevin







Kevin de Boer

unread,
Oct 23, 2012, 3:31:46 AM10/23/12
to mar...@gmail.com, robotframe...@googlegroups.com
Hello Florian,

That indeed did the trick! I see now that I imported the seleniumLibrary on both places. Thats what made it work.

We use a resource file that should be imported in every testfile that we make. This file already imports the Selenium Library for all our test suites, so in the same way I added the context library in the resource file and now it works!

Thanks for the assist!

BR,

Kevin

On 23 October 2012 04:30, Mark Hudson <mar...@gmail.com> wrote:

Library is to be set in a Resource file, not in __init__.txt

Oddly enough, though the __init__.txt can "include" Resource files, any Library settings therein will not be propagated (but Variables will).

You need to either set the Resource file or Library file in the test suite file.
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/robotframework-users/-/_QcxD3BmalsJ.

To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

Pekka Klärck

unread,
Oct 23, 2012, 6:20:55 PM10/23/12
to mar...@gmail.com, robotframe...@googlegroups.com
2012/10/23 Mark Hudson <mar...@gmail.com>:
>
> Library is to be set in a Resource file, not in __init__.txt
>
> Oddly enough, though the __init__.txt can "include" Resource files, any
> Library settings therein will not be propagated (but Variables will).

Variables should not propagate either. If they do, that's probably a
manifestation of this bug/misfeature:
http://code.google.com/p/robotframework/issues/detail?id=532

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages