Skip to content

Commit 26e9216

Browse files
authored
Merge 369193e into bed68d1
2 parents bed68d1 + 369193e commit 26e9216

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

py/selenium/webdriver/support/relative_locator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def to_right_of(self, element_or_locator: Union[WebElement, Dict] = None) -> "Re
133133

134134
def near(self, element_or_locator_distance: Union[WebElement, Dict, int] = None) -> "RelativeBy":
135135
"""
136-
Add a filter to look for elements above.
136+
Add a filter to look for elements near.
137137
:Args:
138138
- element_or_locator_distance: Element to look near by the element or within a distance
139139
"""

py/test/selenium/webdriver/common/webserver.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""A simple web server for testing purpose.
1919
It serves the testing html pages that are needed by the webdriver unit tests."""
20-
20+
import contextlib
2121
import logging
2222
import os
2323
import re
@@ -75,7 +75,7 @@ def do_GET(self):
7575
self.end_headers()
7676
self.wfile.write(html)
7777
except IOError:
78-
self.send_error(404, 'File Not Found: %s' % path)
78+
self.send_error(404, f"File Not Found: {path}")
7979

8080
def do_POST(self):
8181
"""POST method handler."""
@@ -141,7 +141,7 @@ def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT):
141141
self.port = port
142142
break
143143
except socket.error:
144-
LOGGER.debug("port %d is in use, trying to next one" % port)
144+
LOGGER.debug(f"port {port} is in use, trying to next one")
145145
port += 1
146146

147147
self.thread = threading.Thread(target=self._run_web_server)
@@ -160,14 +160,11 @@ def start(self):
160160
def stop(self):
161161
"""Stops the server."""
162162
self.stop_serving = True
163-
try:
164-
# This is to force stop the server loop
165-
urllib_request.URLopener().open("http://%s:%d" % (self.host, self.port))
166-
except IOError:
167-
pass
163+
with contextlib.suppress(IOError):
164+
_ = urllib_request.urlopen(f"http://{self.host}:{self.port}")
168165

169-
def where_is(self, path):
170-
return "http://%s:%d/%s" % (self.host, self.port, path)
166+
def where_is(self, path) -> str:
167+
return f"http://{self.host}:{self.port}/{path}"
171168

172169

173170
def main(argv=None):
@@ -180,16 +177,16 @@ def main(argv=None):
180177

181178
parser = OptionParser("%prog [options]")
182179
parser.add_option("-p", "--port", dest="port", type="int",
183-
help="port to listen (default: %s)" % DEFAULT_PORT,
180+
help=f"port to listen (default: {DEFAULT_PORT})",
184181
default=DEFAULT_PORT)
185182

186183
opts, args = parser.parse_args(argv[1:])
187184
if args:
188185
parser.error("wrong number of arguments") # Will exit
189186

190-
server = SimpleWebServer(opts.port)
187+
server = SimpleWebServer(port=opts.port)
191188
server.start()
192-
print("Server started on port %s, hit CTRL-C to quit" % opts.port)
189+
print(f"Server started on port {opts.port}, hit CTRL-C to quit")
193190
try:
194191
while 1:
195192
sleep(0.1)

0 commit comments

Comments
 (0)