-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speedtest and speedofme changed and add some more banner. I had to adapt and add new detection. I also improved the code to make is more robust. Signed-off-by: Lionel Hubaut <lionel.hubaut@tessares.net>
- Loading branch information
Showing
12 changed files
with
911 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"python.analysis.extraPaths": [ | ||
"lib/" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
browser is the module handling the different browser logic and their | ||
implementation in order to be used with selenium. | ||
""" | ||
|
||
import abc | ||
|
||
from selenium.webdriver.remote.webdriver import WebDriver | ||
|
||
|
||
class BrowserInterface(metaclass=abc.ABCMeta): | ||
""" | ||
BrowserInterface is a generic interface each browser subclass will need to | ||
implement in order to correctly configure the selenium webdriver. This interface | ||
ensures that all subclasses provide a specific method to load and configure | ||
a Selenium WebDriver instance appropriate for the browser they represent. | ||
""" | ||
@classmethod | ||
def __subclasshook__(cls, subclass): | ||
return (hasattr(subclass, 'load_driver') and | ||
callable(subclass.load_driver) or | ||
NotImplemented) | ||
|
||
@classmethod | ||
@abc.abstractmethod | ||
def load_driver(cls) -> WebDriver: | ||
""" | ||
Loads and returns a configured instance of Selenium WebDriver specific to the browser. | ||
This method must be implemented by subclasses to provide a ready-to-use WebDriver | ||
instance that is appropriately configured for the browser the subclass represents. | ||
The configuration may include setting browser options, capabilities, and webdriver paths. | ||
Returns: | ||
WebDriver: An instance of a Selenium WebDriver ready for browser automation tasks. | ||
Raises: | ||
NotImplementedError: If the subclass does not implement this method. | ||
""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
This module defines the ChromiumBrower class, which is an implementation of the BrowserInterface | ||
for creating and configuring a Selenium WebDriver specific to Chromium-based browsers. Currently, | ||
the implementation focuses on Google Chrome, with the intention to extend support to other | ||
Chromium-based browsers in the future. | ||
Key Components: | ||
- BrowserInterface: An abstract base class that defines a generic interface for browser subclasses. | ||
- ChromiumBrower: A concrete class that implements the BrowserInterface for the Chrome browser, | ||
providing a method to load and configure a Selenium WebDriver with Chromium-specific options. | ||
""" | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.remote.webdriver import WebDriver | ||
from selenium.webdriver.chromium.service import ChromiumService | ||
from selenium.webdriver.chromium.options import ChromiumOptions | ||
|
||
from . import BrowserInterface | ||
|
||
@BrowserInterface.register | ||
class ChromiumBrower: | ||
""" | ||
ChromiumBrower implements the BrowserInterface to provide a method for loading | ||
and configuring a WebDriver instance specifically for Chromium browsers. | ||
This class currently supports Chrome browser, with plans to extend support | ||
to other Chromium-based browsers. It demonstrates how to set up a Selenium | ||
WebDriver with specific options tailored for a Chromium browser instance, | ||
including setting the binary location, window size, and disabling GPU acceleration. | ||
Methods: | ||
load_driver(): Creates and returns a configured Selenium WebDriver instance | ||
for the Chromium browser. | ||
""" | ||
|
||
def load_driver(self) -> WebDriver: | ||
""" | ||
Initializes and returns a Selenium WebDriver instance configured for the Chrome browser. | ||
This method sets up a ChromiumService and configures ChromiumOptions to specify | ||
the binary location of the Chrome browser, set the window size, disable GPU acceleration, | ||
and set the browser language. These options ensure that the WebDriver instance is | ||
ready for web automation tasks with Chrome. | ||
Note: While this implementation currently supports Chromium, there is a plan to expand | ||
support to other browsers. | ||
Returns: | ||
WebDriver: A configured instance of Selenium WebDriver for the Chromium browser. | ||
Example: | ||
>>> chromium_browser = ChromiumBrower() | ||
>>> driver = chromium_browser.load_driver() | ||
# Now `driver` can be used to automate web interactions using Chromium. | ||
""" | ||
service = ChromiumService() | ||
options = ChromiumOptions() | ||
options.binary_location = '/snap/chromium/2805/usr/lib/chromium-browser/chrome' | ||
#options.add_argument('--headless') | ||
options.add_argument('--window-size=1400x900') | ||
options.add_argument('--disable-gpu') | ||
options.add_argument('--lang=en_US') | ||
driver = webdriver.Chrome(service=service, options=options) | ||
return driver | ||
# As using selenium api > 2.x, this call should block until | ||
# readyState is hit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.