selenium2library standalone usage

404 views
Skip to first unread message

alans09

unread,
Jun 7, 2014, 1:36:34 PM6/7/14
to robotframe...@googlegroups.com
hi all...


 I'm trying to write test library in python. In order to do this.. i need some of functionalities of selenium2library.

When I'm try to import  something like:

robot.libraries.selenium2library it does not work .... 
but  i can import :
import Selenium2Library

but I can't find out how to use keywords from them to:
I can do something like:


#-*- coding: utf-8 -*-
import Selenium2Library


print dir(Selenium2Library)
x = Selenium2Library.keywords._BrowserManagementKeywords()
print dir(x)
x.open_browser("http://google.sk")


when I try to do this  all is ok, but 
x.open_browser("http://google.sk")  i get:

Traceback (most recent call last):
  File "firewall.py", line 9, in <module>
    x.open_browser("http://google.sk")
  File "<string>", line 2, in open_browser
  File "C:\Python27\lib\site-packages\robotframework_selenium2library-1.5.0-py2.
7.egg\Selenium2Library\keywords\keywordgroup.py", line 12, in _run_on_failure_de
corator
    return method(*args, **kwargs)
  File "C:\Python27\lib\site-packages\robotframework_selenium2library-1.5.0-py2.
7.egg\Selenium2Library\keywords\_browsermanagement.py", line 111, in open_browse
r
    self._info("Opening browser '%s' to base url '%s'" % (browser, url))
AttributeError: '_BrowserManagementKeywords' object has no attribute '_info'


How can I use keywords from this library in python?

alans09

unread,
Jun 7, 2014, 1:41:19 PM6/7/14
to robotframe...@googlegroups.com
I also tried:
#-*- coding: utf-8 -*-
import Selenium2Library
from robot.libraries.BuiltIn import BuiltIn


x = BuiltIn().run_keyword('Open Browser', 'http://google.sk', 'firefox')

but from this I got error:

Traceback (most recent call last):
  File "firewall.py", line 5, in <module>
    x = BuiltIn().run_keyword('Open Browser', 'http://google.sk', 'firefox')
  File "C:\Python27\lib\site-packages\robot\libraries\BuiltIn.py", line 1197, in
 run_keyword
    return kw.run(self._context)
  File "C:\Python27\lib\site-packages\robot\running\keywords.py", line 103, in r
un
    handler = self._start(context)
  File "C:\Python27\lib\site-packages\robot\running\keywords.py", line 117, in _
start
    handler = context.get_handler(self.handler_name)
AttributeError: 'NoneType' object has no attribute 'get_handler'

Tatu Aalto

unread,
Jun 8, 2014, 8:00:02 AM6/8/14
to robotframe...@googlegroups.com
Ugh

Selenium2Library is not part of Robot Framework core, it is separate Python library. Therefore import robot.libraries.selenium2library does not work and import selenium2library works. But in any case, could you tell what you want to do and perhaps we could direct you on the right course. Because, in my experiense, the situation where I can not do it by the Selenium2Library are quite rare.

-Tatu
--
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.

alans09

unread,
Jun 8, 2014, 2:46:30 PM6/8/14
to robotframe...@googlegroups.com
Yes, I know that is not part of core. But... for example you can use any remote robot framework library and it is not part of core either. 
eg.  BuiltIn.Remote() 

What I want to achieve?


I just want to make python script that is able to:
1) use remote library of my own.... -> this is working with no problem (library is used for win applications)
2) use selenium2library for testing of web application on remote machine

I can do this by using robot framework , and robot framework files with ease... but what I want is to create python file that will be able to do the same, but without using robot framework syntax  (text files)


Easy testcase I want to reproduce is:

1) Turn of antivirus firewall (this is done by remote library)
2) Close antivirus  (remote library)
3) open browser  and navigate to www.eicar.com  (selenium2library)
4) try to download eicar file   (selenium2library)
5) close browser (selenium2library)
6) Open antivirus and check if it is logged  (remote library)

Setup is this:
a) I have server, where is robot framework installed, and selenium server with role HUB... and from where all scripts are ran.   
b) I have client, where remote library is installed and started   and selenium server in mode  NODE connected to HUB

As I said I can perfectly do this with robot files  (text files with robot syntax)  but I want to achieve the same result just by using python and robot libraries.  I can use remote library in pure python, but not Selenium2Library.  Below is robot testcase that I am using to achieve steps above.


---------------------------------------- robot file (just part of it, that is doing what i want)
*** Settings ***
Library    Remote    http://10.1.1.1:4223  
Library    Selenium2Library


*** Test cases ***
Part of testcase to use remote execution of windows application and browser
    Remote.Run Application     ${antivirus}
    Start firewall in application
    Remote.Close Applicatoin    ${antivirus}
    Open Browser    http://www.eicar.com    firefox    remote_url=10.1.1.3:4444/wd/hub 
    Click Link    xpath=//a[@href='/eicar/download']  
    Close All Browsers
    Remote.Run Application    ${antivirus}
    Check of log files in application
    Remote.Close Application    ${antivirus}

-----------------------------------------------------------------------

Problem is as i wrote in my first posts. I just can't call any Selenium2Library methods standalone. Or am I missing something?



To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Tatu Aalto

unread,
Jun 8, 2014, 4:27:03 PM6/8/14
to robotframe...@googlegroups.com
Ugh

Remote library is part of the core Robot Framework [1], remote servers [2] although are not part of core Robot Framework.

But in any case, if you just want to run browser on remote machine, there is allready tools for you wihtout coding a line. If you look "Open Browser"-keyword documentation [3], there are parameters called: remote_url and desired_capabilities. Which are in my opinion, hmmm, not so well documeted in Selenium2Library. But setting and using the selenium remote server is better documented on selenium side, so reading selenium documents [4] [5] will give you better description what you need to insert on those parameters.

-Tatu
[1] http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.4#remote-library
[2] https://code.google.com/p/robotframework/wiki/RemoteLibrary#Available_remote_servers
[3] http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Open%20Browser
[4] https://code.google.com/p/selenium/wiki/Grid2
[5] https://code.google.com/p/selenium/wiki/DesiredCapabilities
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

Tatu Aalto

unread,
Jun 8, 2014, 4:58:35 PM6/8/14
to robotframe...@googlegroups.com
Ugh

And I am sorry, for not rearing your mail carefully enough. Just ignore previous mail.

Calling Selenium2Library over the Remote Server. As far I can recall, or find from user group, no-one has done it, or even tried.

All the others, including me, have setteled with Selenium remote server. In this case, I do not need install Selenium2Library in all the remote servers, just downlaod&run the jar file and one is ready to roll. And I mask the usage of the Selenium remote server behind a user definde keyword, that hides the complexity of the setup from 90% of the cases. 

But in any case, I can not help you on the matter, perhaps someone with more experience with Selenium2Library code base could know better.

-Tatu

David

unread,
Jun 8, 2014, 8:54:37 PM6/8/14
to robotframe...@googlegroups.com
Adding to what Tatu said. If you're not wanting to use RF, just custom remote library (using the RF Python remote server as a base to serve the library with), and Selenium outside RF, then why do you need or want to use Selenium2Library? Because you like the keywords/API it exposes?

I ask this because you can get more customization and greater free form use by just using Selenium Python bindings/API, you only need Selenium2Library in your case if you loved some particular keyword(s) in the library that are not available or more work to do in native Selenium Python API. Or are you trying to have a bridge/fallback point where you can easily switch to full use of RF (instead of pure Python) later on if you had a need and thus want to stick with Selenium2Library?

alans09

unread,
Jun 9, 2014, 2:28:55 AM6/9/14
to robotframe...@googlegroups.com
I want to use Selenium2Library because of it has some nice keywords.
Of course I can do all of that keywords by myself just by using selenium bindings. The question is why to reinvent the wheel when it is already done?

If I use S2L there is also easier way how to go from python to RF again. 
But it looks like it is not possible... or not by the easy way 

Janne Härkönen

unread,
Jun 9, 2014, 3:00:31 AM6/9/14
to ala...@gmail.com, robotframework-users
Hi,


On Sat, Jun 7, 2014 at 8:36 PM, alans09 <ala...@gmail.com> wrote:
hi all...


 I'm trying to write test library in python. In order to do this.. i need some of functionalities of selenium2library.

When I'm try to import  something like:

robot.libraries.selenium2library it does not work .... 
but  i can import :
import Selenium2Library

but I can't find out how to use keywords from them to:
I can do something like:


#-*- coding: utf-8 -*-
import Selenium2Library


print dir(Selenium2Library)
x = Selenium2Library.keywords._BrowserManagementKeywords()
print dir(x)
x.open_browser("http://google.sk")


Can you create an instance of the top level Selenium2Library? i.e. something like:

lib = Selenium2Library. Selenium2Library()
lib.open_browser()

Selenium2Library uses multiple inheritance quite sneakily, and you cannot instantiate the individual classes independently.

hth,

--Janne

Kevin O.

unread,
Jun 9, 2014, 1:00:29 PM6/9/14
to robotframe...@googlegroups.com
If you want to use Selenium2Library from a Python library, that works well. You do not need to instantiate the library or even import the class.

s2l = BuiltIn().get_library_instance('Selenium2Library')

Then you can do:
s2l.click_link('foo')
etc.

Using Selenium2Library outside a test run does not work completely - the on failure mechanism depends on RF execution. There is more detail in this enhancement request:

Outside RF, you can do what Janne suggested.

Gilles Lenfant

unread,
Aug 6, 2014, 3:33:20 PM8/6/14
to robotframe...@googlegroups.com


Le samedi 7 juin 2014 19:36:34 UTC+2, alans09 a écrit :
hi all...


 I'm trying to write test library in python. In order to do this.. i need some of functionalities of selenium2library.



If you want to test Web sites in plain Python (say unittest based tests) it will be easier to use splinter than hacking Selenium2Library : http://splinter.cobrateam.info/

Reply all
Reply to author
Forward
0 new messages