Skip to content

Commit c43af38

Browse files
authored
[py] Update Python documentation (modernization) (#15459)
* [py] Remove blank line in tox.ini * [py] Update instructions for docs * [py] Bump Sphinx and Jinja2 versions for building docs * [py] Change permissions of index.rst * [py] Update instructions for building docs * [py] Update Python documentation (modernization) * [py] fix typos in README * [py] Fix theme name * [py] Update browser names in README * [py] Add virtual env name * [py] Change Sphinx version for docs * [py] tiny fix in README
1 parent 52e6e1d commit c43af38

File tree

6 files changed

+94
-75
lines changed

6 files changed

+94
-75
lines changed

Diff for: py/docs/README.rst

+41-30
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,72 @@ How to build docs
1111
=================
1212

1313
One can build the Python documentation without doing a full bazel build. The
14-
following instructions will build the setup a virtual environment and installs tox, clones the
15-
selenium repo and then runs ``tox -c py/tox.ini`` building the Python documentation.
14+
following instructions will build the setup a virtual environment and installs tox,
15+
clones the selenium repo and then runs ``tox -c py/tox.ini -e docs``, building the
16+
Python documentation.
1617

1718
.. code-block:: console
1819
19-
virtualenv test-py38-env
20-
source test-py38-env/bin/activate
20+
python3 -m venv venv
21+
source venv/bin/activate
2122
pip install tox
2223
git clone [email protected]:SeleniumHQ/selenium.git
2324
cd selenium/
2425
# uncomment and switch to your development branch if needed
2526
#git switch -c feature-branch origin/feature-branch
26-
tox -c py/tox.ini
27+
tox -c py/tox.ini -e docs
28+
29+
This works in a similar manner as the larger selenium bazel build, but does just the Python
30+
documentation portion.
2731

28-
Works in similar manner as the larger selenium bazel doing just the python documentation portion.
2932

3033
What is happening under the covers of tox, sphinx
3134
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32-
tox is essentially a build tool for Python. Here it setups its own virtualenv and installs the
33-
documentation packages (sphinx and jinja2) as well as the required selenium python
34-
dependencies. Then tox runs the sphinx generate autodoc stub files and then builds the docs.
35+
36+
tox is essentially a build tool for Python. Here it sets up its own virtual env and installs
37+
the documentation packages (sphinx and jinja2) as well as the required selenium python
38+
dependencies. Then tox runs the ``sphinx-autogen`` command to generate autodoc stub pages.
39+
Then it runs ``sphinx-build`` to build the HTML docs.
3540

3641
Sphinx is .. well a much larger topic then what we could cover here. Most important to say
37-
here is that the docs are using the "classic" theme and than the majority of the api documentation
38-
is autogenerated. There is plenty of information available and currently the documentation is
39-
fairly small and not complex. So some basic understanding of restructed text and the Sphinx tool chain
40-
should be sufficient to contribute and develop the Python docs.
42+
here is that the docs are using the "sphinx-material" theme (AKA "Material for Sphinx" theme)
43+
and the the majority of the api documentation is autogenerated. There is plenty of information
44+
available and currently the documentation is fairly small and not complex. So some basic
45+
understanding of reStructuredText and the Sphinx tool chain should be sufficient to contribute
46+
and develop the Python docs.
47+
48+
49+
To clean up the build assets and tox cache
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4151

42-
To clean up the build / tox cache
43-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44-
Although there is a Sphinx Makefile option to clean up using the tox environment above one can
45-
manually clean the build by deleting the build directory on the root (selenium/build using the
46-
default directory on git clone). Noting that both Sphinx and tox cache parts of their build and
47-
recognize changes to speed up their respective builds. But at times one wants to start fresh
48-
deleting the aformentioned directory will clean the Sphinx cache or removing selenium/py/.tox
49-
directory for cleaning the tox environment.
52+
Although there is a Sphinx Makefile option, to clean up using the tox environment above, one can
53+
manually clean the build assets by deleting the ``build`` directory on the root (``selenium/build``
54+
using the default directory on git clone). Note that tox caches parts of the build and recognizes
55+
changes to speed up the build. To start fresh, delete the aformentioned directory to clean the
56+
Sphinx build assets and delete the ``selenium/py/.tox`` directory to clean the tox environment.
5057

5158

5259
Known documentation issues
5360
==========================
61+
5462
The API Reference primarily builds from the source code. But currently the initial template stating
55-
which modules to document is hard coded within py/docs/source/api.rst. So if modules are added or
56-
removed then the generated docs will be inaccurate. It would be preferred that the API docs generate
57-
soley from the code if possible. This is being tracked in `#14178 <https://github.com/SeleniumHQ/selenium/issues/14178>`_
63+
which modules to document is hard coded within ``py/docs/source/api.rst``. So if modules are added or
64+
removed, then the generated docs will be inaccurate. It would be preferred that the API docs generate
65+
soley from the code if possible. This is being tracked in
66+
`#14178 <https://github.com/SeleniumHQ/selenium/issues/14178>`_
5867

59-
We are working through the Sphinx build Warnings and Errors trying to clean up botht the syntax and
68+
We are working through the Sphinx build warnings and errors, trying to clean up both the syntax and
6069
the build.
6170

71+
6272
Contributing to Python docs
6373
===========================
74+
6475
First it is recommended that you read the main `CONTRIBUTING.md <https://github.com/SeleniumHQ/selenium/blob/trunk/CONTRIBUTING.md>`_.
6576

66-
Some steps for contibuting to the Python documentation ..
77+
Some steps for contibuting to the Python documentation ...
6778

68-
- Check out changes locally using instruction above.
69-
- Try to resolve any warnings/issues.
70-
- If too arduous either ask for help or add to list of known issue.
71-
- If this process is updated please update this doc as well to help the next person.
79+
- Check out changes locally using instructions above.
80+
- Try to resolve any warnings/errors.
81+
- If too arduous, either ask for help or add to the list of known issues.
82+
- If this process is updated, please update this doc as well to help the next person.

Diff for: py/docs/requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
Jinja2==3.1.5
2-
Sphinx==7.1.2
1+
Jinja2==3.1.6
2+
Sphinx==7.4.7
3+
sphinx-material==0.0.36

Diff for: py/docs/selenium_logo_small.png

647 Bytes
Loading

Diff for: py/docs/source/conf.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
# General information about the project.
5151
project = 'Selenium'
52-
copyright = '2009-2024 Software Freedom Conservancy'
52+
copyright = '2009-2025 Software Freedom Conservancy'
5353

5454
# The version info for the project you're documenting, acts as replacement for
5555
# |version| and |release|, also used in various other places throughout the
@@ -97,9 +97,8 @@
9797

9898
# -- Options for HTML output ---------------------------------------------------
9999

100-
# The theme to use for HTML and HTML Help pages. See the documentation for
101-
# a list of builtin themes.
102-
html_theme = 'default'
100+
# The theme to use for HTML and HTML Help pages
101+
html_theme = 'sphinx_material'
103102

104103
# Theme options are theme-specific and customize the look and feel of a theme
105104
# further. For a list of options available for each theme, see the
@@ -118,7 +117,7 @@
118117

119118
# The name of an image file (relative to this directory) to place at the top
120119
# of the sidebar.
121-
#html_logo = None
120+
html_logo = '../selenium_logo_small.png'
122121

123122
# The name of an image file (within the static path) to use as favicon of the
124123
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
@@ -146,13 +145,13 @@
146145
#html_additional_pages = {}
147146

148147
# If false, no module index is generated.
149-
#html_domain_indices = True
148+
html_domain_indices = True
150149

151150
# If false, no index is generated.
152-
#html_use_index = True
151+
html_use_index = True
153152

154153
# If true, the index is split into individual pages for each letter.
155-
#html_split_index = False
154+
html_split_index = True
156155

157156
# If true, links to the reST sources are added to the pages.
158157
html_show_sourcelink = True

Diff for: py/docs/source/index.rst

100755100644
+43-34
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ The `selenium` package is used to automate web browser interaction from Python.
1414
+-----------------+--------------------------------------------------------------------------------------+
1515
| **GitHub**: | https://github.com/SeleniumHQ/Selenium |
1616
+-----------------+--------------------------------------------------------------------------------------+
17-
| **PyPI**: | https://pypi.org/project/selenium/ |
17+
| **PyPI**: | https://pypi.org/project/selenium |
18+
+-----------------+--------------------------------------------------------------------------------------+
19+
| **API Docs**: | https://selenium.dev/selenium/docs/api/py/api.html |
1820
+-----------------+--------------------------------------------------------------------------------------+
1921
| **IRC/Slack**: | `Selenium chat room <https://www.selenium.dev/support/#ChatRoom>`_ |
2022
+-----------------+--------------------------------------------------------------------------------------+
2123

22-
Several browsers/drivers are supported (Firefox, Chrome, Internet Explorer), as well as the Remote protocol.
24+
Several browsers/drivers are supported (Firefox, Chrome, Edge, Safari), as well as the Remote protocol.
2325

2426
Supported Python Versions
2527
=========================
@@ -33,21 +35,22 @@ If you have `pip <https://pip.pypa.io/>`_ on your system, you can simply install
3335

3436
pip install -U selenium
3537

36-
Alternately, you can download the source distribution from `PyPI <https://pypi.org/project/selenium/#files>`, unarchive it, and run::
37-
38-
python -m pip install .
39-
40-
Note: You may want to consider using `virtualenv <http://www.virtualenv.org/>`_ to create isolated Python environments.
38+
You may want to consider using a `virtual environment <https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments>`_
39+
to create isolated Python environments.
4140

4241
Drivers
4342
=======
4443

45-
Selenium requires a driver to interface with the chosen browser. Firefox,
46-
for example, requires `geckodriver <https://github.com/mozilla/geckodriver/releases>`_, which needs to be installed before the below examples can be run. Make sure it's in your `PATH`, e. g., place it in `/usr/bin` or `/usr/local/bin`.
44+
Selenium requires a driver to interface with the chosen browser (chromedriver, edgedriver, geckodriver, etc).
4745

48-
Failure to observe this step will give you an error `selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.`
46+
In older versions of Selenium, it was necessary to install and manage these drivers yourself. You had to make sure the driver
47+
executable was available on your system `PATH`, or specified explicitly in code. Modern versions of Selenium handle browser and
48+
driver installation for you with `Selenium Manager <https://www.selenium.dev/documentation/selenium_manager>`_. You generally
49+
don't have to worry about driver installation or configuration now that it's done for you when you instantiate a WebDriver.
50+
Selenium Manager works with most supported platforms and browsers. If it doesn't meet your needs, you can still install and
51+
specify browsers and drivers yourself.
4952

50-
Other supported browsers will have their own drivers available. Links to some of the more popular browser drivers follow.
53+
Links to some of the more popular browser drivers:
5154

5255
+--------------+-----------------------------------------------------------------------+
5356
| **Chrome**: | https://chromedriver.chromium.org/downloads |
@@ -62,59 +65,65 @@ Other supported browsers will have their own drivers available. Links to some of
6265
Example 0:
6366
==========
6467

65-
* open a new Firefox browser
66-
* load the page at the given URL
68+
* launch a new Chrome browser
69+
* load a web page
70+
* close the browser
6771

6872
.. code-block:: python
6973
7074
from selenium import webdriver
7175
72-
browser = webdriver.Firefox()
73-
browser.get('http://selenium.dev/')
76+
77+
driver = webdriver.Chrome()
78+
driver.get('https://selenium.dev/')
79+
driver.quit()
7480
7581
Example 1:
7682
==========
7783

78-
* open a new Firefox browser
79-
* load the Yahoo homepage
80-
* search for "seleniumhq"
84+
* launch a new Chrome browser
85+
* load the Selenium documentation page
86+
* find the "Webdriver" link
87+
* click the "WebDriver" link
8188
* close the browser
8289

8390
.. code-block:: python
8491
8592
from selenium import webdriver
8693
from selenium.webdriver.common.by import By
87-
from selenium.webdriver.common.keys import Keys
8894
89-
browser = webdriver.Firefox()
9095
91-
browser.get('http://www.yahoo.com')
92-
assert 'Yahoo' in browser.title
96+
driver = webdriver.Chrome()
97+
98+
driver.get('https://selenium.dev/documentation')
99+
assert 'Selenium' in driver.title
93100
94-
elem = browser.find_element(By.NAME, 'p') # Find the search box
95-
elem.send_keys('seleniumhq' + Keys.RETURN)
101+
elem = driver.find_element(By.ID, 'm-documentationwebdriver')
102+
elem.click()
103+
assert 'WebDriver' in driver.title
96104
97-
browser.quit()
105+
driver.quit()
98106
99107
Example 2:
100108
==========
101109

102-
Selenium WebDriver is often used as a basis for testing web applications. Here is a simple example using Python's standard `unittest <http://docs.python.org/3/library/unittest.html>`_ library:
110+
Selenium WebDriver is often used as a basis for testing web applications. Here is a simple example using Python's standard `unittest <http://docs.python.org/3/library/unittest.html>`_ library:
103111

104112
.. code-block:: python
105113
106114
import unittest
107115
from selenium import webdriver
108116
117+
109118
class GoogleTestCase(unittest.TestCase):
110119
111120
def setUp(self):
112-
self.browser = webdriver.Firefox()
113-
self.addCleanup(self.browser.quit)
121+
self.driver = webdriver.Firefox()
122+
self.addCleanup(self.driver.quit)
114123
115124
def test_page_title(self):
116-
self.browser.get('http://www.google.com')
117-
self.assertIn('Google', self.browser.title)
125+
self.driver.get('https://www.google.com')
126+
self.assertIn('Google', self.driver.title)
118127
119128
if __name__ == '__main__':
120129
unittest.main(verbosity=2)
@@ -143,9 +152,9 @@ Contributing
143152

144153
- Create a branch for your work
145154
- Ensure `tox` is installed (using a `virtualenv` is recommended)
146-
- `python3.8 -m venv .venv && . .venv/bin/activate && pip install tox`
155+
- Run: `python -m venv venv && source venv/bin/activate && pip install tox`
147156
- After making changes, before committing execute `tox -e linting`
148-
- If tox exits `0`, commit and push otherwise fix the newly introduced breakages.
157+
- If tox exits `0`, commit and push. Otherwise fix the newly introduced style violations.
149158
- `flake8` requires manual fixes
150-
- `black` will often rewrite the breakages automatically, however the files are unstaged and should staged again.
151-
- `isort` will often rewrite the breakages automatically, however the files are unstaged and should staged again.
159+
- `black` will rewrite the violations automatically, however the files are unstaged and should staged again.
160+
- `isort` will rewrite the violations automatically, however the files are unstaged and should staged again.

Diff for: py/tox.ini

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ skip_install = true
1414
deps =
1515
-r {toxinidir}/docs/requirements.txt
1616
-r {toxinidir}/requirements.txt
17-
1817
commands =
1918
; regenerate autodoc stub pages
2019
sphinx-autogen docs/source/api.rst

0 commit comments

Comments
 (0)