Represents the Speedof.me service for conducting internet speed tests.
This class provides methods to interact with the Speedof.me website using a
Selenium WebDriver, including accepting the end-user license agreement
(EULA), initiating a speed test, and capturing the results as a screenshot.
The class is designed to work with a browser instance that complies
with the BrowserInterface, allowing for flexibility in browser
choice.
Attributes:
Name |
Type |
Description |
driver |
|
A driver instance that adheres to the DriverInterface, used
for web interactions with the browser.
|
Source code in src/speed_sleuth/provider/speedofme.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 | @Provider.register
class Speedofme:
"""Represents the Speedof.me service for conducting internet speed tests.
This class provides methods to interact with the Speedof.me website using a
Selenium WebDriver, including accepting the end-user license agreement
(EULA), initiating a speed test, and capturing the results as a screenshot.
The class is designed to work with a browser instance that complies
with the BrowserInterface, allowing for flexibility in browser
choice.
Attributes:
driver: A driver instance that adheres to the DriverInterface, used
for web interactions with the browser.
"""
def __init__(self, driver: DriverInterface):
"""Initializes the Speedofme provider with the specified browser.
Parameters:
driver: A driver instance that adheres to the DriverInterface, used
for web interactions with the browser.
"""
driver.get("https://speedof.me/")
self.driver = driver
def setup(self):
"""Prepares the testing environment on the Speedof.me website.
This involves accepting the End User License Agreement (EULA) if
it is presented. Failure to find the EULA acceptance button is
handled gracefully and logged.
"""
try:
eula_btn = self.driver.find_element(
By.CSS_SELECTOR, "#cc-accept-btn > a"
)
self.driver.wait_to_be_visible(eula_btn)
print("Found eula accept btn")
eula_btn.click()
except NoSuchElementException as e:
print("element not found: ", e)
def run(self, filename: str = "speedofme-results.png"):
"""Initiates the speed test on Speedof.me and captures the results. The
test results are saved as a screenshot in the specified file.
Parameters:
filename: The name of the file to save the screenshot of the test
results. Defaults to 'speedofme-results.png'.
This method handles the full lifecycle of the speed test,
including setup, starting the test, waiting for the test to
complete, and capturing the results.
"""
code = 0
try:
self.setup()
self.driver.find_element(
By.CSS_SELECTOR, "button#start_test_btn"
).click()
print("[+] running speedof.me, please wait")
retry_btn = self.driver.find_element(
By.CSS_SELECTOR, "div.result-retry.result-color"
)
self.driver.wait_to_be_visible(retry_btn)
print("[+] done, taking snapshot of the website results")
results = self.driver.find_element(
By.CSS_SELECTOR, "#d3_pane > svg.download_svg"
)
if results:
results.screenshot(filename)
except Exception as exp:
print(f"An error occurred: {exp}")
traceback.print_exc()
code = -1
finally:
self.driver.cleanup(code)
def parse_results(self):
"""Parses the results of the speed test. This method is intended to be
implemented in the future to provide functionality for extracting and
interpreting the test results from the screenshot or the webpage
directly.
Currently, this method is a placeholder and does not perform any
actions.
"""
|
__init__(driver)
Initializes the Speedofme provider with the specified browser.
Parameters:
Name |
Type |
Description |
Default |
driver |
DriverInterface
|
A driver instance that adheres to the DriverInterface, used
for web interactions with the browser.
|
required
|
Source code in src/speed_sleuth/provider/speedofme.py
32
33
34
35
36
37
38
39
40
41 | def __init__(self, driver: DriverInterface):
"""Initializes the Speedofme provider with the specified browser.
Parameters:
driver: A driver instance that adheres to the DriverInterface, used
for web interactions with the browser.
"""
driver.get("https://speedof.me/")
self.driver = driver
|
parse_results()
Parses the results of the speed test. This method is intended to be
implemented in the future to provide functionality for extracting and
interpreting the test results from the screenshot or the webpage
directly.
Currently, this method is a placeholder and does not perform any
actions.
Source code in src/speed_sleuth/provider/speedofme.py
99
100
101
102
103
104
105
106
107
108 | def parse_results(self):
"""Parses the results of the speed test. This method is intended to be
implemented in the future to provide functionality for extracting and
interpreting the test results from the screenshot or the webpage
directly.
Currently, this method is a placeholder and does not perform any
actions.
"""
|
run(filename='speedofme-results.png')
Initiates the speed test on Speedof.me and captures the results. The
test results are saved as a screenshot in the specified file.
Parameters:
Name |
Type |
Description |
Default |
filename |
str
|
The name of the file to save the screenshot of the test
results. Defaults to 'speedofme-results.png'.
|
'speedofme-results.png'
|
This method handles the full lifecycle of the speed test,
including setup, starting the test, waiting for the test to
complete, and capturing the results.
Source code in src/speed_sleuth/provider/speedofme.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 | def run(self, filename: str = "speedofme-results.png"):
"""Initiates the speed test on Speedof.me and captures the results. The
test results are saved as a screenshot in the specified file.
Parameters:
filename: The name of the file to save the screenshot of the test
results. Defaults to 'speedofme-results.png'.
This method handles the full lifecycle of the speed test,
including setup, starting the test, waiting for the test to
complete, and capturing the results.
"""
code = 0
try:
self.setup()
self.driver.find_element(
By.CSS_SELECTOR, "button#start_test_btn"
).click()
print("[+] running speedof.me, please wait")
retry_btn = self.driver.find_element(
By.CSS_SELECTOR, "div.result-retry.result-color"
)
self.driver.wait_to_be_visible(retry_btn)
print("[+] done, taking snapshot of the website results")
results = self.driver.find_element(
By.CSS_SELECTOR, "#d3_pane > svg.download_svg"
)
if results:
results.screenshot(filename)
except Exception as exp:
print(f"An error occurred: {exp}")
traceback.print_exc()
code = -1
finally:
self.driver.cleanup(code)
|
setup()
Prepares the testing environment on the Speedof.me website.
This involves accepting the End User License Agreement (EULA) if
it is presented. Failure to find the EULA acceptance button is
handled gracefully and logged.
Source code in src/speed_sleuth/provider/speedofme.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 | def setup(self):
"""Prepares the testing environment on the Speedof.me website.
This involves accepting the End User License Agreement (EULA) if
it is presented. Failure to find the EULA acceptance button is
handled gracefully and logged.
"""
try:
eula_btn = self.driver.find_element(
By.CSS_SELECTOR, "#cc-accept-btn > a"
)
self.driver.wait_to_be_visible(eula_btn)
print("Found eula accept btn")
eula_btn.click()
except NoSuchElementException as e:
print("element not found: ", e)
|