robotframework / OldSeleniumLibrary

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

Possibility to call Selenium API directly (`Call Selenium API` keyword) #74

Closed spooning closed 9 years ago

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 19 Jan 2010

The Selenium API still has a lot of functionality we don't yet expose in the SeleniumLibrary. It would be nice to have a keyword that allowed calling any method in the Selenium API directly so that all this functionality would be available. Probably something like below could do the trick:

def call_selenium_api(self, method, *args): """Calls a method in the Selenium remote controller API directly.

This keyword can be used if some functionality provided by Selenium
is not yet exposed as a keyword.

`method` is the name of the method to call in the Selenium API and
`args` specify the arguments it expects.
"""
return self._selenium.do_command(method)(args)
spooning commented 9 years ago

Originally submitted to Google Code by @yanne on 8 Feb 2010

Actually, the do_command does not do the trick, since some methods in the API do not use do_command directly.

I implemented this based on getattr, implementation is in r300. Should be reviewed. Also, would Call Selenium Method or Call Selenium Function work better as keyword name?

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 9 Feb 2010

1) Perhaps this could be implemented so that the keyword first tries to find a matching method from the Python API using getattr and, if that fails, uses do_command. Something like this:

try: method = getattr(self._selenium, method_name) except AttributeError: method = lambda _args: self._selenium.do_command(method_name, args) method(_args)

2) The current implementation catches TypeError assuming it's caused by calling the method with invalid arguments. The problem is that this potentially masks other TypeErrors and reports them incorrectly to the user. In my opinion it's better to just call the method and let it blow up if it's called incorrectly -- this is anyway a very low-level keyword and users should know what they do.

3) For some reason I like Call Selenium API more than Call Selenium Method or Call Selenium Function. Perhaps Call Selenium RC or Call Selenium Remote Controller would be OK too.

spooning commented 9 years ago

Originally submitted to Google Code by @yanne on 10 Feb 2010

I revised the implementation in r335 and r336.

Do we need to document the differences in calling a remote control method with underscore_name and calling do_command with camelCase name? The former returns always formatted result whereas the latter returns raw result in the form 'STATUS,response'

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 11 Feb 2010

I think the different "call modes" needs to be documented but not on very low level. Perhaps something like this:

"""The keyword first tries to find a method in Selenium's Python API provided by the selenium.py file. If no matching method is found, the keyword calls the Selenium Server's Remote Controller API directly via the do_command method in the Python API. In both cases the keyword returns the return value of the call directly without any modifications or verifications.

Examples: ..."""

spooning commented 9 years ago

Originally submitted to Google Code by @yanne on 11 Feb 2010

Updated doc in r351