Skip to content

Commit b45c4e9

Browse files
author
Daron Andrew Edie
committed
Changed demo to use SeleniumLibrary, minor changes to make files flake8 compliant
1 parent 322c379 commit b45c4e9

File tree

8 files changed

+33
-25
lines changed

8 files changed

+33
-25
lines changed

PageObjectLibrary/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class PageObjectLibrary(PageObjectLibraryKeywords):
1313
1414
*PageObjectLibrary* is a lightweight library which supports using
1515
the page object pattern with
16-
[http://robotframework.org/Selenium2Library/doc/Selenium2Library.html|Selenium2Library].
17-
This library does not replace Selenium2Library; rather, it
18-
provides a framework around which to use Selenium2Library and the
16+
[http://robotframework.org/SeleniumLibrary/doc/SeleniumLibrary.html|SeleniumLibrary].
17+
This library does not replace SeleniumLibrary; rather, it
18+
provides a framework around which to use SeleniumLibrary and the
1919
lower-level [http://selenium-python.readthedocs.org/|Python
2020
bindings to Selenium]
2121
@@ -32,16 +32,16 @@ class your keywords have access to the following pre-defined
3232
attributes and methods:
3333
3434
| =Attribute/method= | =Description= |
35-
| ``self.se2lib`` | A reference to the Selenium2Library instance |
35+
| ``self.se2lib`` | A reference to the SeleniumLibrary instance |
3636
| ``self.browser`` | A reference to the currently open browser |
3737
| ``self.locator`` | A wrapper around the ``_locators`` dictionary |
3838
| ``self.logger`` | A reference to the ``robot.api.logger`` instance |
3939
| ``self._wait_for_page_refresh()`` | a context manager for doing work that causes a page refresh |
4040
41-
= Using Selenium2Library Keywords =
41+
= Using SeleniumLibrary Keywords =
4242
4343
Within your keywords you have access to the full power of
44-
Selenium2Library. You can use ``self.se2lib`` to access the
44+
SeleniumLibrary. You can use ``self.se2lib`` to access the
4545
library keywords. The following example shows how to call the
4646
``Capture Page Screenshot`` keyword:
4747
@@ -128,7 +128,7 @@ class your keywords have access to the following pre-defined
128128
Robot can import it, just like with any other keyword
129129
library. When you use the keyword `Go to page`, the keyword will
130130
automatically load the keyword library and put it at the front of
131-
the Robot Framework library search order (see
131+
the Robot Framework library search order (see
132132
[http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order|Set Library Search Order])
133133
134134
In the following example it is assumed there is a second page
@@ -137,7 +137,7 @@ class your keywords have access to the following pre-defined
137137
138138
| ``*** Settings ***``
139139
| Library PageObjectLibrary
140-
| Library Selenium2Library
140+
| Library SeleniumLibrary
141141
| Suite Setup Open browser http://www.example.com
142142
| Suite Teardown Close all browsers
143143
|

PageObjectLibrary/keywords.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""PageObjectLibrary
22
33
A library to support the creation of page objects using
4-
selenium and Seleniuim2Library.
4+
selenium and SeleniuimLibrary.
55
66
77
"""
@@ -34,11 +34,11 @@ def se2lib(self):
3434
# can be imported outside the context of a running
3535
# suite (ie: by libdoc, robotframework-hub, etc)
3636
try:
37-
se2 = self.builtin.get_library_instance("Selenium2Library")
37+
se2 = self.builtin.get_library_instance("SeleniumLibrary")
3838

3939
except RuntimeError:
40-
self.builtin.import_library("Selenium2Library")
41-
se2 = self.builtin.get_library_instance("Selenium2Library")
40+
self.builtin.import_library("SeleniumLibrary")
41+
se2 = self.builtin.get_library_instance("SeleniumLibrary")
4242

4343
return se2
4444

@@ -94,7 +94,7 @@ def go_to_page(self, page_name, page_root=None):
9494
The effect is the same as if you had called the following three
9595
keywords:
9696
97-
| Selenium2Library.Go To http://www.example.com/login
97+
| SeleniumLibrary.Go To http://www.example.com/login
9898
| Import Library ExampleLoginPage
9999
| Set Library Search Order ExampleLoginPage
100100

PageObjectLibrary/pageobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class variable PAGE_TITLE. A class can override this method if the
3434
Classes that inherit from this class have access to the
3535
following properties:
3636
37-
* se2lib a reference to an instance of Selenium2Library
37+
* se2lib a reference to an instance of SeleniumLibrary
3838
* browser a reference to the current webdriver instance
3939
* logger a reference to robot.api.logger
4040
* locator a wrapper around the page object's ``_locators`` dictionary
@@ -61,7 +61,7 @@ def __init__(self):
6161
# test (eg: by libdoc, robotframework-hub, etc)
6262
@property
6363
def se2lib(self):
64-
return BuiltIn().get_library_instance("Selenium2Library")
64+
return BuiltIn().get_library_instance("SeleniumLibrary")
6565

6666
@property
6767
def browser(self):

demo/resources/HomePage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from PageObjectLibrary import PageObject
22

3+
34
class HomePage(PageObject):
45
"""Keywords for the Home page of the demo app
56
@@ -16,4 +17,3 @@ class HomePage(PageObject):
1617
# (eg: self.locator.username, etc)
1718
_locators = {
1819
}
19-

demo/resources/LoginPage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from PageObjectLibrary import PageObject
2+
23
from robot.libraries.BuiltIn import BuiltIn
34

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

27-
def enter_password(self,password):
29+
def enter_password(self, password):
2830
"""Enter the given string into the password field"""
2931
self.se2lib.input_text(self.locator.password, password)
3032

demo/resources/config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
import sys
33

4+
45
class Config(object):
5-
"""Configuration variables for this test suite
6+
"""Configuration variables for this test suite
67
78
This creates a variable named CONFIG (${CONFIG} when included
8-
in a test as a variable file.
9+
in a test as a variable file.
910
1011
Example:
1112
@@ -28,11 +29,12 @@ def __init__(self):
2829
self.demo_root = os.path.abspath(os.path.join(_here, ".."))
2930
self.port = 8000
3031
self.root_url = "http://localhost:%s" % self.port
31-
self.username="test user"
32-
self.password="password"
32+
self.username = "test user"
33+
self.password = "password"
3334

3435
def __str__(self):
3536
return "<Config: %s>" % str(self.__dict__)
36-
37+
38+
3739
# This creates a variable that robot can see
3840
CONFIG = Config()

demo/tests/demo.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| Variables | ../resources/config.py
66
|
77
| Library | PageObjectLibrary
8-
| Library | Selenium2Library
8+
| Library | SeleniumLibrary
99
| Library | Process
1010
|
1111
| Suite Setup | Start webapp and open browser

demo/webapp/demoserver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import SocketServer as socketserver
1616
from urlparse import urlparse
1717

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

36+
3537
class DemoHandler(SimpleHTTPRequestHandler):
3638

3739
def redirect(self, uri):
@@ -50,7 +52,7 @@ def do_POST(self):
5052
def do_GET(self):
5153
url = urlparse(self.path)
5254
print("url: '%s' url.path: '%s'" % (url, url.path))
53-
if url.path == "" or url.path == "/" :
55+
if url.path == "" or url.path == "/":
5456
self.redirect("/login.html")
5557

5658
if url.path == "/authenticate":
@@ -79,10 +81,12 @@ def get_form_data(self):
7981
})
8082
return form
8183

84+
8285
class DemoServer(socketserver.TCPServer):
8386
def server_bind(self):
8487
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
8588
self.socket.bind(self.server_address)
8689

90+
8791
if __name__ == "__main__":
8892
main()

0 commit comments

Comments
 (0)