How to execute Selenium2Library keywords from Python interactive shell?

427 views
Skip to first unread message

Tset Noitamotua

unread,
Nov 9, 2015, 5:50:50 AM11/9/15
to robotframework-users
Hi guys!

Is it possible to execute Selenium2Library (S2L) keywords from Python iteractive shell? I am getting an error when I try:

>>> from robot.libraries.BuiltIn import BuiltIn
>>> s2l = BuiltIn().get_library_instance('Selenium2Library')

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    s2l = BuiltIn().get_library_instance('Selenium2Library')
  File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 2922, in get_library_instance
    return self._namespace.get_library_instance(name)
  File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 70, in _namespace
    return self._context.namespace
  File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 65, in _context
    raise RobotNotRunningError('Cannot access execution context')
RobotNotRunningError: Cannot access execution context

Cheers
Tset


Ed Manlove

unread,
Nov 9, 2015, 6:11:03 AM11/9/15
to robotframe...@googlegroups.com
You can but the method you are using, going straight into Selenium2Library without instantiating robot first, will not work; at least that is my guess from the two lines you've shown and the error message. You can put in pdb set_trace line to jump into the python debugger. Try placing the following line in the code ( somewhere down C:\Python27\lib\site-packages\Selenium2Library or ..\robot) to start the debugger

    import pdb,sys; pdb.Pdb(stdout=sys.__stdout__).set_trace()

(see [1] for a little more information). There should be a set of lines that "start robot" and then allow you to do what you are trying above but can't think of them of the top of my head. Try taking a look at the test runner within the Selenium2Library [2].

Ed

[1] https://github.com/robotframework/Selenium2Library/blob/master/BUILD.rst#debugging-selenium2library
[2] https://github.com/robotframework/Selenium2Library/blob/master/test/run_tests.py

Tset Noitamotua

unread,
Nov 13, 2015, 10:35:26 AM11/13/15
to robotframework-users
@Ed: Thanx for reply!

Could you (or some one else) please provide some more detailed steps. I did not get where to place this peace of code:

 import pdb,sys; pdb.Pdb(stdout=sys.__stdout__).set_trace()

Cheers
Tset

Tatu Aalto

unread,
Nov 13, 2015, 10:41:04 AM11/13/15
to Wladislaw Wagner, robotframework-users

Ugh

The answers depends, to your original question, do you want to run S2L functions, when RF is running or do you want to run S2L functions when RF is not running? Both of them are possible, but requires quite different setup.

-Tatu
Send from my mobile

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Tset Noitamotua

unread,
Nov 13, 2015, 4:41:18 PM11/13/15
to robotframework-users
I tried to use robotframework-debuglibrary[1] as Robot Framework Shell (rfshell) but I`m getting following error:

> import library  Selenium2Library
< keyword: import library  Selenium2Library
! Importing test library 'Selenium2Library' failed: ImportError: cannot import name GLOBAL_VARIABLES

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\Selenium2Library\__init__.py", line 2, in <module>
    from keywords import *
  File "C:\Python27\lib\site-packages\Selenium2Library\keywords\__init__.py", line 1, in <module>
    from _logging import _LoggingKeywords
  File "C:\Python27\lib\site-packages\Selenium2Library\keywords\_logging.py", line 3, in <module>
    from robot.variables import GLOBAL_VARIABLES
PYTHONPATH:
  C:\Python27\Scripts
  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
  C:\Python27\lib\site-packages\win32
  C:\Python27\lib\site-packages\win32\lib
  C:\Python27\lib\site-packages\Pythonwin
  C:\Python27\lib\site-packages\wx-2.8-msw-unicode
>

[1] https://github.com/xyb/robotframework-debuglibrary

Tset Noitamotua

unread,
Nov 13, 2015, 5:56:33 PM11/13/15
to robotframework-users
UPDATE: This error happens only with outdated Selenim2Library 1.6.0!
No problem after updating S2L 1.7.4

Cheers
Tset

Tset Noitamotua

unread,
Nov 14, 2015, 1:07:01 PM11/14/15
to robotframework-users
What I found out so far:
One possibility to execute Selenium2Library from Python Interactive Shell is by using the 'robotframework-debuglibrary' which you can find on Github:



1. pip install robotframework-debuglibrary
2. pip install pyreadline
3. Open CMD / Shell and call rfshell
4. Now you can use Robot Framework keywords interactively from the shell
5. e.g. Import Library  Selenium2Library (NOTE: put at least to spaces between keywords and arguments)
6. Now you can use all Selenium2Library keywords interactively from the shell
7. e.g. Open Browser   http://www.google.com   Chrome
8. Be happy!



Cheers
Tset

Am Montag, 9. November 2015 11:50:50 UTC+1 schrieb Tset Noitamotua:
Reply all
Reply to author
Forward
0 new messages