bs00336332 / robotframework-seleniumlibrary

Automatically exported from code.google.com/p/robotframework-seleniumlibrary
Apache License 2.0
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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/de2231f
3aebb3268

Original issue reported on code.google.com by ovuaia...@gmail.com on 25 Jul 2011 at 10:01

GoogleCodeExporter commented 9 years ago
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.    

Original comment by pekka.klarck on 25 Jul 2011 at 10:38

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

Original comment by janne.t....@gmail.com on 8 Aug 2011 at 7:03

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 13fc61e3a3d2.

Original comment by janne.t....@gmail.com on 8 Aug 2011 at 7:56

GoogleCodeExporter commented 9 years ago

Original comment by janne.t....@gmail.com on 8 Aug 2011 at 11:51

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
{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}

Original comment by seanogoc...@gmail.com on 12 Jul 2012 at 12:03

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Above is an example of this working. (Well kind of, there is a typo or two)  
Ex. the closing bracket after yahoo.com"

Original comment by seanogoc...@gmail.com on 12 Jul 2012 at 12:05