Issue 200 in robotframework-seleniumlibrary: Add a public member of the selenium instance to SeleniumLibrary

5 views
Skip to first unread message

robotframework-...@googlecode.com

unread,
Jul 25, 2011, 6:01:39 PM7/25/11
to robotframework-se...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Enhancement Priority-Medium

New issue 200 by ovuaia...@gmail.com: Add a public member of the selenium
instance to SeleniumLibrary
http://code.google.com/p/robotframework-seleniumlibrary/issues/detail?id=200

When there is complex logic involved in the implementation of keywords
for selenium driven in-browser testing, (and perhaps you need to
access selenium api functions not implemented as SeleniumLibrary
keywords) a good practice is to implement those keywords directly in
python.

In such a case it makes a whole lot of sense (i.e. it is more
convenient and in most cases more elegant) to interact directly with
the underlying selenium object instance.

So instead of the following code :-
from robot.libraries.BuiltIn import BuiltIn
def title_should_start_with(expected):
seleniumlib = BuiltIn().get_library_instance('SeleniumLibrary')
xml_data =
seleniumlib.call_selenium_api('captureNetworkTraffic','xml')
# do something useful with xml_data
title = seleniumlib.get_title()
if not title.startswith(expected):
raise AssertionError("Title '%s' did not start with '%s'"
% (title, expected))
you could have the following code snippet which uses the private
selenium member object ('_selenium') of the SeleniumLibrary instance
directly:-
from robot.libraries.BuiltIn import BuiltIn
def title_should_start_with(expected):
seleniumlib = BuiltIn().get_library_instance('SeleniumLibrary')
seleniumobj = seleniumlib._selenium
xml_data = seleniumobj.captureNetworkTraffic('xml')
# do something useful with xml_data
title = seleniumobj.get_title() #calling get_title directly on
the _selenium instance
if not title.startswith(expected):
raise AssertionError("Title '%s' did not start with '%s'"
% (title, expected))
This alternate approach would require that the ._selenium member
object of the robotframework SeleniumLibrary instance be always
available through subsequent releases.

But it may be more pythonic for the SeleniumLibrary API to explicitly
provide a public reference to the _selenium private member.

Please see the following URL where this was earlier discussed :-

http://groups.google.com/group/robotframework-users/browse_thread/thread/de2231f3aebb3268

robotframework-...@googlecode.com

unread,
Jul 25, 2011, 6:39:40 PM7/25/11
to robotframework-se...@googlegroups.com
Updates:
Status: Accepted

Comment #1 on issue 200 by pekka.klarck: Add a public member of the

It's a good idea we expose the active Selenium instance either as `se` or
`selenium` attribute. We can change the library itself to use that too, but
we need to keep the old `_selenium` around for backwards compatibility.

robotframework-...@googlecode.com

unread,
Aug 8, 2011, 3:04:20 AM8/8/11
to robotframework-se...@googlegroups.com
Updates:
Status: Started
Owner: janne.t.harkonen

Comment #2 on issue 200 by janne.t.harkonen: Add a public member of the

I think I'll go with `selenium` as the property name since it is not too
long to be cumbersome.

robotframework-...@googlecode.com

unread,
Aug 8, 2011, 3:57:35 AM8/8/11
to robotframework-se...@googlegroups.com
Updates:
Status: Done

Comment #3 on issue 200 by janne.t.harkonen: Add a public member of the

This issue was updated by revision 13fc61e3a3d2.

robotframework-...@googlecode.com

unread,
Aug 8, 2011, 7:52:30 AM8/8/11
to robotframework-se...@googlegroups.com
Updates:
Labels: Target-2.8

Comment #4 on issue 200 by janne.t.harkonen: Add a public member of the

(No comment was entered for this change.)

robotframework-...@googlecode.com

unread,
Jul 12, 2012, 7:54:18 AM7/12/12
to robotframework-se...@googlegroups.com

Comment #5 on issue 200 by seanogoc...@gmail.com: Add a public member of
Any chance we could get a example for this?

robotframework-...@googlecode.com

unread,
Jul 12, 2012, 8:03:29 AM7/12/12
to robotframework-se...@googlegroups.com

Comment #6 on issue 200 by seanogoc...@gmail.com: Add a public member of
{code}
*** Settings ***
Documentation use selenium property so python can access the instance
Library SeleniumLibrary
Library WebKeywordLibrary

*** Test Cases ***
Call Python Keyword and Python Keyword to do Selenium Action
[Tags] psel
Start Selenium Server
Open Browser http://www.google.com firefox ${EMPTY}
WebKeywordLibrary.Do_Selenium_Action
{code}

{code}
import selenium
from robot.libraries.BuiltIn import BuiltIn

class WebKeywordLibrary:

def Do_Selenium_Action(self):
seleniumlib = BuiltIn().get_library_instance('SeleniumLibrary')
print dir(seleniumlib)
self.selenium = seleniumlib.selenium
self.selenium.open("http://www.yahoo.com")
{code}

robotframework-...@googlecode.com

unread,
Jul 12, 2012, 8:04:29 AM7/12/12
to robotframework-se...@googlegroups.com

Comment #7 on issue 200 by seanogoc...@gmail.com: Add a public member of
Above is an example of this working.

robotframework-...@googlecode.com

unread,
Jul 12, 2012, 8:05:29 AM7/12/12
to robotframework-se...@googlegroups.com

Comment #8 on issue 200 by seanogoc...@gmail.com: Add a public member of
Above is an example of this working. (Well kind of, there is a typo or
two) Ex. the closing bracket after yahoo.com"

Reply all
Reply to author
Forward
0 new messages