robotframework / OldSeleniumLibrary

Deprecated Selenium library for Robot Framework
Apache License 2.0
13 stars 3 forks source link

Add a public member of the selenium instance to SeleniumLibrary #200

Closed spooning closed 9 years ago

spooning commented 9 years ago

Originally submitted to Google Code by ovuaia... on 25 Jul 2011

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

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 25 Jul 2011

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.

spooning commented 9 years ago

Originally submitted to Google Code by @yanne on 8 Aug 2011

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

spooning commented 9 years ago

Originally submitted to Google Code by @yanne on 8 Aug 2011

This issue was updated by revision 13fc61e3a3d2.

spooning commented 9 years ago

Originally submitted to Google Code by seanogoconaire on 12 Jul 2012

{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}

spooning commented 9 years ago

Originally submitted to Google Code by seanogoconaire on 12 Jul 2012

Above is an example of this working. (Well kind of, there is a typo or two) Ex. the closing bracket after yahoo.com"