Skip to content

Commit 3d63e35

Browse files
committed
Merge pull request robotframework#113 from emanlove/rf-s2l-documentation
Looks good to me. THanks guys. :)
2 parents 4b36772 + 1fb23e7 commit 3d63e35

File tree

5 files changed

+164
-14
lines changed

5 files changed

+164
-14
lines changed

BUILD.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,96 @@ To run just the unit tests, run::
6464
python test/run_unit_tests.py
6565

6666

67+
Testing Third-Party Packages
68+
----------------------------
69+
70+
Sometimes in the process of developing and testing Selenium2Library
71+
one needs to determine whether or not an issue is within Selenium2Library
72+
or if it lies within a third-party package like Selenium or Robot Framework.
73+
Here are some hints for writing quick, short unit tests against Selenium
74+
and Robot Framework.
75+
76+
Testing Selenium
77+
~~~~~~~~~~~~~~~~
78+
First create a test directory and create an isolated Python environment
79+
using virtualenv::
80+
81+
~$ mkdir se-bug
82+
~$ cd se-bug
83+
~/se-bug$ virtualenv -p /usr/bin/python2.6 --no-site-packages clean-python26-env
84+
85+
Activate the virtual environment::
86+
87+
~/se-bug$ source clean-python26-env/bin/activate
88+
89+
Install the version of Selenium for which you wish to test. In the following
90+
case we are going to check Selenium version 2.25.0.
91+
92+
(clean-python26-env) ~/se-bug$ easy_install selenium==2.25.0
93+
94+
Create a test file, in this case ~/se-bug/testExeJS.py::
95+
96+
import unittest
97+
from selenium import webdriver
98+
99+
class ExecuteJavascriptTestCase(unittest.TestCase):
100+
101+
def setUp(self):
102+
self.driver = webdriver.Firefox()
103+
104+
def test_exe_javascript(self):
105+
driver = self.driver
106+
driver.get("http://www.google.com")
107+
url = driver.execute_script("return [ document.location ];")
108+
print('Finished')
109+
self.assertEqual(url[0]['href'], u"http://www.google.com/")
110+
111+
def tearDown(self):
112+
self.driver.close()
113+
114+
if __name__ == "__main__":
115+
unittest.main()
116+
117+
Breaking down this example test case we see in the setUp and tearDown
118+
methods we initiate and close the Firefox webdriver, respectively.
119+
In the one test, text_exe_javascript, we perform steps to verify or
120+
disprove the issue we are experiencing is with Selenium only. (In
121+
`this case`_ the browser was hanging after the execute_script call and
122+
not returning; thus I printed 'Finished' to help show where the test
123+
progressed to.)
124+
125+
An important part of the above test case, and all unit tests, is the
126+
line "self.assertEqual(...". This is one example of the method's
127+
available to check for errors or failures. For example, you can check
128+
for trueness or falseness of a stament by using assertTrue() and
129+
assertFalse(). Or you can for inclusiveness and exclussiveness by using
130+
assertIn() and assertNotIn(), respectively. For more information about
131+
unittest see `Python's unittest documentation`_. The last two lines
132+
allow this test to be run from the command line.
133+
134+
To run the unittest type::
135+
136+
(clean-python26-env) ~/se-bug$ python testExeJS.py
137+
138+
In this example I removed the troubled selenium version and reinstalled a
139+
previous version, re-running the test case to verfiy selenium was the
140+
problem and not Selenium2Library::
141+
142+
(clean-python26-env) ~/se-bug$ rm -Rf clean-python26-env/lib/python2.6/site-packages/selenium-2.25.0-py2.6.egg
143+
(clean-python26-env) ~/se-bug$ easy_install selenium==2.24.0
144+
(clean-python26-env) ~/se-bug$ python testExeJS.py
145+
Finished
146+
.
147+
----------------------------------------------------------------------
148+
Ran 1 test in 6.198s
149+
150+
OK
151+
(clean-python26-env) ~/se-bug$
152+
153+
If you discover an issue with Selenium it is helpful to `report it`_ to
154+
the Selenium developers.
155+
156+
67157
Pushing Code to GitHub
68158
----------------------
69159

@@ -187,3 +277,6 @@ are parsed by the reStructuredText parser. To build them, run::
187277
.. _downloads section on GitHub: https://github.com/rtomac/robotframework-selenium2library/downloads
188278
.. _PyPI: http://pypi.python.org
189279
.. _.pypirc file: http://docs.python.org/distutils/packageindex.html#the-pypirc-file
280+
.. _this case: http://code.google.com/p/selenium/issues/detail?id=4375
281+
.. _report it: http://code.google.com/p/selenium/issues/list
282+
.. _Python's unittest documentation: http://docs.python.org/library/unittest.html

INSTALL.rst

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,35 @@ are the most restrictive, and as of now require Python 2.6 or Python 2.7.
1111

1212
Selenium2Library depends on a few other Python libraries, including
1313
of course Robot Framework and Selenium. All dependencies are declared
14-
in setup.py. If you use pip or easy_install to install this library, the
15-
dependencies will be installed for you (this is recommended).
14+
in setup.py.
1615

1716

18-
Installing from PyPI (recommended)
19-
----------------------------------
17+
Installing using pip (recommended) or easy_install
18+
--------------------------------------------------
2019

21-
Selenium2Library is available in the Python Package Index (PyPI_). To install,
22-
you need to have `pip`_ installed. Then run::
20+
Selenium2Library is available in the Python Package Index (PyPI_). It is
21+
recommended that you use `pip`_ to install. Using pip will ensure that
22+
both Selenium2Library **and** it's dependiences are installed.
23+
To install using pip, run::
2324

2425
pip install robotframework-selenium2library
2526

2627
Or alternately, if you only have `easy_install`_,::
2728

2829
easy_install robotframework-selenium2library
2930

31+
If you install Selenium2Library under Windows **and** you use easy_install,
32+
you will need to install Selenium2Library's dependencies seperately.
33+
To install the dependencies, run::
34+
35+
easy_install robotframework
36+
easy_install selenium
37+
easy_install decorator
38+
easy_install docutils
39+
40+
Once installation is completed, you should verify proper installation of
41+
Selenium2Library and it's dependencies. See `Verifying Installation` section
42+
below.
3043

3144
Installing from source
3245
----------------------
@@ -52,11 +65,40 @@ Using Windows installer
5265
-----------------------
5366

5467
Currently, Windows installer is the only available binary installer. Just
55-
double-click the installer and follow the instructions.
68+
double-click the installer and follow the instructions. The installer is missing
69+
decorator module. It must be installed either via pip or easy install, or from
70+
http://pypi.python.org/pypi/decorator/
5671

5772
Selenium2Library can be uninstalled using the Programs and Features utility from
5873
Control Panel (Add/Remove Programs on older versions of Windows).
5974

75+
Verifying Installation
76+
----------------------
77+
78+
Once you have installed Selenium2Library it is a good idea to verify the installation. To verify installation start python::
79+
80+
C:\> python
81+
82+
and then at the Python prompt type::
83+
84+
>> import Selenium2Library
85+
>>
86+
87+
If the python command line interpretor returns with another prompt ('>>' as shown above) then your installation was successful.
88+
89+
Troubleshooting Installation
90+
----------------------------
91+
92+
The most common issue with installing Selenium2Library is missing dependencies. An error like::
93+
94+
ImportError: No module named robot.variables
95+
96+
indicates that you are missing the Robot Framework package. To correct this problem try typing at the prompt::
97+
98+
easy_install robotframework
99+
100+
Similarly if you receive "No module named ..." error message then you have another missing dependency. To correct, use easy_install to install the missing package.
101+
60102

61103
.. _Selenium Python Bindings: http://code.google.com/p/selenium/wiki/PythonBindings
62104
.. _PyPI: http://code.google.com/p/selenium/wiki/PythonBindings

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ but re-implemented to use Selenium 2 and WebDriver technologies.
1717
- Developer information is found in `BUILD.rst` file.
1818

1919

20+
Installation
21+
------------
22+
23+
You can install Selenium2Library using pip, with the following command
24+
25+
pip install robotframework-selenium2library
26+
27+
2028
Directory Layout
2129
----------------
2230

demo/rundemo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232

3333
try:
3434
import Selenium2Library
35-
except ImportError:
36-
print 'Importing Selenium2Library module failed.'
37-
print 'Please make sure you have SeleniumLibrary installed.'
35+
except ImportError, e:
36+
print 'Importing Selenium2Library module failed (%s).' % e
37+
print 'Please make sure you have Selenium2Library properly installed.'
38+
print 'See INSTALL.rst for troubleshooting information.'
3839
sys.exit(1)
3940

4041

src/Selenium2Library/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page
9494
9595
'implicit_wait' is the implicit timeout that Selenium waits when
9696
looking for elements.
97-
It can be later set with 'Set Selenium Implicit Wait'.
97+
It can be later set with `Set Selenium Implicit Wait`.
98+
See `WebDriver: Advanced Usage`__ section of the SeleniumHQ documentation
99+
for more information about WebDriver's implicit wait functionality.
100+
101+
__ http://seleniumhq.org/docs/04_webdriver_advanced.html#explicit-and-implicit-waits
98102
99103
`run_on_failure` specifies the name of a keyword (from any available
100104
libraries) to execute when a Selenium2Library keyword fails. By default
@@ -104,9 +108,11 @@ def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page
104108
functionality.
105109
106110
Examples:
107-
| Library `|` Selenium2Library `|` 15 | # Sets default timeout to 15 seconds |
108-
| Library `|` Selenium2Library `|` 5 `|` Log Source | # Sets default timeout to 5 seconds and runs `Log Source` on failure |
109-
| Library `|` Selenium2Library `|` timeout=10 `|` run_on_failure=Nothing | # Sets default timeout to 10 seconds and does nothing on failure |
111+
| Library `|` Selenium2Library `|` 15 | # Sets default timeout to 15 seconds |
112+
| Library `|` Selenium2Library `|` 0 `|` 5 | # Sets default timeout to 0 seconds and default implicit_wait to 5 seconds |
113+
| Library `|` Selenium2Library `|` 5 `|` run_on_failure=Log Source | # Sets default timeout to 5 seconds and runs `Log Source` on failure |
114+
| Library `|` Selenium2Library `|` implicit_wait=5 `|` run_on_failure=Log Source | # Sets default implicit_wait to 5 seconds and runs `Log Source` on failure |
115+
| Library `|` Selenium2Library `|` timeout=10 `|` run_on_failure=Nothing | # Sets default timeout to 10 seconds and does nothing on failure |
110116
"""
111117
for base in Selenium2Library.__bases__:
112118
base.__init__(self)

0 commit comments

Comments
 (0)