Skip to content

Commit 6e02b5e

Browse files
authored
New extending documentation (#1368)
More documentation in a new place.
1 parent 9b06578 commit 6e02b5e

File tree

14 files changed

+612
-165
lines changed

14 files changed

+612
-165
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from robot.api import logger
2+
from selenium.webdriver.support.events import AbstractEventListener
3+
4+
5+
class MyListener(AbstractEventListener):
6+
7+
def before_navigate_to(self, url, driver):
8+
logger.info("Before navigate to %s" % url)
9+
10+
def after_navigate_to(self, url, driver):
11+
logger.info("After navigate to %s" % url)
12+
13+
def before_click(self, element, driver):
14+
logger.info("Before click")
15+
16+
def after_click(self, element, driver):
17+
logger.info("After click")
18+
19+
def before_change_value_of(self, element, driver):
20+
logger.info("Before clear and send_keys")
21+
22+
def after_change_value_of(self, element, driver):
23+
logger.info("After clear and send_keys")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*** Settings ***
2+
Library SeleniumLibrary event_firing_webdriver=${CURDIR}/MyListener.py
3+
Suite Teardown Close All Browsers
4+
5+
*** Variables ***
6+
${URL} https://github.com/robotframework/SeleniumLibrary
7+
${ISSUES} ${URL}/issues
8+
${BROWSER} Chrome
9+
10+
*** Test Cases ***
11+
Open Browser To Start Page
12+
Open Browser ${URL} ${BROWSER}
13+
14+
Event Firing Webdriver Go To (WebDriver)
15+
Go To ${ISSUES}
16+
17+
Event Firing Webdriver Click Element (WebElement)
18+
Click Element js-issues-search
19+
20+
Event Firing Webdriver Input Text (WebElement)
21+
Input Text js-issues-search FooBar
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
EventFiringWebDriver
2+
====================
3+
4+
This example demonstrates the EventFiringWenDriver support. The MyListener.py
5+
does only log before and after the Selenium API call. But MyListener.py
6+
could make new Selenium API calls or anything else which is possible from the Python.
7+
8+
To run the example, give command::
9+
10+
robot event_firing_webdriver.robot
11+
12+
From the generated log.html, in the keywords logging, look at logging.
13+
The lines starting "Before " and "After " are from the EventFiringWenDriver.
14+
15+
See `Robot Framework test suite`_ and `EventFiringWebDriver class`_ for further details.
16+
17+
.. _Robot Framework test suite: https://github.com/robotframework/SeleniumLibrary/blob/master/docs/extending/event_firing_webdriver/event_firing_webdriver.robot
18+
.. _EventFiringWebDriver class: https://github.com/robotframework/SeleniumLibrary/blob/master/docs/extending/event_firing_webdriver/MyListener.py
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from SeleniumLibrary import SeleniumLibrary
2+
from SeleniumLibrary.base import keyword, LibraryComponent
3+
from SeleniumLibrary.keywords import BrowserManagementKeywords
4+
5+
6+
class BrowserKeywords(LibraryComponent):
7+
8+
def __init__(self, ctx):
9+
LibraryComponent.__init__(self, ctx)
10+
11+
@keyword
12+
def open_browser(self, host):
13+
url = 'http://{}.com/'.format(host)
14+
browser_management = BrowserManagementKeywords(self.ctx)
15+
browser_management.open_browser(url, 'chrome')
16+
17+
18+
class DesiredCapabilitiesKeywords(LibraryComponent):
19+
20+
def __init__(self, ctx):
21+
LibraryComponent.__init__(self, ctx)
22+
23+
@keyword
24+
def get_browser_desired_capabilities(self):
25+
self.info('Getting currently open browser desired capabilities')
26+
return self.driver.desired_capabilities
27+
28+
29+
class Decomposition(SeleniumLibrary):
30+
31+
def __init__(self, timeout=5.0, implicit_wait=0.0,
32+
run_on_failure='Capture Page Screenshot',
33+
screenshot_root_directory=None):
34+
SeleniumLibrary.__init__(self, timeout=timeout, implicit_wait=implicit_wait,
35+
run_on_failure=run_on_failure,
36+
screenshot_root_directory=screenshot_root_directory)
37+
self.add_library_components([BrowserKeywords(self),
38+
DesiredCapabilitiesKeywords(self)])
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*** Settings ***
2+
Library ./Decomposition.py
3+
4+
*** Test Cases ***
5+
Decomposition Example
6+
Open Browser google
7+
${capabilities} = Get Browser Desired Capabilities
8+
Log ${capabilities}
9+
[Teardown] Close Browser
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from robot.api import logger
2+
from robot.libraries.BuiltIn import BuiltIn
3+
4+
5+
def open_browser(host):
6+
url = 'http://{}.com/'.format(host)
7+
sl = BuiltIn().get_library_instance('SeleniumLibrary')
8+
sl.open_browser(url, 'chrome')
9+
10+
11+
def get_browser_desired_capabilities():
12+
logger.info('Getting currently open browser desired capabilities')
13+
sl = BuiltIn().get_library_instance('SeleniumLibrary')
14+
return sl.driver.desired_capabilities
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*** Settings ***
2+
Library SeleniumLibrary
3+
Library ./GetSeleniumLibraryInstance.py
4+
5+
*** Test Cases ***
6+
Use InheritSeleniumLibrary Open Browser Keyword
7+
GetSeleniumLibraryInstance.Open Browser google
8+
${capabilities} = GetSeleniumLibraryInstance.Get Browser Desired Capabilities
9+
Log ${capabilities}
10+
[Teardown] Close Browser
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from robot.api import logger
2+
from SeleniumLibrary import SeleniumLibrary
3+
from SeleniumLibrary.base import keyword
4+
from SeleniumLibrary.keywords import BrowserManagementKeywords
5+
6+
7+
class InheritSeleniumLibrary(SeleniumLibrary):
8+
9+
@keyword
10+
def open_browser(self, host):
11+
url = 'http://{}.com/'.format(host)
12+
browser_management = BrowserManagementKeywords(self)
13+
browser_management.open_browser(url, 'chrome')
14+
15+
@keyword
16+
def get_browser_desired_capabilities(self):
17+
logger.info('Getting currently open browser desired capabilities')
18+
return self.driver.desired_capabilities
19+
20+
def not_keywords_but_public_methods(self):
21+
logger.info('Python public method not a keyword, because it is not '
22+
'decorated with @keyword decorator')
23+
24+
def _private_method_are_not_keywords(self):
25+
logger.info('Python private method is not a keyword, because it is not '
26+
'decorated with @keyword decorator')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*** Settings ***
2+
Library ./InheritSeleniumLibrary.py
3+
4+
*** Test Cases ***
5+
Use InheritSeleniumLibrary Open Browser Keyword
6+
Open Browser google
7+
${capabilities} = Get Browser Desired Capabilities
8+
Log ${capabilities}
9+
[Teardown] Close Browser

0 commit comments

Comments
 (0)