Skip to content

Commit

Permalink
Changed demo to use SeleniumLibrary, minor changes to make files flak…
Browse files Browse the repository at this point in the history
…e8 compliant
  • Loading branch information
Daron Andrew Edie committed Jul 17, 2018
1 parent 322c379 commit b45c4e9
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 25 deletions.
16 changes: 8 additions & 8 deletions PageObjectLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class PageObjectLibrary(PageObjectLibraryKeywords):
*PageObjectLibrary* is a lightweight library which supports using
the page object pattern with
[http://robotframework.org/Selenium2Library/doc/Selenium2Library.html|Selenium2Library].
This library does not replace Selenium2Library; rather, it
provides a framework around which to use Selenium2Library and the
[http://robotframework.org/SeleniumLibrary/doc/SeleniumLibrary.html|SeleniumLibrary].
This library does not replace SeleniumLibrary; rather, it
provides a framework around which to use SeleniumLibrary and the
lower-level [http://selenium-python.readthedocs.org/|Python
bindings to Selenium]
Expand All @@ -32,16 +32,16 @@ class your keywords have access to the following pre-defined
attributes and methods:
| =Attribute/method= | =Description= |
| ``self.se2lib`` | A reference to the Selenium2Library instance |
| ``self.se2lib`` | A reference to the SeleniumLibrary instance |
| ``self.browser`` | A reference to the currently open browser |
| ``self.locator`` | A wrapper around the ``_locators`` dictionary |
| ``self.logger`` | A reference to the ``robot.api.logger`` instance |
| ``self._wait_for_page_refresh()`` | a context manager for doing work that causes a page refresh |
= Using Selenium2Library Keywords =
= Using SeleniumLibrary Keywords =
Within your keywords you have access to the full power of
Selenium2Library. You can use ``self.se2lib`` to access the
SeleniumLibrary. You can use ``self.se2lib`` to access the
library keywords. The following example shows how to call the
``Capture Page Screenshot`` keyword:
Expand Down Expand Up @@ -128,7 +128,7 @@ class your keywords have access to the following pre-defined
Robot can import it, just like with any other keyword
library. When you use the keyword `Go to page`, the keyword will
automatically load the keyword library and put it at the front of
the Robot Framework library search order (see
the Robot Framework library search order (see
[http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order|Set Library Search Order])
In the following example it is assumed there is a second page
Expand All @@ -137,7 +137,7 @@ class your keywords have access to the following pre-defined
| ``*** Settings ***``
| Library PageObjectLibrary
| Library Selenium2Library
| Library SeleniumLibrary
| Suite Setup Open browser http://www.example.com
| Suite Teardown Close all browsers
|
Expand Down
10 changes: 5 additions & 5 deletions PageObjectLibrary/keywords.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""PageObjectLibrary
A library to support the creation of page objects using
selenium and Seleniuim2Library.
selenium and SeleniuimLibrary.
"""
Expand Down Expand Up @@ -34,11 +34,11 @@ def se2lib(self):
# can be imported outside the context of a running
# suite (ie: by libdoc, robotframework-hub, etc)
try:
se2 = self.builtin.get_library_instance("Selenium2Library")
se2 = self.builtin.get_library_instance("SeleniumLibrary")

except RuntimeError:
self.builtin.import_library("Selenium2Library")
se2 = self.builtin.get_library_instance("Selenium2Library")
self.builtin.import_library("SeleniumLibrary")
se2 = self.builtin.get_library_instance("SeleniumLibrary")

return se2

Expand Down Expand Up @@ -94,7 +94,7 @@ def go_to_page(self, page_name, page_root=None):
The effect is the same as if you had called the following three
keywords:
| Selenium2Library.Go To http://www.example.com/login
| SeleniumLibrary.Go To http://www.example.com/login
| Import Library ExampleLoginPage
| Set Library Search Order ExampleLoginPage
Expand Down
4 changes: 2 additions & 2 deletions PageObjectLibrary/pageobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class variable PAGE_TITLE. A class can override this method if the
Classes that inherit from this class have access to the
following properties:
* se2lib a reference to an instance of Selenium2Library
* se2lib a reference to an instance of SeleniumLibrary
* browser a reference to the current webdriver instance
* logger a reference to robot.api.logger
* locator a wrapper around the page object's ``_locators`` dictionary
Expand All @@ -61,7 +61,7 @@ def __init__(self):
# test (eg: by libdoc, robotframework-hub, etc)
@property
def se2lib(self):
return BuiltIn().get_library_instance("Selenium2Library")
return BuiltIn().get_library_instance("SeleniumLibrary")

@property
def browser(self):
Expand Down
2 changes: 1 addition & 1 deletion demo/resources/HomePage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from PageObjectLibrary import PageObject


class HomePage(PageObject):
"""Keywords for the Home page of the demo app
Expand All @@ -16,4 +17,3 @@ class HomePage(PageObject):
# (eg: self.locator.username, etc)
_locators = {
}

4 changes: 3 additions & 1 deletion demo/resources/LoginPage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from PageObjectLibrary import PageObject

from robot.libraries.BuiltIn import BuiltIn


class LoginPage(PageObject):
PAGE_TITLE = "Login - PageObjectLibrary Demo"
PAGE_URL = "/login.html"
Expand All @@ -24,7 +26,7 @@ def enter_username(self, username):
"""Enter the given string into the username field"""
self.se2lib.input_text(self.locator.username, username)

def enter_password(self,password):
def enter_password(self, password):
"""Enter the given string into the password field"""
self.se2lib.input_text(self.locator.password, password)

Expand Down
12 changes: 7 additions & 5 deletions demo/resources/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import sys


class Config(object):
"""Configuration variables for this test suite
"""Configuration variables for this test suite
This creates a variable named CONFIG (${CONFIG} when included
in a test as a variable file.
in a test as a variable file.
Example:
Expand All @@ -28,11 +29,12 @@ def __init__(self):
self.demo_root = os.path.abspath(os.path.join(_here, ".."))
self.port = 8000
self.root_url = "http://localhost:%s" % self.port
self.username="test user"
self.password="password"
self.username = "test user"
self.password = "password"

def __str__(self):
return "<Config: %s>" % str(self.__dict__)



# This creates a variable that robot can see
CONFIG = Config()
2 changes: 1 addition & 1 deletion demo/tests/demo.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| Variables | ../resources/config.py
|
| Library | PageObjectLibrary
| Library | Selenium2Library
| Library | SeleniumLibrary
| Library | Process
|
| Suite Setup | Start webapp and open browser
Expand Down
8 changes: 6 additions & 2 deletions demo/webapp/demoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import SocketServer as socketserver
from urlparse import urlparse


def main():
parser = argparse.ArgumentParser(description="demo web server")
parser.add_argument("-p", "--port", type=int, default=8000, help="port number for the server (default 8000)")
Expand All @@ -27,11 +28,12 @@ def main():
try:
httpd = DemoServer(("", args.port), DemoHandler)
print("serving %s on port %s" % (docroot, 8000))
print ("^C, or visit http://localhost:%s/admin/shutdown to stop" % args.port)
print("^C, or visit http://localhost:%s/admin/shutdown to stop" % args.port)
httpd.serve_forever()
except KeyboardInterrupt:
pass


class DemoHandler(SimpleHTTPRequestHandler):

def redirect(self, uri):
Expand All @@ -50,7 +52,7 @@ def do_POST(self):
def do_GET(self):
url = urlparse(self.path)
print("url: '%s' url.path: '%s'" % (url, url.path))
if url.path == "" or url.path == "/" :
if url.path == "" or url.path == "/":
self.redirect("/login.html")

if url.path == "/authenticate":
Expand Down Expand Up @@ -79,10 +81,12 @@ def get_form_data(self):
})
return form


class DemoServer(socketserver.TCPServer):
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)


if __name__ == "__main__":
main()

0 comments on commit b45c4e9

Please sign in to comment.